Subject: kern/34013: system crash when unload a LKM driver
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <georgechen2101@msn.com>
List: netbsd-bugs
Date: 07/16/2006 08:45:00
>Number:         34013
>Category:       kern
>Synopsis:       system crash when unload a LKM driver
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 16 08:45:00 +0000 2006
>Originator:     George Chen
>Release:        3.0
>Organization:
Semptian Technologies
>Environment:
NetBSD fw022 3.0 NetBSD 3.0 (SEMPOS.debug) #128: Thu Jun 22 09:26:34 CST 2006  george@fw022:/home/george/usr/src/sys/arch/i386/compile/SEMPOS.debug i386

>Description:
System got crash when unload a LKM driver, which is supported by pcilkm.o.

>How-To-Repeat:
modload -s pcilkm.o
modload pcienum.o
modunload pcienum.o

>Fix:
The problem was introduced by pcilkm_lkm.c. It can be fixed by adding 7 lines.

in function of pcilkm_hostlkmunload(), the original code is

---int error, i;
---
---for (i = 0; i<pld->pld_cfd->cd_ndevs; i++) 
	if ((error = config_detach(pld->pld_cfd->cd_devs[i], 0)) != 0)
		return error;
The modified lines are
+++int error, i;
+++struct device * parent, * dev;
+++void * save;
+++
+++for (i = 0; i<pld->pld_cfd->cd_ndevs; i++) {
+++	dev=pld->pld_cfd->cd_devs[i];
+++	parent = dev->dv_parent;
+++	save = parent->dv_cfattach->ca_childdetached;
+++	parent->dv_cfattach->ca_childdetached = NULL;
+++		
+++	if ((error = config_detach(pld->pld_cfd->cd_devs[i], 0)) != 0)
+++		return error;
+++	parent->dv_cfattach->ca_childdetached = save;
+++}