ak411x fix patches for ice1724 Juli@
cover ak411x fix patches for ice1724 Juli@
Hi,
here is a bit more cooked patch series for ak411x and juli@ device.
[PATCH 1/4] ALSA: ak411x: Fix stall in work callback [PATCH 2/4] ALSA: ak4114: Move EXPORT_SYMBOL() after each function [PATCH 3/4] ALSA: ak411x: Add PM helper functions [PATCH 4/4] ALSA: ak411x: Fix race of reinit() calls
Takashi
PATCH 1/4 ALSA: ak411x: Fix stall in work callback
When ak4114 work calls its callback and the callback invokes ak4114_reinit(), it stalls due to flush_delayed_work(). For avoiding this, control the reentrance by introducing a refcount. Also flush_delayed_work() is replaced with cancel_delayed_work_sync().
The exactly same bug is present in ak4113.c and fixed as well.
--- include/sound/ak4113.h | 2 +- include/sound/ak4114.h | 2 +- sound/i2c/other/ak4113.c | 17 ++++++++--------- sound/i2c/other/ak4114.c | 18 ++++++++---------- 4 files changed, 18 insertions(+), 21 deletions(-)
include/sound/ak4113.h +1 -1
@@ -286,7 +286,7 @@ struct ak4113 {ak4113_write_t *write;ak4113_read_t *read;void *private_data; - unsigned int init:1; +atomic_t wq_processing;spinlock_t lock;unsigned char regmap[AK4113_WRITABLE_REGS ];struct snd_kcontrol *kctls[AK4113_CONTROLS ];
include/sound/ak4114.h +1 -1
@@ -168,7 +168,7 @@ struct ak4114 {ak4114_write_t * write;ak4114_read_t * read;void * private_data; - unsigned int init: 1; +atomic_t wq_processing;spinlock_t lock;unsigned char regmap[6 ];unsigned char txcsb[5 ];
sound/i2c/other/ak4113.c +8 -9
@@ -56,8 +56,7 @@ static inline unsigned char reg_read(struct ak4113 *ak4113, unsigned char reg)static void snd_ak4113_free (struct ak4113 *chip) { - chip->init =1 ;/* don't schedule new work */ -mb (); +atomic_inc (&chip->wq_processing);/* don't schedule new work */ cancel_delayed_work_sync (&chip->work);kfree (chip); }
@@ -89,6 +88,7 @@ int snd_ak4113_create(struct snd_card *card, ak4113_read_t *read, chip->write = write; chip->private_data = private_data;INIT_DELAYED_WORK (&chip->work, ak4113_stats); +atomic_set (&chip->wq_processing,0 );for (reg =0 ; reg <AK4113_WRITABLE_REGS ; reg++) chip->regmap[reg] = pgm[reg];
@@ -139,13 +139,11 @@ static void ak4113_init_regs(struct ak4113 *chip)void snd_ak4113_reinit (struct ak4113 *chip) { - chip->init =1 ; -mb (); -flush_delayed_work (&chip->work); +if (atomic_inc_return (&chip->wq_processing) ==1 ) +cancel_delayed_work_sync (&chip->work);ak4113_init_regs (chip);/* bring up statistics / event queing */ - chip->init =0 ; -if (chip->kctls[0 ]) +if (atomic_dec_and_test (&chip->wq_processing))schedule_delayed_work (&chip->work,HZ /10 ); }EXPORT_SYMBOL_GPL (snd_ak4113_reinit);
@@ -632,8 +630,9 @@ static void ak4113_stats(struct work_struct *work) { struct ak4113 *chip = container_of(work, struct ak4113, work.work); -if (!chip->init) +if (atomic_inc_return (&chip->wq_processing) ==1 )snd_ak4113_check_rate_and_errors (chip, chip->check_flags); -schedule_delayed_work (&chip->work,HZ /10 ); +if (atomic_dec_and_test (&chip->wq_processing)) +schedule_delayed_work (&chip->work,HZ /10 ); }
sound/i2c/other/ak4114.c +8 -10
@@ -66,8 +66,7 @@ static void reg_dump(struct ak4114 *ak4114)static void snd_ak4114_free (struct ak4114 *chip) { - chip->init =1 ;/* don't schedule new work */ -mb (); +atomic_inc (&chip->wq_processing);/* don't schedule new work */ cancel_delayed_work_sync (&chip->work);kfree (chip); }
@@ -100,6 +99,7 @@ int snd_ak4114_create(struct snd_card *card, chip->write = write; chip->private_data = private_data;INIT_DELAYED_WORK (&chip->work, ak4114_stats); +atomic_set (&chip->wq_processing,0 );for (reg =0 ; reg <6 ; reg++) chip->regmap[reg] = pgm[reg];
@@ -152,13 +152,11 @@ static void ak4114_init_regs(struct ak4114 *chip)void snd_ak4114_reinit (struct ak4114 *chip) { - chip->init =1 ; -mb (); -flush_delayed_work (&chip->work); +if (atomic_inc_return (&chip->wq_processing) ==1 ) +cancel_delayed_work_sync (&chip->work);ak4114_init_regs (chip);/* bring up statistics / event queing */ - chip->init =0 ; -if (chip->kctls[0 ]) +if (atomic_dec_and_test (&chip->wq_processing))schedule_delayed_work (&chip->work,HZ /10 ); }
@@ -612,10 +610,10 @@ static void ak4114_stats(struct work_struct *work) { struct ak4114 *chip = container_of(work, struct ak4114, work.work); -if (!chip->init) +if (atomic_inc_return (&chip->wq_processing) ==1 )snd_ak4114_check_rate_and_errors (chip, chip->check_flags); - -schedule_delayed_work (&chip->work,HZ /10 ); +if (atomic_dec_and_test (&chip->wq_processing)) +schedule_delayed_work (&chip->work,HZ /10 ); }EXPORT_SYMBOL (snd_ak4114_create);
Signature · 1 line
2.2.1
PATCH 2/4 ALSA: ak4114: Move EXPORT_SYMBOL() after each function
In reply to Takashi Iwai... just to follow the standard coding style.
--- sound/i2c/other/ak4114.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
sound/i2c/other/ak4114.c +6 -7
@@ -122,6 +122,7 @@ int snd_ak4114_create(struct snd_card *card,snd_ak4114_free (chip);return err <0 ? err : -EIO ; } +EXPORT_SYMBOL (snd_ak4114_create);void snd_ak4114_reg_write (struct ak4114 *chip,unsigned char reg,unsigned char mask,unsigned char val) {
@@ -131,6 +132,7 @@ void snd_ak4114_reg_write(struct ak4114 *chip, unsigned char reg, unsigned charreg_write (chip, reg, (chip->txcsb[reg-AK4114_REG_TXCSB0 ] & ~mask) | val); } +EXPORT_SYMBOL (snd_ak4114_reg_write);static void ak4114_init_regs (struct ak4114 *chip) {
@@ -159,6 +161,7 @@ void snd_ak4114_reinit(struct ak4114 *chip)if (atomic_dec_and_test (&chip->wq_processing))schedule_delayed_work (&chip->work,HZ /10 ); } +EXPORT_SYMBOL (snd_ak4114_reinit);static unsigned int external_rate (unsigned char rcs1) {
@@ -503,6 +506,7 @@ int snd_ak4114_build(struct ak4114 *ak4114,schedule_delayed_work (&ak4114->work,HZ /10 );return 0 ; } +EXPORT_SYMBOL (snd_ak4114_build);/* notify kcontrols if any parameters are changed */ static void ak4114_notify(struct ak4114 *ak4114,
@@ -558,6 +562,7 @@ int snd_ak4114_external_rate(struct ak4114 *ak4114) rcs1 =reg_read (ak4114,AK4114_REG_RCS1 );return external_rate (rcs1); } +EXPORT_SYMBOL (snd_ak4114_external_rate);int snd_ak4114_check_rate_and_errors (struct ak4114 *ak4114,unsigned int flags) {
@@ -605,6 +610,7 @@ int snd_ak4114_check_rate_and_errors(struct ak4114 *ak4114, unsigned int flags) }return res; } +EXPORT_SYMBOL (snd_ak4114_check_rate_and_errors);static void ak4114_stats (struct work_struct *work) {
@@ -615,10 +621,3 @@ static void ak4114_stats(struct work_struct *work)if (atomic_dec_and_test (&chip->wq_processing))schedule_delayed_work (&chip->work,HZ /10 ); } - -EXPORT_SYMBOL (snd_ak4114_create); -EXPORT_SYMBOL (snd_ak4114_reg_write); -EXPORT_SYMBOL (snd_ak4114_reinit); -EXPORT_SYMBOL (snd_ak4114_build); -EXPORT_SYMBOL (snd_ak4114_external_rate); -EXPORT_SYMBOL (snd_ak4114_check_rate_and_errors);
Signature · 1 line
2.2.1
PATCH 3/4 ALSA: ak411x: Add PM helper functions
In reply to Takashi IwaiDefine snd_ak4114_suspend() and snd_ak4114_resume() functions to handle PM properly, stopping and restarting the work at PM. Currently only ice1712/juli.c deals with the PM and ak4114, so fix the calls there appropriately.
The same PM functions are defined in ak4113.c, too, although they aren't currently called yet (ice1712/quartet.c may be enhanced to support PM later).
--- include/sound/ak4113.h | 8 ++++++++ include/sound/ak4114.h | 8 ++++++++ sound/i2c/other/ak4113.c | 16 ++++++++++++++++ sound/i2c/other/ak4114.c | 16 ++++++++++++++++ sound/pci/ice1712/juli.c | 4 +++- 5 files changed, 51 insertions(+), 1 deletion(-)
include/sound/ak4113.h +8 -0
@@ -317,5 +317,13 @@ int snd_ak4113_build(struct ak4113 *ak4113,int snd_ak4113_external_rate (struct ak4113 *ak4113);int snd_ak4113_check_rate_and_errors (struct ak4113 *ak4113,unsigned int flags); +#ifdef CONFIG_PM +void snd_ak4113_suspend (struct ak4113 *chip); +void snd_ak4113_resume (struct ak4113 *chip); +#else +static inline void snd_ak4113_suspend (struct ak4113 *chip) {} +static inline void snd_ak4113_resume (struct ak4113 *chip) {} +#endif +#endif /* __SOUND_AK4113_H */
include/sound/ak4114.h +8 -0
@@ -199,5 +199,13 @@ int snd_ak4114_build(struct ak4114 *ak4114,int snd_ak4114_external_rate (struct ak4114 *ak4114);int snd_ak4114_check_rate_and_errors (struct ak4114 *ak4114,unsigned int flags); +#ifdef CONFIG_PM +void snd_ak4114_suspend (struct ak4114 *chip); +void snd_ak4114_resume (struct ak4114 *chip); +#else +static inline void snd_ak4114_suspend (struct ak4114 *chip) {} +static inline void snd_ak4114_resume (struct ak4114 *chip) {} +#endif +#endif /* __SOUND_AK4114_H */
sound/i2c/other/ak4113.c +16 -0
@@ -636,3 +636,19 @@ static void ak4113_stats(struct work_struct *work)if (atomic_dec_and_test (&chip->wq_processing))schedule_delayed_work (&chip->work,HZ /10 ); } + +#ifdef CONFIG_PM +void snd_ak4113_suspend (struct ak4113 *chip) +{ +atomic_inc (&chip->wq_processing);/* don't schedule new work */ +cancel_delayed_work_sync (&chip->work); +} +EXPORT_SYMBOL (snd_ak4113_suspend); + +void snd_ak4113_resume (struct ak4113 *chip) +{ +atomic_dec (&chip->wq_processing); +snd_ak4113_reinit (chip); +} +EXPORT_SYMBOL (snd_ak4113_resume); +#endif
sound/i2c/other/ak4114.c +16 -0
@@ -621,3 +621,19 @@ static void ak4114_stats(struct work_struct *work)if (atomic_dec_and_test (&chip->wq_processing))schedule_delayed_work (&chip->work,HZ /10 ); } + +#ifdef CONFIG_PM +void snd_ak4114_suspend (struct ak4114 *chip) +{ +atomic_inc (&chip->wq_processing);/* don't schedule new work */ +cancel_delayed_work_sync (&chip->work); +} +EXPORT_SYMBOL (snd_ak4114_suspend); + +void snd_ak4114_resume (struct ak4114 *chip) +{ +atomic_dec (&chip->wq_processing); +snd_ak4114_reinit (chip); +} +EXPORT_SYMBOL (snd_ak4114_resume); +#endif
sound/pci/ice1712/juli.c +3 -1
@@ -491,15 +491,17 @@ static int juli_resume(struct snd_ice1712 *ice)/* akm4358 un-reset, un-mute */ snd_akm4xxx_reset (ak,0 );/* reinit ak4114 */ -snd_ak4114_reinit (spec->ak4114); +snd_ak4114_resume (spec->ak4114); return 0; }static int juli_suspend (struct snd_ice1712 *ice) {struct snd_akm4xxx *ak = ice->akm; +struct juli_spec *spec = ice->spec;/* akm4358 reset and soft-mute */ snd_akm4xxx_reset (ak,1 ); +snd_ak4114_suspend (spec->ak4114);return 0 ; }#endif
Signature · 1 line
2.2.1
PATCH 4/4 ALSA: ak411x: Fix race of reinit() calls
In reply to Takashi IwaiProtect the call with a mutex, as this may be called in parallel (either from the PCM rate change and the clock change).
--- include/sound/ak4113.h | 1 + include/sound/ak4114.h | 1 + sound/i2c/other/ak4113.c | 3 +++ sound/i2c/other/ak4114.c | 3 +++ 4 files changed, 8 insertions(+)
include/sound/ak4113.h +1 -0
@@ -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 ];
include/sound/ak4114.h +1 -0
@@ -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 ];
sound/i2c/other/ak4113.c +3 -0
@@ -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];
@@ -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 );
sound/i2c/other/ak4114.c +3 -0
@@ -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];
@@ -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 );
Signature · 1 line
2.2.1
Dne 16.1.2015 v 18:16 Takashi Iwai napsal(a):
Quoted 8 lines
Hi,
here is a bit more cooked patch series for ak411x and juli@ device.
[PATCH 1/4] ALSA: ak411x: Fix stall in work callback [PATCH 2/4] ALSA: ak4114: Move
EXPORT_SYMBOL()after each function [PATCH 3/4] ALSA: ak411x: Add PM helper functions [PATCH 4/4] ALSA: ak411x: Fix race ofreinit()calls
for all of them...
Thanks,
Jaroslav
Signature · 3 lines
Jaroslav Kysela <[email protected]> Linux Kernel Sound Maintainer ALSA Project; Red Hat, Inc.
At Fri, 16 Jan 2015 18:27:39 +0100,
Quoted 6 lines · Jaroslav Kysela
Dne 16.1.2015 v 18:16 Takashi Iwai napsal(a):
Quoted 4 lines
Hi,
here is a bit more cooked patch series for ak411x and juli@ device.
Quoted 8 lines
Quoted 4 lines
[PATCH 1/4] ALSA: ak411x: Fix stall in work callback [PATCH 2/4] ALSA: ak4114: Move
EXPORT_SYMBOL()after each function [PATCH 3/4] ALSA: ak411x: Add PM helper functions [PATCH 4/4] ALSA: ak411x: Fix race ofreinit()callsAcked-by Jaroslav Kysela <[email protected]>for all of them...
Thanks, added your ack to each commit now. They are found in topic/ak411x-fix branch, not merged to for-next yet, though.
Takashi