1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-18 10:35:55 +00:00

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
This commit is contained in:
Zbigniew Bodek 2017-05-17 15:58:39 +00:00
parent b488f7aaa5
commit 7118192a72
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=318410

View File

@ -321,9 +321,11 @@ e6000sw_init_interface(e6000sw_softc_t *sc, int port)
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);