NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/38980: sysmonread_power() has unreachable mutex_exit(), - or - locking it too complicated



>Number:         38980
>Category:       kern
>Synopsis:       sysmonread_power() has unreachable mutex_exit(), - or - 
>locking it too complicated
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 18 05:50:00 +0000 2008
>Originator:     Gregory McGarry
>Release:        -current
>Organization:
>Environment:
>Description:
sysmonread_power() has acquired locking to cover all exit points, however the 
last mutex_exit() is unreachable, and there isn't a return value for this 
unreachable code.

It's probably less complicated to change the code to have a single exit point 
and a single point to exit the mutex.



>How-To-Repeat:

>Fix:
Index: sysmon_power.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sysmon/sysmon_power.c,v
retrieving revision 1.38
diff -u -r1.38 sysmon_power.c
--- sysmon_power.c      10 May 2008 14:01:32 -0000      1.38
+++ sysmon_power.c      18 Jun 2008 05:42:33 -0000
@@ -425,6 +425,7 @@
 sysmonread_power(dev_t dev, struct uio *uio, int flags)
 {
        power_event_t pev;
+       int rv;
 
        /* We only allow one event to be read at a time. */
        if (uio->uio_resid != POWER_EVENT_MSG_SIZE)
@@ -433,19 +434,21 @@
        mutex_enter(&sysmon_power_event_queue_mtx);
        for (;;) {
                if (sysmon_get_power_event(&pev)) {
-                       mutex_exit(&sysmon_power_event_queue_mtx);
-                       return uiomove(&pev, POWER_EVENT_MSG_SIZE, uio);
+                       rv =  uiomove(&pev, POWER_EVENT_MSG_SIZE, uio);
+                       break;
                }
 
-               if (flags & IO_NDELAY) {
-                       mutex_exit(&sysmon_power_event_queue_mtx);
-                       return EWOULDBLOCK;
+               if (flags & IO_NDELAY)
+                       rv = EWOULDBLOCK;
+                       break;
                }
 
                cv_wait(&sysmon_power_event_queue_cv,
                        &sysmon_power_event_queue_mtx);
        }
        mutex_exit(&sysmon_power_event_queue_mtx);
+
+       return rv;
 }
 
 /*




Home | Main Index | Thread Index | Old Index