Source-Changes-HG archive

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

[src/trunk]: src/sys/dev On failed attach hw_if is NULL, so guard against it ...



details:   https://anonhg.NetBSD.org/src/rev/d54ce68a267c
branches:  trunk
changeset: 349622:d54ce68a267c
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Dec 16 16:03:28 2016 +0000

description:
On failed attach hw_if is NULL, so guard against it in more places. Should
avoid crashes people have been seeing recently.

diffstat:

 sys/dev/audio.c |  20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diffs (83 lines):

diff -r 0bca023b0933 -r d54ce68a267c sys/dev/audio.c
--- a/sys/dev/audio.c   Fri Dec 16 15:06:39 2016 +0000
+++ b/sys/dev/audio.c   Fri Dec 16 16:03:28 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.279 2016/12/15 22:01:57 pgoyette Exp $     */
+/*     $NetBSD: audio.c,v 1.280 2016/12/16 16:03:28 christos Exp $     */
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.279 2016/12/15 22:01:57 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.280 2016/12/16 16:03:28 christos Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -2177,6 +2177,8 @@
        vc = sc->sc_vchan[n];
 
        hw = sc->hw_if;
+       if (hw == NULL)
+               return ENXIO;
        mutex_enter(sc->sc_intr_lock);
        DPRINTF(("audio_close: sc=%p\n", sc));
        /* Stop recording. */
@@ -2269,6 +2271,8 @@
        if (m == VAUDIOCHANS)
                return EINVAL;
 
+       if (sc->hw_if == NULL)
+               return ENXIO;
        vc = sc->sc_vchan[m];
 
        cb = &vc->sc_mrr;
@@ -2600,6 +2604,9 @@
        if (n == VAUDIOCHANS)
                return EINVAL;
 
+       if (sc->hw_if == NULL)
+               return ENXIO;
+
        vc = sc->sc_vchan[n];
        cb = &vc->sc_mpr;
 
@@ -2773,6 +2780,8 @@
        DPRINTF(("audio_ioctl(%lu,'%c',%lu)\n",
                 IOCPARM_LEN(cmd), (char)IOCGROUP(cmd), cmd&0xff));
        hw = sc->hw_if;
+       if (hw == NULL)
+               return ENXIO;
        error = 0;
        switch (cmd) {
        case AUDIO_SETPROC:
@@ -3141,6 +3150,9 @@
        if (n == VAUDIOCHANS)
                return -1;
 
+       if (sc->hw_if == NULL)
+               return ENXIO;
+
        DPRINTF(("audio_mmap: off=%lld, prot=%d\n", (long long)off, prot));
        vc = sc->sc_vchan[n];
        if (!(audio_get_props(sc) & AUDIO_PROP_MMAP))
@@ -4759,6 +4771,8 @@
 {
 
        KASSERT(mutex_owned(sc->sc_lock));
+       if (sc->hw_if == NULL)
+               return ENXIO;
 
        DPRINTF(("mixer_close: sc %p\n", sc));
        mixer_remove(sc);
@@ -4777,6 +4791,8 @@
        DPRINTF(("mixer_ioctl(%lu,'%c',%lu)\n",
                 IOCPARM_LEN(cmd), (char)IOCGROUP(cmd), cmd&0xff));
        hw = sc->hw_if;
+       if (hw == NULL)
+               return ENXIO;
        error = EINVAL;
 
        /* we can return cached values if we are sleeping */



Home | Main Index | Thread Index | Old Index