Tue May 5 09:22:33 2015 UTC ()
Optimize a bit - don't re-enter the mutex if we're just going to exit.

While here, remove some parens around a return value.


(pgoyette)
diff -r1.27 -r1.28 src/sys/dev/sysmon/sysmon.c

cvs diff -r1.27 -r1.28 src/sys/dev/sysmon/sysmon.c (expand / switch to unified diff)

--- src/sys/dev/sysmon/sysmon.c 2015/05/05 00:28:25 1.27
+++ src/sys/dev/sysmon/sysmon.c 2015/05/05 09:22:33 1.28
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sysmon.c,v 1.27 2015/05/05 00:28:25 pgoyette Exp $ */ 1/* $NetBSD: sysmon.c,v 1.28 2015/05/05 09:22:33 pgoyette Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 Zembu Labs, Inc. 4 * Copyright (c) 2000 Zembu Labs, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Author: Jason R. Thorpe <thorpej@zembu.com> 7 * Author: Jason R. Thorpe <thorpej@zembu.com>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -29,27 +29,27 @@ @@ -29,27 +29,27 @@
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36/* 36/*
37 * Clearing house for system monitoring hardware. We currently 37 * Clearing house for system monitoring hardware. We currently
38 * handle environmental sensors, watchdog timers, and power management. 38 * handle environmental sensors, watchdog timers, and power management.
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.27 2015/05/05 00:28:25 pgoyette Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.28 2015/05/05 09:22:33 pgoyette Exp $");
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/conf.h> 45#include <sys/conf.h>
46#include <sys/errno.h> 46#include <sys/errno.h>
47#include <sys/fcntl.h> 47#include <sys/fcntl.h>
48#include <sys/callout.h> 48#include <sys/callout.h>
49#include <sys/kernel.h> 49#include <sys/kernel.h>
50#include <sys/systm.h> 50#include <sys/systm.h>
51#include <sys/proc.h> 51#include <sys/proc.h>
52#include <sys/module.h> 52#include <sys/module.h>
53#include <sys/mutex.h> 53#include <sys/mutex.h>
54#include <sys/device.h> 54#include <sys/device.h>
55#include <sys/once.h> 55#include <sys/once.h>
@@ -142,45 +142,45 @@ sysmonopen(dev_t dev, int flag, int mode @@ -142,45 +142,45 @@ sysmonopen(dev_t dev, int flag, int mode
142{ 142{
143 int error; 143 int error;
144 144
145 mutex_enter(&sysmon_minor_mtx); 145 mutex_enter(&sysmon_minor_mtx);
146 146
147 switch (minor(dev)) { 147 switch (minor(dev)) {
148 case SYSMON_MINOR_ENVSYS: 148 case SYSMON_MINOR_ENVSYS:
149 case SYSMON_MINOR_WDOG: 149 case SYSMON_MINOR_WDOG:
150 case SYSMON_MINOR_POWER: 150 case SYSMON_MINOR_POWER:
151 if (sysmon_opvec_table[minor(dev)] == NULL) { 151 if (sysmon_opvec_table[minor(dev)] == NULL) {
152 mutex_exit(&sysmon_minor_mtx); 152 mutex_exit(&sysmon_minor_mtx);
153 error = module_autoload(sysmon_mod[minor(dev)], 153 error = module_autoload(sysmon_mod[minor(dev)],
154 MODULE_CLASS_MISC); 154 MODULE_CLASS_MISC);
155 mutex_enter(&sysmon_minor_mtx); 
156 if (error) 155 if (error)
157 break; 156 return error;
 157 mutex_enter(&sysmon_minor_mtx);
158 if (sysmon_opvec_table[minor(dev)] == NULL) { 158 if (sysmon_opvec_table[minor(dev)] == NULL) {
159 error = ENODEV; 159 error = ENODEV;
160 break; 160 break;
161 } 161 }
162 } 162 }
163 error = (sysmon_opvec_table[minor(dev)]->so_open)(dev, flag, 163 error = (sysmon_opvec_table[minor(dev)]->so_open)(dev, flag,
164 mode, l); 164 mode, l);
165 if (error == 0) 165 if (error == 0)
166 sysmon_refcnt[minor(dev)]++; 166 sysmon_refcnt[minor(dev)]++;
167 break; 167 break;
168 default: 168 default:
169 error = ENODEV; 169 error = ENODEV;
170 } 170 }
171 171
172 mutex_exit(&sysmon_minor_mtx); 172 mutex_exit(&sysmon_minor_mtx);
173 return (error); 173 return error;
174} 174}
175 175
176/* 176/*
177 * sysmonclose: 177 * sysmonclose:
178 * 178 *
179 * Close the system monitor device. 179 * Close the system monitor device.
180 */ 180 */
181int 181int
182sysmonclose(dev_t dev, int flag, int mode, struct lwp *l) 182sysmonclose(dev_t dev, int flag, int mode, struct lwp *l)
183{ 183{
184 int error; 184 int error;
185 185
186 switch (minor(dev)) { 186 switch (minor(dev)) {