Skip to content

Commit

Permalink
ALSA: ak411x: Fix race of reinit() calls
Browse files Browse the repository at this point in the history
Protect the call with a mutex, as this may be called in parallel
(either from the PCM rate change and the clock change).

Acked-by: Jaroslav Kysela <[email protected]>
Tested-by: Pavel Hofman <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Jan 28, 2015
1 parent 1293617 commit 1781e78
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/sound/ak4113.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ struct ak4113 {
ak4113_read_t *read;
void *private_data;
atomic_t wq_processing;
struct mutex reinit_mutex;
spinlock_t lock;
unsigned char regmap[AK4113_WRITABLE_REGS];
struct snd_kcontrol *kctls[AK4113_CONTROLS];
Expand Down
1 change: 1 addition & 0 deletions include/sound/ak4114.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct ak4114 {
ak4114_read_t * read;
void * private_data;
atomic_t wq_processing;
struct mutex reinit_mutex;
spinlock_t lock;
unsigned char regmap[6];
unsigned char txcsb[5];
Expand Down
3 changes: 3 additions & 0 deletions sound/i2c/other/ak4113.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read,
chip->private_data = private_data;
INIT_DELAYED_WORK(&chip->work, ak4113_stats);
atomic_set(&chip->wq_processing, 0);
mutex_init(&chip->reinit_mutex);

for (reg = 0; reg < AK4113_WRITABLE_REGS ; reg++)
chip->regmap[reg] = pgm[reg];
Expand Down Expand Up @@ -141,7 +142,9 @@ void snd_ak4113_reinit(struct ak4113 *chip)
{
if (atomic_inc_return(&chip->wq_processing) == 1)
cancel_delayed_work_sync(&chip->work);
mutex_lock(&chip->reinit_mutex);
ak4113_init_regs(chip);
mutex_unlock(&chip->reinit_mutex);
/* bring up statistics / event queing */
if (atomic_dec_and_test(&chip->wq_processing))
schedule_delayed_work(&chip->work, HZ / 10);
Expand Down
3 changes: 3 additions & 0 deletions sound/i2c/other/ak4114.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ int snd_ak4114_create(struct snd_card *card,
chip->private_data = private_data;
INIT_DELAYED_WORK(&chip->work, ak4114_stats);
atomic_set(&chip->wq_processing, 0);
mutex_init(&chip->reinit_mutex);

for (reg = 0; reg < 6; reg++)
chip->regmap[reg] = pgm[reg];
Expand Down Expand Up @@ -156,7 +157,9 @@ void snd_ak4114_reinit(struct ak4114 *chip)
{
if (atomic_inc_return(&chip->wq_processing) == 1)
cancel_delayed_work_sync(&chip->work);
mutex_lock(&chip->reinit_mutex);
ak4114_init_regs(chip);
mutex_unlock(&chip->reinit_mutex);
/* bring up statistics / event queing */
if (atomic_dec_and_test(&chip->wq_processing))
schedule_delayed_work(&chip->work, HZ / 10);
Expand Down

0 comments on commit 1781e78

Please sign in to comment.