NetBSD-Bugs archive

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

re: kern/46121: audiomp: locking protocol error



this looks like it should do the trick.

oh, i'll fix the comment as well.


.mrg.


Index: audio.c
===================================================================
RCS file: /cvsroot/src/sys/dev/audio.c,v
retrieving revision 1.258
diff -p -r1.258 audio.c
*** audio.c     21 Feb 2012 20:53:34 -0000      1.258
--- audio.c     26 Mar 2012 07:01:37 -0000
*************** audioattach(device_t parent, device_t se
*** 389,394 ****
--- 390,396 ----
        mixer_devinfo_t mi;
        int iclass, mclass, oclass, rclass, props;
        int record_master_found, record_source_found;
+       bool can_capture, can_playback;
  
        sc = device_private(self);
        sc->dev = self;
*************** audioattach(device_t parent, device_t se
*** 459,482 ****
         * Revisit.
         */
        mutex_enter(sc->sc_lock);
!       if (audio_can_playback(sc)) {
                error = audio_alloc_ring(sc, &sc->sc_pr,
                    AUMODE_PLAY, AU_RING_SIZE);
                if (error) {
                        sc->hw_if = NULL;
-                       mutex_exit(sc->sc_lock);
                        aprint_error("audio: could not allocate play buffer\n");
                        return;
                }
        }
!       if (audio_can_capture(sc)) {
                error = audio_alloc_ring(sc, &sc->sc_rr,
                    AUMODE_RECORD, AU_RING_SIZE);
                if (error) {
                        if (sc->sc_pr.s.start != 0)
                                audio_free_ring(sc, &sc->sc_pr);
                        sc->hw_if = NULL;
-                       mutex_exit(sc->sc_lock);
                        aprint_error("audio: could not allocate record 
buffer\n");
                        return;
                }
--- 461,486 ----
         * Revisit.
         */
        mutex_enter(sc->sc_lock);
!       can_playback = audio_can_playback(sc);
!       can_capture = audio_can_capture(sc);
!       mutex_exit(sc->sc_lock);
! 
!       if (can_playback) {
                error = audio_alloc_ring(sc, &sc->sc_pr,
                    AUMODE_PLAY, AU_RING_SIZE);
                if (error) {
                        sc->hw_if = NULL;
                        aprint_error("audio: could not allocate play buffer\n");
                        return;
                }
        }
!       if (can_capture) {
                error = audio_alloc_ring(sc, &sc->sc_rr,
                    AUMODE_RECORD, AU_RING_SIZE);
                if (error) {
                        if (sc->sc_pr.s.start != 0)
                                audio_free_ring(sc, &sc->sc_pr);
                        sc->hw_if = NULL;
                        aprint_error("audio: could not allocate record 
buffer\n");
                        return;
                }
*************** audioattach(device_t parent, device_t se
*** 484,489 ****
--- 488,494 ----
  
        sc->sc_lastgain = 128;
  
+       mutex_enter(sc->sc_lock);
        error = audio_set_defaults(sc, 0);
        mutex_exit(sc->sc_lock);
        if (error != 0) {
*************** audio_alloc_ring(struct audio_softc *sc,
*** 884,891 ****
        if (bufsize < AUMINBUF)
                bufsize = AUMINBUF;
        ROUNDSIZE(bufsize);
!       if (hw->round_buffersize)
                bufsize = hw->round_buffersize(hdl, direction, bufsize);
        if (hw->allocm)
                r->s.start = hw->allocm(hdl, direction, bufsize);
        else
--- 889,899 ----
        if (bufsize < AUMINBUF)
                bufsize = AUMINBUF;
        ROUNDSIZE(bufsize);
!       if (hw->round_buffersize) {
!               mutex_enter(sc->sc_lock);
                bufsize = hw->round_buffersize(hdl, direction, bufsize);
+               mutex_exit(sc->sc_lock);
+       }
        if (hw->allocm)
                r->s.start = hw->allocm(hdl, direction, bufsize);
        else


Home | Main Index | Thread Index | Old Index