Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Complete the initialization of tap_softc before if_a...



details:   https://anonhg.NetBSD.org/src/rev/d6c005c63be4
branches:  trunk
changeset: 333521:d6c005c63be4
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Nov 07 09:26:08 2014 +0000

description:
Complete the initialization of tap_softc before if_attach

Basically we should complete the initializaiton of softc before if_attach
because once if_attach is called if_detach can be called for the softc
before returning from if_attach. In case of tap, mutex_destroy can be
called before mutex_init that comes after if_attach.

diffstat:

 sys/net/if_tap.c |  44 +++++++++++++++++++++-----------------------
 1 files changed, 21 insertions(+), 23 deletions(-)

diffs (79 lines):

diff -r 37a960a33420 -r d6c005c63be4 sys/net/if_tap.c
--- a/sys/net/if_tap.c  Fri Nov 07 05:37:05 2014 +0000
+++ b/sys/net/if_tap.c  Fri Nov 07 09:26:08 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_tap.c,v 1.79 2014/10/03 06:46:02 skrll Exp $        */
+/*     $NetBSD: if_tap.c,v 1.80 2014/11/07 09:26:08 ozaki-r 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.79 2014/10/03 06:46:02 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.80 2014/11/07 09:26:08 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -275,6 +275,25 @@
        sc->sc_sih = NULL;
        getnanotime(&sc->sc_btime);
        sc->sc_atime = sc->sc_mtime = sc->sc_btime;
+       sc->sc_flags = 0;
+       selinit(&sc->sc_rsel);
+
+       /*
+        * Initialize the two locks for the device.
+        *
+        * We need a lock here because even though the tap device can be
+        * opened only once, the file descriptor might be passed to another
+        * process, say a fork(2)ed child.
+        *
+        * The Giant saves us from most of the hassle, but since the read
+        * operation can sleep, we don't want two processes to wake up at
+        * the same moment and both try and dequeue a single packet.
+        *
+        * The queue for event listeners (used by kqueue(9), see below) has
+        * to be protected too, so use a spin lock.
+        */
+       mutex_init(&sc->sc_rdlock, MUTEX_DEFAULT, IPL_NONE);
+       mutex_init(&sc->sc_kqlock, MUTEX_DEFAULT, IPL_VM);
 
        if (!pmf_device_register(self, NULL, NULL))
                aprint_error_dev(self, "couldn't establish power handler\n");
@@ -327,8 +346,6 @@
        if_attach(ifp);
        ether_ifattach(ifp, enaddr);
 
-       sc->sc_flags = 0;
-
 #if defined(COMPAT_40) || defined(MODULAR)
        /*
         * Add a sysctl node for that interface.
@@ -353,25 +370,6 @@
                aprint_error_dev(self, "sysctl_createv returned %d, ignoring\n",
                    error);
 #endif
-
-       /*
-        * Initialize the two locks for the device.
-        *
-        * We need a lock here because even though the tap device can be
-        * opened only once, the file descriptor might be passed to another
-        * process, say a fork(2)ed child.
-        *
-        * The Giant saves us from most of the hassle, but since the read
-        * operation can sleep, we don't want two processes to wake up at
-        * the same moment and both try and dequeue a single packet.
-        *
-        * The queue for event listeners (used by kqueue(9), see below) has
-        * to be protected too, so use a spin lock.
-        */
-       mutex_init(&sc->sc_rdlock, MUTEX_DEFAULT, IPL_NONE);
-       mutex_init(&sc->sc_kqlock, MUTEX_DEFAULT, IPL_VM);
-
-       selinit(&sc->sc_rsel);
 }
 
 /*



Home | Main Index | Thread Index | Old Index