Re: Driver not unset properly after kldunload

2006-12-07 Thread Iasen Kostov
On Wed, 2006-12-06 at 11:35 -0500, John Baldwin wrote:
...
 I don't see why this patch changes things.  devclass_delete_device() only 
 clears dev-unit, dev-devclass, and dev-nameunit.  device_set_driver() 
 doesn't check or clear any of those.  In fact, your change does make 
 device_set_driver() not work at all since the device state will still be 
 DS_ATTACHED when you call device_set_driver() now.  So, I guess your patch 
 actually makes the device _not_ be detached from the driver.
 
Forgive me for being so lazy :). I've analized the problem as I should
have done the first time and I hope I found the solution. First time I
was missleaded by sys/dev/pci/pci_user.c and the way it sets pd_name[]
in pci_devinfo struct (You actualy need to use pciconf atleast once
after loading the driver) ... It's only set when you use PCIOCGETCONF
ioctl on /dev/pci and it only sets it once (which is not very clever)
and never unset it. But one can unload the current driver and load
another (as in if_nfe, if_nve case) or just unload the driver and
pd_name[] will always show the first driver attached on that device.
So I hope this new patch is better one.


--- sys/dev/pci/pci_user.c.old	Thu Dec  7 02:26:12 2006
+++ sys/dev/pci/pci_user.c	Thu Dec  7 02:52:23 2006
@@ -303,14 +303,18 @@
 
 			/* Populate pd_name and pd_unit */
 			name = NULL;
-			if (dinfo-cfg.dev  dinfo-conf.pd_name[0] == '\0')
+			if (dinfo-cfg.dev) {
 name = device_get_name(dinfo-cfg.dev);
-			if (name) {
-strncpy(dinfo-conf.pd_name, name,
-	sizeof(dinfo-conf.pd_name));
-dinfo-conf.pd_name[PCI_MAXNAMELEN] = 0;
-dinfo-conf.pd_unit =
-	device_get_unit(dinfo-cfg.dev);
+if (name) {
+	strncpy(dinfo-conf.pd_name, name,
+		sizeof(dinfo-conf.pd_name));
+	dinfo-conf.pd_name[PCI_MAXNAMELEN] = 0;
+	dinfo-conf.pd_unit =
+		device_get_unit(dinfo-cfg.dev);
+} else {
+	dinfo-conf.pd_name[0] = '\0';
+	dinfo-conf.pd_unit = 0;
+}
 			}
 
 			if ((pattern_buf == NULL) ||
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]

Re: Driver not unset properly after kldunload

2006-12-06 Thread John Baldwin
On Wednesday 29 November 2006 18:18, Iasen Kostoff wrote:
   Hi,
 It seems that after I load and then unload a driver its name stays
 linked to the device e.g:
 
 [EMAIL PROTECTED]:10:0: class=0x068000 card=0x81411043 chip=0x005710de 
 rev=0xa3
 hdr=0x00
 
 but of course 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 at least
 device_set_driver(dev, NULL) - it doesn't unset the driver. I'm not so
 sure about the other 2 but I guess it's same there. So when I changed the
 order of this funcs everything worked fine (at least it looks like it
 worked fine :) I'm not absolutely sure that this won't broke something
 else). I've attached a patch for review.

I don't see why this patch changes things.  devclass_delete_device() only 
clears dev-unit, dev-devclass, and dev-nameunit.  device_set_driver() 
doesn't check or clear any of those.  In fact, your change does make 
device_set_driver() not work at all since the device state will still be 
DS_ATTACHED when you call device_set_driver() now.  So, I guess your patch 
actually makes the device _not_ be detached from the driver.

-- 
John Baldwin
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Driver not unset properly after kldunload

2006-11-29 Thread Iasen Kostoff
  Hi,
It seems that after I load and then unload a driver its name stays
linked to the device e.g:

[EMAIL PROTECTED]:10:0: class=0x068000 card=0x81411043 chip=0x005710de rev=0xa3
hdr=0x00

but of course 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 at least
device_set_driver(dev, NULL) - it doesn't unset the driver. I'm not so
sure about the other 2 but I guess it's same there. So when I changed the
order of this funcs everything worked fine (at least it looks like it
worked fine :) I'm not absolutely sure that this won't broke something
else). I've attached a patch for review.

(I've filled a PR http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/104777)

--- subr_bus.c.bak	Sun Oct 22 18:42:11 2006
+++ 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);
 }
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]