Module Name: src Committed By: msaitoh Date: Mon Oct 23 09:32:33 UTC 2017
Modified Files: src/sys/net: if_pppoe.c if_tap.c Log Message: - If if_initialize() failed in the attach function, free resources and return. - KNF To generate a diff of this commit: cvs rdiff -u -r1.128 -r1.129 src/sys/net/if_pppoe.c cvs rdiff -u -r1.99 -r1.100 src/sys/net/if_tap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_pppoe.c diff -u src/sys/net/if_pppoe.c:1.128 src/sys/net/if_pppoe.c:1.129 --- src/sys/net/if_pppoe.c:1.128 Thu Oct 12 09:49:43 2017 +++ src/sys/net/if_pppoe.c Mon Oct 23 09:32:33 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_pppoe.c,v 1.128 2017/10/12 09:49:43 knakahara Exp $ */ +/* $NetBSD: if_pppoe.c,v 1.129 2017/10/23 09:32:33 msaitoh Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.128 2017/10/12 09:49:43 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.129 2017/10/23 09:32:33 msaitoh Exp $"); #ifdef _KERNEL_OPT #include "pppoe.h" @@ -223,7 +223,8 @@ static int pppoe_send_padt(struct ifnet static int pppoe_output(struct pppoe_softc *, struct mbuf *); /* internal helper functions */ -static struct pppoe_softc * pppoe_find_softc_by_session(u_int, struct ifnet *, krw_t); +static struct pppoe_softc * pppoe_find_softc_by_session(u_int, struct ifnet *, + krw_t); static struct pppoe_softc * pppoe_find_softc_by_hunique(uint8_t *, size_t, struct ifnet *, krw_t); static struct mbuf *pppoe_get_mbuf(size_t len); @@ -293,6 +294,7 @@ static int pppoe_clone_create(struct if_clone *ifc, int unit) { struct pppoe_softc *sc; + int rv; sc = malloc(sizeof(struct pppoe_softc), M_DEVBUF, M_WAITOK|M_ZERO); @@ -325,7 +327,13 @@ pppoe_clone_create(struct if_clone *ifc, sc->sc_sppp.pp_tlf = pppoe_tlf; sc->sc_sppp.pp_framebytes = PPPOE_HEADERLEN; /* framing added to ppp packets */ - if_initialize(&sc->sc_sppp.pp_if); + rv = if_initialize(&sc->sc_sppp.pp_if); + if (rv != 0) { + callout_halt(&sc->sc_timeout, NULL); + callout_destroy(&sc->sc_timeout); + free(sc, M_DEVBUF); + return rv; + } sc->sc_sppp.pp_if.if_percpuq = if_percpuq_create(&sc->sc_sppp.pp_if); sppp_attach(&sc->sc_sppp.pp_if); if_register(&sc->sc_sppp.pp_if); @@ -360,7 +368,6 @@ pppoe_clone_destroy(struct ifnet *ifp) } rw_exit(&pppoe_softc_list_lock); - bpf_detach(ifp); sppp_detach(&sc->sc_sppp.pp_if); if_detach(ifp); @@ -379,7 +386,7 @@ pppoe_clone_destroy(struct ifnet *ifp) free(sc, M_DEVBUF); - return (0); + return 0; } /* @@ -634,8 +641,9 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, #endif rcvif = m_get_rcvif_psref(m, &psref); if (rcvif != NULL) { - sc = pppoe_find_softc_by_hunique(mtod(n, char *) + noff, - len, rcvif, RW_READER); + sc = pppoe_find_softc_by_hunique( + mtod(n, char *) + noff, len, rcvif, + RW_READER); } m_put_rcvif_psref(rcvif, &psref); if (sc != NULL) { @@ -1015,8 +1023,7 @@ pppoe_data_input(struct mbuf *m) struct mbuf *p; printf("%s: pkthdr.len=%d, pppoe.len=%d", - sc->sc_sppp.pp_if.if_xname, - m->m_pkthdr.len, plen); + sc->sc_sppp.pp_if.if_xname, m->m_pkthdr.len, plen); p = m; while (p) { printf(" l=%d", p->m_len); @@ -1030,7 +1037,10 @@ pppoe_data_input(struct mbuf *m) if (m->m_pkthdr.len < plen) goto drop; - /* fix incoming interface pointer (not the raw ethernet interface anymore) */ + /* + * Fix incoming interface pointer (not the raw ethernet interface + * anymore) + */ m_set_rcvif(m, &sc->sc_sppp.pp_if); /* pass packet up and account for it */ @@ -1059,7 +1069,8 @@ pppoe_output(struct pppoe_softc *sc, str memset(&dst, 0, sizeof dst); dst.sa_family = AF_UNSPEC; eh = (struct ether_header*)&dst.sa_data; - etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHERTYPE_PPPOE : ETHERTYPE_PPPOEDISC; + etype = sc->sc_state == PPPOE_STATE_SESSION + ? ETHERTYPE_PPPOE : ETHERTYPE_PPPOEDISC; eh->ether_type = htons(etype); memcpy(&eh->ether_dhost, &sc->sc_dest, sizeof sc->sc_dest); @@ -1090,7 +1101,7 @@ pppoe_ioctl(struct ifnet *ifp, unsigned if (kauth_authorize_network(l->l_cred, KAUTH_NETWORK_INTERFACE, KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd, NULL) != 0) - return (EPERM); + return EPERM; if (parms->eth_ifname[0] != 0) { struct ifnet *eth_if; @@ -1383,8 +1394,7 @@ pppoe_timeout(void *arg) if (sc->sc_sppp.pp_if.if_flags & IFF_DEBUG) printf("%s: failed to send PADI" ", error=%d\n", - sc->sc_sppp.pp_if.if_xname, - err); + sc->sc_sppp.pp_if.if_xname, err); } callout_reset(&sc->sc_timeout, PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried), @@ -1462,7 +1472,8 @@ pppoe_disconnect(struct pppoe_softc *sc) if (sc->sc_sppp.pp_if.if_flags & IFF_DEBUG) printf("%s: disconnecting\n", sc->sc_sppp.pp_if.if_xname); - err = pppoe_send_padt(sc->sc_eth_if, sc->sc_session, (const uint8_t *)&sc->sc_dest); + err = pppoe_send_padt(sc->sc_eth_if, sc->sc_session, + (const uint8_t *)&sc->sc_dest); } /* cleanup softc */ Index: src/sys/net/if_tap.c diff -u src/sys/net/if_tap.c:1.99 src/sys/net/if_tap.c:1.100 --- src/sys/net/if_tap.c:1.99 Sun Feb 12 09:47:31 2017 +++ src/sys/net/if_tap.c Mon Oct 23 09:32:33 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if_tap.c,v 1.99 2017/02/12 09:47:31 skrll Exp $ */ +/* $NetBSD: if_tap.c,v 1.100 2017/10/23 09:32:33 msaitoh Exp $ */ /* * Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation. @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.99 2017/02/12 09:47:31 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.100 2017/10/23 09:32:33 msaitoh Exp $"); #if defined(_KERNEL_OPT) @@ -379,7 +379,17 @@ tap_attach(device_t parent, device_t sel sc->sc_ec.ec_capabilities = ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU; /* Those steps are mandatory for an Ethernet driver. */ - if_initialize(ifp); + error = if_initialize(ifp); + if (error != 0) { + aprint_error_dev(self, "if_initialize failed(%d)\n", error); + ifmedia_removeall(&sc->sc_im); + pmf_device_deregister(self); + mutex_destroy(&sc->sc_rdlock); + mutex_destroy(&sc->sc_kqlock); + seldestroy(&sc->sc_rsel); + + return; /* Error */ + } ether_ifattach(ifp, enaddr); if_register(ifp); @@ -403,8 +413,8 @@ tap_attach(device_t parent, device_t sel tap_sysctl_handler, 0, (void *)sc, 18, CTL_NET, AF_LINK, tap_node, device_unit(sc->sc_dev), CTL_EOL)) != 0) - aprint_error_dev(self, "sysctl_createv returned %d, ignoring\n", - error); + aprint_error_dev(self, + "sysctl_createv returned %d, ignoring\n", error); } /* @@ -441,7 +451,7 @@ tap_detach(device_t self, int flags) "sysctl_destroyv returned %d, ignoring\n", error); ether_ifdetach(ifp); if_detach(ifp); - ifmedia_delete_instance(&sc->sc_im, IFM_INST_ANY); + ifmedia_removeall(&sc->sc_im); seldestroy(&sc->sc_rsel); mutex_destroy(&sc->sc_rdlock); mutex_destroy(&sc->sc_kqlock);