From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 29 23:19:00 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1DCCA16A504 for ; Wed, 29 Nov 2006 23:19:00 +0000 (UTC) (envelope-from tbyte@otel.net) Received: from mail.otel.net (gw3.OTEL.net [212.36.8.151]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5F8CF43C9D for ; Wed, 29 Nov 2006 23:18:55 +0000 (GMT) (envelope-from tbyte@otel.net) Received: from warhead.otel.net ([212.36.8.210]) by mail.otel.net with esmtp (Exim 4.63 (FreeBSD)) (envelope-from ) id 1GpYhc-000Hxr-Rq for freebsd-hackers@freebsd.org; Thu, 30 Nov 2006 01:18:57 +0200 From: Iasen Kostoff To: freebsd-hackers@freebsd.org Content-Type: multipart/mixed; boundary="=-PAH/twysuwDrzpoEvaGo" Date: Thu, 30 Nov 2006 01:18:56 +0200 Message-Id: <1164842336.1066.6.camel@WarHeaD.OTEL.net> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2.1 FreeBSD GNOME Team Port Subject: Driver not unset properly after kldunload X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Nov 2006 23:19:00 -0000 --=-PAH/twysuwDrzpoEvaGo Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi, 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 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) --=-PAH/twysuwDrzpoEvaGo Content-Disposition: attachment; filename=subr_bus.c.diff Content-Type: text/x-patch; name=subr_bus.c.diff; charset=us-ascii Content-Transfer-Encoding: 7bit --- 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); } --=-PAH/twysuwDrzpoEvaGo--