Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net - If if_initialize() failed in the attach function, ...
details: https://anonhg.NetBSD.org/src/rev/7c0a53a2e4a1
branches: trunk
changeset: 357016:7c0a53a2e4a1
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Mon Oct 23 09:32:33 2017 +0000
description:
- If if_initialize() failed in the attach function, free resources and return.
- KNF
diffstat:
sys/net/if_pppoe.c | 43 +++++++++++++++++++++++++++----------------
sys/net/if_tap.c | 22 ++++++++++++++++------
2 files changed, 43 insertions(+), 22 deletions(-)
diffs (198 lines):
diff -r 49f83decc38e -r 7c0a53a2e4a1 sys/net/if_pppoe.c
--- a/sys/net/if_pppoe.c Mon Oct 23 09:32:00 2017 +0000
+++ b/sys/net/if_pppoe.c Mon Oct 23 09:32:33 2017 +0000
@@ -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_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 @@
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 @@
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 @@
}
rw_exit(&pppoe_softc_list_lock);
-
bpf_detach(ifp);
sppp_detach(&sc->sc_sppp.pp_if);
if_detach(ifp);
@@ -379,7 +386,7 @@
free(sc, M_DEVBUF);
- return (0);
+ return 0;
}
/*
@@ -634,8 +641,9 @@
#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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 */
diff -r 49f83decc38e -r 7c0a53a2e4a1 sys/net/if_tap.c
--- a/sys/net/if_tap.c Mon Oct 23 09:32:00 2017 +0000
+++ b/sys/net/if_tap.c Mon Oct 23 09:32:33 2017 +0000
@@ -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 @@
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_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 @@
"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);
Home |
Main Index |
Thread Index |
Old Index