Subject: Re: kern/36673 (dubious code is sysmon_envsys)
To: None <xtraeme@NetBSD.org, gnats-admin@netbsd.org,>
From: Juan RP <juan@xtrarom.org>
List: netbsd-bugs
Date: 07/23/2007 23:40:03
The following reply was made to PR kern/36673; it has been noted by GNATS.
From: Juan RP <juan@xtrarom.org>
To: gnats-bugs@NetBSD.org
Cc: yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi)
Subject: Re: kern/36673 (dubious code is sysmon_envsys)
Date: Tue, 24 Jul 2007 01:35:30 +0200
On Mon, 23 Jul 2007 23:20:03 +0000 (UTC)
yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi) wrote:
> the usages of these mutexes are not obvious or documented.
>
> for example,
> - i can't understand why sysmon_envsys_createplist acquires
> sme_mtx in the loop.
I wanted to protect the sme_gtredata function callback, this one
is executed in the driver to refresh data in the sensors.
> - sysmon_envsys_register seems to assume sysmon_envsys_list is stable
> while unlocking sme_list_mtx.
Do you think the following patch is ok for you?
Index: sysmon_envsys.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sysmon/sysmon_envsys.c,v
retrieving revision 1.43
diff -b -u -r1.43 sysmon_envsys.c
--- sysmon_envsys.c 23 Jul 2007 17:51:16 -0000 1.43
+++ sysmon_envsys.c 23 Jul 2007 23:30:18 -0000
@@ -483,7 +483,6 @@
mutex_enter(&sme_list_mtx);
LIST_FOREACH(lsme, &sysmon_envsys_list, sme_list) {
if (strcmp(lsme->sme_name, sme->sme_name) == 0) {
- mutex_exit(&sme_list_mtx);
error = EEXIST;
goto out;
}
@@ -496,16 +495,14 @@
sme->sme_fsensor = sysmon_envsys_next_sensor_index;
sysmon_envsys_next_sensor_index += sme->sme_nsensors;
#endif
- mutex_exit(&sme_list_mtx);
error = sysmon_envsys_createplist(sme);
if (!error) {
- mutex_enter(&sme_list_mtx);
LIST_INSERT_HEAD(&sysmon_envsys_list, sme, sme_list);
sme_uniqsensors = 0;
- mutex_exit(&sme_list_mtx);
}
out:
+ mutex_exit(&sme_mtx);
return error;
}
@@ -626,6 +623,9 @@
nsens = error = 0;
+ KASSERT(mutex_owned(&sme_list_mtx));
+ mutex_exit(&sme_list_mtx);
+
/* create the sysmon envsys device array. */
array = prop_array_create();
if (array == NULL)
One thing that is not clear to me is if I can allocate/deallocate memory
with a mutex held, can you please answer?
--
Juan Romero Pardines - The NetBSD Project
http://plog.xtrarom.org - NetBSD/pkgsrc news in Spanish