From nobody@FreeBSD.org  Wed Dec  5 05:46:16 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A399A16A420
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  5 Dec 2007 05:46:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 8F31F13C46E
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  5 Dec 2007 05:46:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id lB55kDa5039075
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 5 Dec 2007 05:46:13 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id lB55kDwi039074;
	Wed, 5 Dec 2007 05:46:13 GMT
	(envelope-from nobody)
Message-Id: <200712050546.lB55kDwi039074@www.freebsd.org>
Date: Wed, 5 Dec 2007 05:46:13 GMT
From: Weongyo Jeong <weongyo.jeong@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] if_ndis - fix a panic when ndis_attach() failed.
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         118439
>Category:       kern
>Synopsis:       [ndis] [patch] if_ndis - fix a panic when ndis_attach() failed.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    thompsa
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 05 05:50:01 UTC 2007
>Closed-Date:    Fri Mar 15 23:34:36 UTC 2013
>Last-Modified:  Fri Mar 15 23:34:36 UTC 2013
>Originator:     Weongyo Jeong
>Release:        FreeBSD-CURRENT
>Organization:
CDNetworks
>Environment:
>Description:
When ndis_attach() failed to initialize a device, it always call ndis_detach().
However, the problem is that it can try to call taskqueue_drain() or taskqueue_free() of sc->ndis_tq before taskqueue_create() function is called.

sc->ndis_tq variable is only initialized when a driver module is for wireless NICs.

This problem can drive the kernel to a panic.

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: if_ndis.c
===================================================================
RCS file: /data/cvs/src/sys/dev/if_ndis/if_ndis.c,v
retrieving revision 1.128
diff -u -r1.128 if_ndis.c
--- if_ndis.c	4 Dec 2007 20:48:32 -0000	1.128
+++ if_ndis.c	5 Dec 2007 02:49:17 -0000
@@ -958,7 +958,8 @@
 	} else
 		NDIS_UNLOCK(sc);
 
-	taskqueue_drain(sc->ndis_tq, &sc->ndis_scantask);
+	if (sc->ndis_80211)
+		taskqueue_drain(sc->ndis_tq, &sc->ndis_scantask);
 
 	if (sc->ndis_tickitem != NULL)
 		IoFreeWorkItem(sc->ndis_tickitem);
@@ -1017,7 +1018,8 @@
 	if (sc->ndis_iftype == PCIBus)
 		bus_dma_tag_destroy(sc->ndis_parent_tag);
 
-	taskqueue_free(sc->ndis_tq);
+	if (sc->ndis_80211)
+		taskqueue_free(sc->ndis_tq);
 	return(0);
 }
 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->thompsa 
Responsible-Changed-By: thompsa 
Responsible-Changed-When: Fri Dec 7 10:46:30 UTC 2007 
Responsible-Changed-Why:  
I'll take care of this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=118439 
State-Changed-From-To: open->patched 
State-Changed-By: thompsa 
State-Changed-When: Sun Dec 9 20:14:39 UTC 2007 
State-Changed-Why:  
Committed to HEAD, thanks for the patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=118439 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/118439: commit references a PR
Date: Sun,  9 Dec 2007 20:14:09 +0000 (UTC)

 thompsa     2007-12-09 20:14:01 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/dev/if_ndis      if_ndis.c 
   Log:
   sc->ndis_tq variable is only initialized when a driver module is for wireless
   NICs.
   
   PR:             kern/118439
   Submitted by:   Weongyo Jeong
   
   Revision  Changes    Path
   1.130     +4 -2      src/sys/dev/if_ndis/if_ndis.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Fri Mar 15 23:34:36 UTC 2013 
State-Changed-Why:  
MFCed/fixed by now or it will never be MFCed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=118439 
>Unformatted:
