Re: [PATCH] sound: Fix race condition in the pcm_lib "wait forspace loop

From: Arjan van de Ven
Date: Tue Sep 06 2011 - 23:04:19 EST


On Tue, 6 Sep 2011 15:59:54 -0700
Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:

> > --- a/sound/core/pcm_lib.c
> > +++ b/sound/core/pcm_lib.c
> > @@ -1761,6 +1761,10 @@ static int wait_for_avail(struct
> > snd_pcm_substream *substream, snd_pcm_uframes_t avail = 0;
> > long wait_time, tout;
> >
> > + init_waitqueue_entry(&wait, current);
> > + add_wait_queue(&runtime->tsleep, &wait);
> > + set_current_state(TASK_INTERRUPTIBLE);
>
> Well, this isn't very good either. if a wakeup gets delivered to
> runtime->tsleep before the set_current_state(), this process will go
> ahead and incorrectly set itself into TASK_INTERRUPTIBLE state.

... and then check the condition for exit, and then set it to
TASK_RUNABLE a the end...

>
> That looks like it will be dont-care/cant-happen in this case, but
> it's setting a bad example.

agreed that your ordering is more clean/better.....



--
Arjan van de Ven Intel Open Source Technology Centre
For development, discussion and tips for power savings,
visit http://www.lesswatts.org
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/