Module Name:    src
Committed By:   pgoyette
Date:           Sun Apr 30 05:18:53 UTC 2017

Modified Files:
        src/sys/kern [prg-localcount2]: subr_autoconf.c

Log Message:
Release the interlock mutex before calling device_release().

Ensure that device_release() gets called even if the (ca->ca_detach)()
call fails.


To generate a diff of this commit:
cvs rdiff -u -r1.252.4.2 -r1.252.4.3 src/sys/kern/subr_autoconf.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/kern/subr_autoconf.c
diff -u src/sys/kern/subr_autoconf.c:1.252.4.2 src/sys/kern/subr_autoconf.c:1.252.4.3
--- src/sys/kern/subr_autoconf.c:1.252.4.2	Fri Apr 28 06:00:33 2017
+++ src/sys/kern/subr_autoconf.c	Sun Apr 30 05:18:53 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.252.4.2 2017/04/28 06:00:33 pgoyette Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.252.4.3 2017/04/30 05:18:53 pgoyette Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.252.4.2 2017/04/28 06:00:33 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.252.4.3 2017/04/30 05:18:53 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1277,9 +1277,13 @@ config_devunlink(device_t dev, struct de
 
 	/*
 	 * Release the reference that was held by (the caller of)
-	 * config_detach_release()
+	 * config_detach_release().  Note that since device_release()
+	 * might need to acquire the alldevs.lock mutex, we need to
+	 * release and then reacquire the mutex.
 	 */
+	mutex_exit(&alldevs.lock);
 	device_release(dev);
+	mutex_enter(&alldevs.lock);
 
 	/* Now wait for references to drain - no new refs are possible */
 	localcount_drain(&dev->dv_localcnt, &config_drain_cv,
@@ -1866,6 +1870,8 @@ out:
 		}
 	}
 	config_alldevs_exit(&af);
+	if (rv != 0)
+		device_release(dev);
 
 	return rv;
 }

Reply via email to