Author: mizhka
Date: Wed Jan 24 21:33:18 2018
New Revision: 328377
URL: https://svnweb.freebsd.org/changeset/base/328377

Log:
  [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 <dmitryluhtio...@gmail.com>
  Reported by:  Dmitry Luhtionov <dmitryluhtio...@gmail.com>

Modified:
  head/sys/dev/etherswitch/arswitch/arswitch.c
  head/sys/dev/etherswitch/e6000sw/e6060sw.c
  head/sys/dev/etherswitch/infineon/adm6996fc.c
  head/sys/dev/etherswitch/ip17x/ip17x.c
  head/sys/dev/etherswitch/micrel/ksz8995ma.c
  head/sys/dev/etherswitch/mtkswitch/mtkswitch.c
  head/sys/dev/etherswitch/rtl8366/rtl8366rb.c
  head/sys/dev/etherswitch/ukswitch/ukswitch.c

Modified: head/sys/dev/etherswitch/arswitch/arswitch.c
==============================================================================
--- head/sys/dev/etherswitch/arswitch/arswitch.c        Wed Jan 24 21:26:01 
2018        (r328376)
+++ head/sys/dev/etherswitch/arswitch/arswitch.c        Wed Jan 24 21:33:18 
2018        (r328377)
@@ -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;

Modified: head/sys/dev/etherswitch/e6000sw/e6060sw.c
==============================================================================
--- head/sys/dev/etherswitch/e6000sw/e6060sw.c  Wed Jan 24 21:26:01 2018        
(r328376)
+++ head/sys/dev/etherswitch/e6000sw/e6060sw.c  Wed Jan 24 21:33:18 2018        
(r328377)
@@ -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;

Modified: head/sys/dev/etherswitch/infineon/adm6996fc.c
==============================================================================
--- head/sys/dev/etherswitch/infineon/adm6996fc.c       Wed Jan 24 21:26:01 
2018        (r328376)
+++ head/sys/dev/etherswitch/infineon/adm6996fc.c       Wed Jan 24 21:33:18 
2018        (r328377)
@@ -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;

Modified: head/sys/dev/etherswitch/ip17x/ip17x.c
==============================================================================
--- head/sys/dev/etherswitch/ip17x/ip17x.c      Wed Jan 24 21:26:01 2018        
(r328376)
+++ head/sys/dev/etherswitch/ip17x/ip17x.c      Wed Jan 24 21:33:18 2018        
(r328377)
@@ -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;

Modified: head/sys/dev/etherswitch/micrel/ksz8995ma.c
==============================================================================
--- head/sys/dev/etherswitch/micrel/ksz8995ma.c Wed Jan 24 21:26:01 2018        
(r328376)
+++ head/sys/dev/etherswitch/micrel/ksz8995ma.c Wed Jan 24 21:33:18 2018        
(r328377)
@@ -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;

Modified: head/sys/dev/etherswitch/mtkswitch/mtkswitch.c
==============================================================================
--- head/sys/dev/etherswitch/mtkswitch/mtkswitch.c      Wed Jan 24 21:26:01 
2018        (r328376)
+++ head/sys/dev/etherswitch/mtkswitch/mtkswitch.c      Wed Jan 24 21:33:18 
2018        (r328377)
@@ -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;

Modified: head/sys/dev/etherswitch/rtl8366/rtl8366rb.c
==============================================================================
--- head/sys/dev/etherswitch/rtl8366/rtl8366rb.c        Wed Jan 24 21:26:01 
2018        (r328376)
+++ head/sys/dev/etherswitch/rtl8366/rtl8366rb.c        Wed Jan 24 21:33:18 
2018        (r328377)
@@ -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;

Modified: head/sys/dev/etherswitch/ukswitch/ukswitch.c
==============================================================================
--- head/sys/dev/etherswitch/ukswitch/ukswitch.c        Wed Jan 24 21:26:01 
2018        (r328376)
+++ head/sys/dev/etherswitch/ukswitch/ukswitch.c        Wed Jan 24 21:33:18 
2018        (r328377)
@@ -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;
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to