[etherswitch] check if_alloc returns NULL

This patch is cosmetic. It checks if allocation of ifnet structure failed.
It's better to have this check rather than assume positive scenario.

Submitted by:	Dmitry Luhtionov <dmitryluhtionov@gmail.com>
Reported by:	Dmitry Luhtionov <dmitryluhtionov@gmail.com>
This commit is contained in:
Michael Zhilin 2018-01-24 21:33:18 +00:00
parent 9f747dc6dc
commit 0774131e27
8 changed files with 48 additions and 0 deletions

View File

@ -177,6 +177,12 @@ arswitch_attach_phys(struct arswitch_softc *sc)
snprintf(name, IFNAMSIZ, "%sport", device_get_nameunit(sc->sc_dev));
for (phy = 0; phy < sc->numphys; phy++) {
sc->ifp[phy] = if_alloc(IFT_ETHER);
if (sc->ifp[phy] == NULL) {
device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
err = ENOMEM;
break;
}
sc->ifp[phy]->if_softc = sc;
sc->ifp[phy]->if_flags |= IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX;

View File

@ -218,6 +218,12 @@ e6060sw_attach_phys(struct e6060sw_softc *sc)
sc->ifpport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
if (sc->ifp[port] == NULL) {
device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
err = ENOMEM;
break;
}
sc->ifp[port]->if_softc = sc;
sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX;

View File

@ -175,6 +175,12 @@ adm6996fc_attach_phys(struct adm6996fc_softc *sc)
sc->ifpport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
if (sc->ifp[port] == NULL) {
device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
err = ENOMEM;
break;
}
sc->ifp[port]->if_softc = sc;
sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX;

View File

@ -174,6 +174,12 @@ ip17x_attach_phys(struct ip17x_softc *sc)
sc->phyport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
if (sc->ifp[port] == NULL) {
device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
err = ENOMEM;
break;
}
sc->ifp[port]->if_softc = sc;
sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX;

View File

@ -221,6 +221,12 @@ ksz8995ma_attach_phys(struct ksz8995ma_softc *sc)
sc->ifpport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
if (sc->ifp[port] == NULL) {
device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
err = ENOMEM;
break;
}
sc->ifp[port]->if_softc = sc;
sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX;

View File

@ -122,6 +122,12 @@ mtkswitch_attach_phys(struct mtkswitch_softc *sc)
continue;
}
sc->ifp[phy] = if_alloc(IFT_ETHER);
if (sc->ifp[phy] == NULL) {
device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
err = ENOMEM;
break;
}
sc->ifp[phy]->if_softc = sc;
sc->ifp[phy]->if_flags |= IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX;

View File

@ -239,6 +239,12 @@ rtl8366rb_attach(device_t dev)
/* PHYs need an interface, so we generate a dummy one */
for (i = 0; i < sc->numphys; i++) {
sc->ifp[i] = if_alloc(IFT_ETHER);
if (sc->ifp[i] == NULL) {
device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
err = ENOMEM;
break;
}
sc->ifp[i]->if_softc = sc;
sc->ifp[i]->if_flags |= IFF_UP | IFF_BROADCAST | IFF_DRV_RUNNING
| IFF_SIMPLEX;

View File

@ -126,6 +126,12 @@ ukswitch_attach_phys(struct ukswitch_softc *sc)
sc->ifpport[phy] = port;
sc->portphy[port] = phy;
sc->ifp[port] = if_alloc(IFT_ETHER);
if (sc->ifp[port] == NULL) {
device_printf(sc->sc_dev, "couldn't allocate ifnet structure\n");
err = ENOMEM;
break;
}
sc->ifp[port]->if_softc = sc;
sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
IFF_DRV_RUNNING | IFF_SIMPLEX;