Module Name:    src
Committed By:   msaitoh
Date:           Wed Sep  6 11:08:54 UTC 2017

Modified Files:
        src/sys/dev/sysmon: sysmon_envsys.c sysmon_envsys_events.c

Log Message:
 Fixes a problem that some driver(e.g. acpitz(4) or coretemp(5)) which
use sysmon_envsys sleep waiting at "rndsrc" when "drvctl -d".
Don't call rnd_detach_source() in sme_remove_event() which is called
from sme_event_unregister_all(). Instead, call rnd_detach_source() in
sysmon_envsys_sensor_detach() and call sysmon_envsys_sensor_detach()
before sme_event_unregister_sensor(). Each sensor(envsys_data) has each
rnd_src, but some sme_events point to the same rnd_src in a sensor.
Calling rnd_detach_souce() twice with the same rnd_src brokes a reference
count in rnd_src. OK'd by pgoyette@.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/dev/sysmon/sysmon_envsys.c
cvs rdiff -u -r1.119 -r1.120 src/sys/dev/sysmon/sysmon_envsys_events.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/sysmon/sysmon_envsys.c
diff -u src/sys/dev/sysmon/sysmon_envsys.c:1.139 src/sys/dev/sysmon/sysmon_envsys.c:1.140
--- src/sys/dev/sysmon/sysmon_envsys.c:1.139	Mon Dec 14 01:08:47 2015
+++ src/sys/dev/sysmon/sysmon_envsys.c	Wed Sep  6 11:08:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysmon_envsys.c,v 1.139 2015/12/14 01:08:47 pgoyette Exp $	*/
+/*	$NetBSD: sysmon_envsys.c,v 1.140 2017/09/06 11:08:53 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.139 2015/12/14 01:08:47 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys.c,v 1.140 2017/09/06 11:08:53 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -650,6 +650,8 @@ sysmon_envsys_sensor_detach(struct sysmo
 	/*
 	 * remove it, unhook from rnd(4), and decrement the sensors count.
 	 */
+	if (oedata->flags & ENVSYS_FHAS_ENTROPY)
+		rnd_detach_source(&oedata->rnd_src);
 	sme_event_unregister_sensor(sme, edata);
 	if (LIST_EMPTY(&sme->sme_events_list)) {
 		sme_events_halt_callout(sme);
@@ -970,6 +972,7 @@ sysmon_envsys_unregister(struct sysmon_e
 {
 	prop_array_t array;
 	struct sysmon_envsys *osme;
+	envsys_data_t *edata;
 
 	KASSERT(sme != NULL);
 
@@ -987,6 +990,10 @@ sysmon_envsys_unregister(struct sysmon_e
 	LIST_REMOVE(sme, sme_list);
 	mutex_exit(&sme_global_mtx);
 
+	TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {
+		sysmon_envsys_sensor_detach(sme, edata);
+	}
+
 	/*
 	 * Unregister all events associated with device.
 	 */

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.119 src/sys/dev/sysmon/sysmon_envsys_events.c:1.120
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.119	Thu Jun  1 02:45:11 2017
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Wed Sep  6 11:08:53 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.119 2017/06/01 02:45:11 chs Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.120 2017/09/06 11:08:53 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.119 2017/06/01 02:45:11 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.120 2017/09/06 11:08:53 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -480,8 +480,6 @@ sme_remove_event(sme_event_t *see, struc
 
 	KASSERT(mutex_owned(&sme->sme_mtx));
 
-	if (see->see_edata->flags & ENVSYS_FHAS_ENTROPY)
-		rnd_detach_source(&see->see_edata->rnd_src);
 	LIST_REMOVE(see, see_list);
 	kmem_free(see, sizeof(*see));
 }

Reply via email to