genet: Fix potential crash during attach

As pointed out in the bug, the genet driver (RPi4 Ethernet) was
attaching the interrupts before the data structures were fully
initialized, causing a crash if an interrupt came in during the
attach.  Fix by reordering code blocks.

PR:		256334
Reported by:	< ghuckriede at blackberry.com >
Reviewed by:	< ghuckriede at blackberry.com > (informally)
MFC after:	3 days
This commit is contained in:
Mike Karels 2021-06-20 11:10:26 -05:00
parent 9d1cafb304
commit 13604fb0fd

View File

@ -279,21 +279,6 @@ gen_attach(device_t dev)
goto fail;
}
/* Install interrupt handlers */
error = bus_setup_intr(dev, sc->res[_RES_IRQ1],
INTR_TYPE_NET | INTR_MPSAFE, NULL, gen_intr, sc, &sc->ih);
if (error != 0) {
device_printf(dev, "cannot setup interrupt handler1\n");
goto fail;
}
error = bus_setup_intr(dev, sc->res[_RES_IRQ2],
INTR_TYPE_NET | INTR_MPSAFE, NULL, gen_intr2, sc, &sc->ih2);
if (error != 0) {
device_printf(dev, "cannot setup interrupt handler2\n");
goto fail;
}
/* Setup ethernet interface */
sc->ifp = if_alloc(IFT_ETHER);
if_setsoftc(sc->ifp, sc);
@ -310,6 +295,21 @@ gen_attach(device_t dev)
IFCAP_HWCSUM_IPV6);
if_setcapenable(sc->ifp, if_getcapabilities(sc->ifp));
/* Install interrupt handlers */
error = bus_setup_intr(dev, sc->res[_RES_IRQ1],
INTR_TYPE_NET | INTR_MPSAFE, NULL, gen_intr, sc, &sc->ih);
if (error != 0) {
device_printf(dev, "cannot setup interrupt handler1\n");
goto fail;
}
error = bus_setup_intr(dev, sc->res[_RES_IRQ2],
INTR_TYPE_NET | INTR_MPSAFE, NULL, gen_intr2, sc, &sc->ih2);
if (error != 0) {
device_printf(dev, "cannot setup interrupt handler2\n");
goto fail;
}
/* Attach MII driver */
mii_flags = 0;
switch (sc->phy_mode)