Module Name:    src
Committed By:   cegger
Date:           Sun May 17 14:36:46 UTC 2009

Modified Files:
        src/sys/dev/sdmmc: sdhc.c

Log Message:
fix crash with LOCKDEBUG+DIAGNOSTIC kernels:

sdhc_bus_clock() calls mutex_enter().
then in DIAGNOSTIC section, sdhc_bus_clock() calls sdhc_card_detect().
sdhc_card_detect() calls mutex_enter() on the same mutex again.
when LOCKDEBUG is enabled, you get

Mutex error: lockdebug_wantlock: locking against myself


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/sdmmc/sdhc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/sdhc.c
diff -u src/sys/dev/sdmmc/sdhc.c:1.1 src/sys/dev/sdmmc/sdhc.c:1.2
--- src/sys/dev/sdmmc/sdhc.c:1.1	Tue Apr 21 03:00:30 2009
+++ src/sys/dev/sdmmc/sdhc.c	Sun May 17 14:36:46 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc.c,v 1.1 2009/04/21 03:00:30 nonaka Exp $	*/
+/*	$NetBSD: sdhc.c,v 1.2 2009/05/17 14:36:46 cegger Exp $	*/
 /*	$OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.1 2009/04/21 03:00:30 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.2 2009/05/17 14:36:46 cegger Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -558,17 +558,23 @@
 	int div;
 	int timo;
 	int error = 0;
+#ifdef DIAGNOSTIC
+	int ispresent;
+#endif
 
+#ifdef DIAGNOSTIC
 	mutex_enter(&hp->host_mtx);
+	ispresent = ISSET(HREAD4(hp, SDHC_PRESENT_STATE), SDHC_CMD_INHIBIT_MASK);
+	mutex_exit(&hp->host_mtx);
 
-#ifdef DIAGNOSTIC
 	/* Must not stop the clock if commands are in progress. */
-	if (ISSET(HREAD4(hp, SDHC_PRESENT_STATE), SDHC_CMD_INHIBIT_MASK) &&
-	    sdhc_card_detect(hp))
+	if (ispresent && sdhc_card_detect(hp))
 		printf("%s: sdhc_sdclk_frequency_select: command in progress\n",
 		    device_xname(hp->sc->sc_dev));
 #endif
 
+	mutex_enter(&hp->host_mtx);
+
 	/*
 	 * Stop SD clock before changing the frequency.
 	 */

Reply via email to