Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/audio audio(4): Insert mixers and audioctls into sc_...



details:   https://anonhg.NetBSD.org/src/rev/d912f1f3ecf2
branches:  trunk
changeset: 983684:d912f1f3ecf2
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Jun 01 21:19:03 2021 +0000

description:
audio(4): Insert mixers and audioctls into sc_files on open too.

This is necessary so that on detach we set file->dying before any
operations, particularly audioclose, try to acquire a psref by the
time the audio softc is gone.

Candidate fix for PR kern/56164.

diffstat:

 sys/dev/audio/audio.c |  51 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 41 insertions(+), 10 deletions(-)

diffs (102 lines):

diff -r 48db97ec16b7 -r d912f1f3ecf2 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Tue Jun 01 21:15:37 2021 +0000
+++ b/sys/dev/audio/audio.c     Tue Jun 01 21:19:03 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.100 2021/06/01 21:15:37 riastradh Exp $    */
+/*     $NetBSD: audio.c,v 1.101 2021/06/01 21:19:03 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.100 2021/06/01 21:15:37 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.101 2021/06/01 21:19:03 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1343,11 +1343,19 @@
 
        /*
         * Clean up all open instances.
-        * Here, we no longer need any locks to traverse sc_files.
         */
+       mutex_enter(sc->sc_lock);
        while ((file = SLIST_FIRST(&sc->sc_files)) != NULL) {
-               audio_unlink(sc, file);
-       }
+               mutex_enter(sc->sc_intr_lock);
+               SLIST_REMOVE_HEAD(&sc->sc_files, entry);
+               mutex_exit(sc->sc_intr_lock);
+               if (file->ptrack || file->rtrack) {
+                       mutex_exit(sc->sc_lock);
+                       audio_unlink(sc, file);
+                       mutex_enter(sc->sc_lock);
+               }
+       }
+       mutex_exit(sc->sc_lock);
 
        pmf_event_deregister(self, PMFE_AUDIO_VOLUME_DOWN,
            audio_volume_down, true);
@@ -1739,6 +1747,11 @@
        bound = curlwp_bind();
        sc = audio_sc_acquire_fromfile(file, &sc_ref);
        if (sc) {
+               mutex_enter(sc->sc_lock);
+               mutex_enter(sc->sc_intr_lock);
+               SLIST_REMOVE(&sc->sc_files, file, audio_file, entry);
+               mutex_exit(sc->sc_intr_lock);
+               mutex_exit(sc->sc_lock);
                switch (AUDIODEV(dev)) {
                case SOUND_DEVICE:
                case AUDIO_DEVICE:
@@ -2596,10 +2609,6 @@
 
        device_active(sc->sc_dev, DVA_SYSTEM);
 
-       mutex_enter(sc->sc_intr_lock);
-       SLIST_REMOVE(&sc->sc_files, file, audio_file, entry);
-       mutex_exit(sc->sc_intr_lock);
-
        if (file->ptrack) {
                TRACET(3, file->ptrack, "dropframes=%" PRIu64,
                    file->ptrack->dropframes);
@@ -3517,7 +3526,17 @@
        af->sc = sc;
        af->dev = dev;
 
-       /* Not necessary to insert sc_files. */
+       mutex_enter(sc->sc_lock);
+       if (sc->sc_dying) {
+               mutex_exit(sc->sc_lock);
+               kmem_free(af, sizeof(*af));
+               fd_abort(curproc, fp, fd);
+               return ENXIO;
+       }
+       mutex_enter(sc->sc_intr_lock);
+       SLIST_INSERT_HEAD(&sc->sc_files, af, entry);
+       mutex_exit(sc->sc_intr_lock);
+       mutex_exit(sc->sc_lock);
 
        error = fd_clone(fp, fd, flags, &audio_fileops, af);
        KASSERTMSG(error == EMOVEFD, "error=%d", error);
@@ -8133,6 +8152,18 @@
        af->sc = sc;
        af->dev = dev;
 
+       mutex_enter(sc->sc_lock);
+       if (sc->sc_dying) {
+               mutex_exit(sc->sc_lock);
+               kmem_free(af, sizeof(*af));
+               fd_abort(curproc, fp, fd);
+               return ENXIO;
+       }
+       mutex_enter(sc->sc_intr_lock);
+       SLIST_INSERT_HEAD(&sc->sc_files, af, entry);
+       mutex_exit(sc->sc_intr_lock);
+       mutex_exit(sc->sc_lock);
+
        error = fd_clone(fp, fd, flags, &audio_fileops, af);
        KASSERT(error == EMOVEFD);
 



Home | Main Index | Thread Index | Old Index