Source-Changes-HG archive

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

[src/trunk]: src/sys/dev - check sc->dying after sleeping in several more pla...



details:   https://anonhg.NetBSD.org/src/rev/d4c2f1681e56
branches:  trunk
changeset: 335215:d4c2f1681e56
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Dec 30 07:28:34 2014 +0000

description:
- check sc->dying after sleeping in several more places, and
  convert it into EIO error where necessary.
- remove a wrong additional mutex_exit() call.
- make sure to check sc->dying under the device lock.

diffstat:

 sys/dev/midi.c |  33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)

diffs (111 lines):

diff -r a79efd24f0f2 -r d4c2f1681e56 sys/dev/midi.c
--- a/sys/dev/midi.c    Tue Dec 30 07:18:42 2014 +0000
+++ b/sys/dev/midi.c    Tue Dec 30 07:28:34 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: midi.c,v 1.82 2014/12/22 07:02:22 mrg Exp $    */
+/*     $NetBSD: midi.c,v 1.83 2014/12/30 07:28:34 mrg Exp $    */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.82 2014/12/22 07:02:22 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.83 2014/12/30 07:28:34 mrg Exp $");
 
 #include "midi.h"
 #include "sequencer.h"
@@ -880,6 +880,8 @@
        mutex_enter(sc->lock);
        /* midi_start_output(sc); anything buffered => pbus already set! */
        while (sc->pbus) {
+               if (sc->dying)
+                       break;
                DPRINTFN(8,("midiclose sleep ...\n"));
                cv_wait(&sc->wchan, sc->lock);
        }
@@ -1277,13 +1279,13 @@
                error = sc->hw_if->output(sc->hw_hdl, *buf_cur);
                if (error &&  error != EINPROGRESS)
                        break;
-               ++ buf_cur;
+               ++buf_cur;
                MIDI_BUF_WRAP(buf);
-               -- msglen;
+               --msglen;
                if (msglen)
                        *idx_cur = PACK_MB_IDX(MB_IDX_CAT(*idx_cur),msglen);
                else {
-                       ++ idx_cur;
+                       ++idx_cur;
                        MIDI_BUF_WRAP(idx);
                }
                if (!error) {
@@ -1362,7 +1364,7 @@
        
        while (ibuf < iend) {
                got = midi_fst(&sc->xmt, *ibuf, form);
-               ++ ibuf;
+               ++ibuf;
                switch ( got) {
                case FST_MORE:
                        continue;
@@ -1484,7 +1486,6 @@
                                 * the common syscall code will automagically
                                 * convert this to success with a short count.
                                 */
-                               mutex_exit(sc->lock);
                                error = EWOULDBLOCK;
                                goto out;
                        }
@@ -1495,6 +1496,8 @@
                                pollout = 0;
                        } else
                                error = cv_wait_sig(&sc->wchan, sc->lock);
+                       if (sc->dying)
+                               error = EIO;
                        if (error) {
                                /*
                                 * Similarly, the common code will handle
@@ -1532,7 +1535,7 @@
                               "xfrcount=%zu inp=%p\n",
                               error, xfrcount, inp);
 #endif
-               if ( error )
+               if (error)
                        break;
                
                /*
@@ -1581,7 +1584,10 @@
                     sc, unit, cc, bf[0], bf[1], bf[2]));
 
        mutex_enter(sc->lock);
-       error = real_writebytes(sc, bf, cc);
+       if (sc->dying)
+               error = EIO;
+       else
+               error = real_writebytes(sc, bf, cc);
        mutex_exit(sc->lock);
 
        return error;
@@ -1596,13 +1602,16 @@
        MIDI_BUF_DECLARE(buf);
 
        (void)buf_end;
-       sc = device_lookup_private(&midi_cd, MIDIUNIT(dev));;
-       if (sc->dying)
+       sc = device_lookup_private(&midi_cd, MIDIUNIT(dev));
+
+       mutex_enter(sc->lock);
+       if (sc->dying) {
+               mutex_exit(sc->lock);
                return EIO;
+       }
        hw = sc->hw_if;
        error = 0;
 
-       mutex_enter(sc->lock);
        sc->refcnt++;
 
        DPRINTFN(5,("midiioctl: %p cmd=0x%08lx\n", sc, cmd));



Home | Main Index | Thread Index | Old Index