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.
> ...
> >     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) {
> Hmmm... that sort of code tends to look dubious [1].
> While acquiring a mutex across a function call can protect the underlying
> data from immediate corruption, it isn't necessarily obvious that
> the checked condition can't change state after the mutex is released.
>       David
> [1] As does releaseing a mutex across a function call!

in a general you're right, but this case doesn't fit.  we need the
lock to ask the hw driver about play/record state, and this is in
audioattach() so there won't be other activity here yet.  so what
this really does is push locking around that probably isn't strictly
necessary for this path, but is necessary for others.

the conditions can change, but only after open() etc.


Home | Main Index | Thread Index | Old Index