From: Tristan Madani rt5668_remove() does not disable the IRQ or cancel the pending jack_detect_work and jd_check_work delayed works. If the component is unbound while work is pending, the handlers access freed memory. Track IRQ acquisition in rt5668_i2c_probe() via an irq_acquired flag. In rt5668_remove(), disable the IRQ (if acquired) and cancel both delayed works before resetting the codec. Re-enable the IRQ in rt5668_probe() when a sound card rebinds to prevent permanent IRQ silencing across card unbind/rebind cycles. Fixes: d59fb2856223 ("ASoC: rt5668: add rt5668B codec driver") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani --- sound/soc/codecs/rt5668.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt5668.c b/sound/soc/codecs/rt5668.c index cd6245d6b91af..29d70802a046a 100644 --- a/sound/soc/codecs/rt5668.c +++ b/sound/soc/codecs/rt5668.c @@ -62,6 +62,9 @@ struct rt5668_priv { int pll_out; int jack_type; + + bool irq_acquired; + bool irq_disabled; }; static const struct reg_default rt5668_reg[] = { @@ -2216,12 +2219,26 @@ static int rt5668_probe(struct snd_soc_component *component) rt5668->component = component; + if (rt5668->irq_disabled) { + enable_irq(to_i2c_client(component->dev)->irq); + rt5668->irq_disabled = false; + } + return 0; } static void rt5668_remove(struct snd_soc_component *component) { struct rt5668_priv *rt5668 = snd_soc_component_get_drvdata(component); + struct i2c_client *i2c = to_i2c_client(component->dev); + + if (rt5668->irq_acquired) { + disable_irq(i2c->irq); + rt5668->irq_disabled = true; + } + + cancel_delayed_work_sync(&rt5668->jack_detect_work); + cancel_delayed_work_sync(&rt5668->jd_check_work); rt5668_reset(rt5668->regmap); } @@ -2555,7 +2572,8 @@ static int rt5668_i2c_probe(struct i2c_client *i2c) | IRQF_ONESHOT, "rt5668", rt5668); if (ret) dev_err(&i2c->dev, "Failed to request IRQ: %d\n", ret); - + else + rt5668->irq_acquired = true; } return devm_snd_soc_register_component(&i2c->dev, &soc_component_dev_rt5668, -- 2.47.3