Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 May 2017 15:58:39 +0000 (UTC)
From:      Zbigniew Bodek <zbb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r318410 - head/sys/dev/etherswitch/e6000sw
Message-ID:  <201705171558.v4HFwde0001621@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: zbb
Date: Wed May 17 15:58:39 2017
New Revision: 318410
URL: https://svnweb.freebsd.org/changeset/base/318410

Log:
  Fix broken malloc in e6000sw
  
  Malloc should always return something when M_WAITOK flag is used,
  but keep this code and change flag to M_NOWAIT as it is under a lock
  (allows for possible future change). Free ifnet structure to avoid
  memory leak on failure.
  
  Submitted by:  Zbigniew Bodek <zbb@semihalf.com>
  Obtained from: Semihalf
  Sponsored by:  Stormshield
  Reviewed by: loos
  Differential revision: https://reviews.freebsd.org/D10711

Modified:
  head/sys/dev/etherswitch/e6000sw/e6000sw.c

Modified: head/sys/dev/etherswitch/e6000sw/e6000sw.c
==============================================================================
--- head/sys/dev/etherswitch/e6000sw/e6000sw.c	Wed May 17 15:57:14 2017	(r318409)
+++ head/sys/dev/etherswitch/e6000sw/e6000sw.c	Wed May 17 15:58:39 2017	(r318410)
@@ -321,9 +321,11 @@ e6000sw_init_interface(e6000sw_softc_t *
 	sc->ifp[port]->if_softc = sc;
 	sc->ifp[port]->if_flags |= IFF_UP | IFF_BROADCAST |
 	    IFF_DRV_RUNNING | IFF_SIMPLEX;
-	sc->ifname[port] = malloc(strlen(name) + 1, M_E6000SW, M_WAITOK);
-	if (sc->ifname[port] == NULL)
+	sc->ifname[port] = malloc(strlen(name) + 1, M_E6000SW, M_NOWAIT);
+	if (sc->ifname[port] == NULL) {
+		if_free(sc->ifp[port]);
 		return (ENOMEM);
+	}
 	memcpy(sc->ifname[port], name, strlen(name) + 1);
 	if_initname(sc->ifp[port], sc->ifname[port], port);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705171558.v4HFwde0001621>