Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Oct 2006 00:15:56 +0300
From:      "Iasen Kostoff" <tbyte@otel.net>
To:        "FreeBSD gnats submit" <FreeBSD-gnats-submit@FreeBSD.org>
Subject:   kern/104777: Driver not unset properly after kldunload
Message-ID:  <1161724556.33505@WarHeaD.OTEL.net>
Resent-Message-ID: <200610242120.k9OLKN2x029862@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         104777
>Category:       kern
>Synopsis:       Driver not unset properly after kldunload
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 24 21:20:23 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Iasen Kostoff
>Release:        FreeBSD 6.2-PRERELEASE i386
>Organization:
OTEL.net 
>Environment:


System: FreeBSD 6.2-PRERELEASE #0: Tue Sep 19 21:43:51 EEST 2006
    root@WarHeaD.OTEL.net:/usr/obj/usr/src6/sys/WARHEAD



>Description:



It seems that after I load and then unload a driver its name stays
linked to the device e.g:

nfe0@pci0:10:0: class=0x068000 card=0x81411043 chip=0x005710de rev=0xa3
hdr=0x00

but ofcourse if_nfe is neither compiled in kernel nor is loaded as
module anymore.
  I digged around in kernel and saw this in device_detach():

        if (!(dev->flags & DF_FIXEDCLASS))
                devclass_delete_device(dev->devclass, dev);

        dev->state = DS_NOTPRESENT;
        device_set_driver(dev, NULL);
        device_set_desc(dev, NULL);
        device_sysctl_fini(dev);

I've put some device_printf()s around and then looked at
devclass_delete_device(). It destroys (frees) a lot of the info about
the device and so the device_printf() prints device name as
"unknown" (NULL). That seems to be a problem for atleast
device_set_driver(dev, NULL) - it dosn't unset the driver. I'm not so
sure about the other 2 but I gues it same there. So when I changed the
order of this funcs everything worked fine (atleast it looks like it
worked fine :) I'm not absolutely sure that this won't broke something
else).


>How-To-Repeat:


Load and unload some driver.



>Fix:


--- subr_bus.c.diff begins here ---
--- sys/kern/subr_bus.c.bak	Sun Oct 22 18:42:11 2006
+++ sys/kern/subr_bus.c	Mon Oct 23 00:27:22 2006
@@ -2417,13 +2417,14 @@
 	if (dev->parent)
 		BUS_CHILD_DETACHED(dev->parent, dev);
 
+	device_set_driver(dev, NULL);
+	device_set_desc(dev, NULL);
+	device_sysctl_fini(dev);
+	
 	if (!(dev->flags & DF_FIXEDCLASS))
 		devclass_delete_device(dev->devclass, dev);
 
 	dev->state = DS_NOTPRESENT;
-	device_set_driver(dev, NULL);
-	device_set_desc(dev, NULL);
-	device_sysctl_fini(dev);
 
 	return (0);
 }
--- subr_bus.c.diff ends here ---



>Release-Note:
>Audit-Trail:
>Unformatted:



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