Skip to content

Commit

Permalink
es1968: fix sleep-while-holding-lock bug
Browse files Browse the repository at this point in the history
snd_es1968_ac97_read() calls snd_es1968_ac97_wait() first outside a locked
area, and later, while holding a lock.

snd_es1968_ac97_wait() has a polling loop with a cond_resched() inside it..
which sleeps, so the second call is invalid.

This patch adds a version of the wait function that just pure polls.  While
this is not very elegant in principle, it's very likely the easiest thing to
do here, we already checked if the chip was ready (while yielding) just
before, so it is very unlikely to take a long time here.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Jaroslav Kysela <perex@suse.cz>
Cc: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
fenrus75 authored and torvalds committed Apr 9, 2008
1 parent 41e3355 commit 4b47c97
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sound/pci/es1968.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,18 @@ static int snd_es1968_ac97_wait(struct es1968 *chip)
return 1; /* timeout */
}

static int snd_es1968_ac97_wait_poll(struct es1968 *chip)
{
int timeout = 100000;

while (timeout-- > 0) {
if (!(inb(chip->io_port + ESM_AC97_INDEX) & 1))
return 0;
}
snd_printd("es1968: ac97 timeout\n");
return 1; /* timeout */
}

static void snd_es1968_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
{
struct es1968 *chip = ac97->private_data;
Expand Down Expand Up @@ -645,7 +657,7 @@ static unsigned short snd_es1968_ac97_read(struct snd_ac97 *ac97, unsigned short
outb(reg | 0x80, chip->io_port + ESM_AC97_INDEX);
/*msleep(1);*/

if (! snd_es1968_ac97_wait(chip)) {
if (!snd_es1968_ac97_wait_poll(chip)) {
data = inw(chip->io_port + ESM_AC97_DATA);
/*msleep(1);*/
}
Expand Down

0 comments on commit 4b47c97

Please sign in to comment.