mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 00/21] ASoC: codecs: Fix resource leaks across card bind/unbind
@ 2026-09-21 10:46 Chancel Liu
  2026-09-21 10:46 ` [PATCH 01/21] ASoC: cpcap: Fix devm " Chancel Liu
                   ` (20 more replies)
  0 siblings, 21 replies; 33+ messages in thread
From: Chancel Liu @ 2026-09-21 10:46 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Charles Keepax, Oder Chiou
  Cc: Support Opensource, linux-sound, linux-kernel, patches

From: Chancel Liu <chancel.liu@nxp.com>

For an ASoC component, component->dev is the underlying bus device
(I2C / SPI / platform). Its devres lifetime is tied to the physical
device's probe/remove, not to the ASoC card's bind/unbind.

A card bind (snd_soc_bind_card()) / unbind (snd_soc_unbind_card())
runs the component .probe / .remove callbacks, but the bus device
itself stays bound across the cycle. Resources requested from the
component .probe (or from a runtime DAI callback) with
devm_*(component->dev, ...), or allocated there and only released when
the bus device is removed, therefore outlive a card unbind and
accumulate one extra copy on every bind/unbind cycle.

Each codec is fixed following one of two principles, chosen by what the
resource actually depends on:

1. Pure hardware resources (clk / regulator / regmap / GPIO / board
   description) only depend on the physical device, not on the ASoC
   component.

   Their acquisition is moved to the bus probe (i2c / spi / platform probe)
   using devm_*(&client->dev, ...), so their devres lifetime correctly
   follows the device and they are not re-requested on every bind.

2. Resources that genuinely depend on the card/component (they are bound
   to the component, or must be torn down when the card is unbound)

   They are kept in the component .probe, but switched from devm to
   plain allocation and released in a paired component .remove:
   memory (kzalloc/kcalloc + kfree), IRQ (request_irq + free_irq),
   delayed work (cancel), wakeup source and mutex.

While working on the card re-bind resource leaks fixed in
https://lore.kernel.org/linux-sound/20260913101531.2787654-1-chancel.liu@oss.nxp.com/

I noticed that the same devm-on-component->dev pattern is present in
many other codecs, leaking resources in the same way.

This series is the result of code analysis only, based on the same
devm-without-remove leak pattern I confirmed by repeated card bind/unbind
with wm8962. The individual fixes have not been tested on hardware, as I
do not have access to these codecs; review of the resource lifetimes
is therefore appreciated.

Chancel Liu (21):
  ASoC: cpcap: Fix devm resource leaks across card bind/unbind
  ASoC: da7218: Fix devm resource leaks across card bind/unbind
  ASoC: tlv320aic32x4: Fix clock leak from runtime callbacks
  ASoC: twl4030: Acquire board params and hs_extmute GPIO in the
    platform probe
  ASoC: es8316: Move mclk acquisition to the i2c probe
  ASoC: es8323: Move mclk acquisition to the i2c probe
  ASoC: es8311: Move mclk acquisition to the i2c probe
  ASoC: es8328: Move clk acquisition to the bus probe
  ASoC: rt5640: Move mclk acquisition to the i2c probe
  ASoC: rt5616: Move mclk acquisition to the i2c probe
  ASoC: rt5514: Move clk acquisition to the i2c probe
  ASoC: rt5682s: Move mclk acquisition to the i2c probe
  ASoC: max98090: Move mclk acquisition to the i2c probe
  ASoC: max98095: Move mclk acquisition to the i2c probe
  ASoC: wm8985: Move regulator acquisition to the bus probe
  ASoC: wm8955: Move regulator acquisition to the i2c probe
  ASoC: es8389: Move regulator and mclk acquisition to the i2c probe
  ASoC: rt5677-spi: Free the DSP context on component remove
  ASoC: rt1011: Free the bq/drc coefficient arrays on component remove
  ASoC: rt5645: Free the hardware EQ parameters on component remove
  ASoC: rt5514-spi: Free the DSP context on component remove

 sound/soc/codecs/cpcap.c         | 74 +++++++++++++++----------
 sound/soc/codecs/da7218.c        | 49 +++++++++--------
 sound/soc/codecs/es8311.c        | 10 ++--
 sound/soc/codecs/es8316.c        | 14 ++---
 sound/soc/codecs/es8323.c        | 15 ++---
 sound/soc/codecs/es8328.c        | 13 ++---
 sound/soc/codecs/es8389.c        | 34 ++++++------
 sound/soc/codecs/max98090.c      | 10 ++--
 sound/soc/codecs/max98095.c      | 10 ++--
 sound/soc/codecs/rt1011.c        | 30 +++++++---
 sound/soc/codecs/rt5514-spi.c    | 37 ++++++++++---
 sound/soc/codecs/rt5514.c        | 23 ++++----
 sound/soc/codecs/rt5616.c        | 10 ++--
 sound/soc/codecs/rt5640.c        | 10 ++--
 sound/soc/codecs/rt5645.c        | 11 ++--
 sound/soc/codecs/rt5677-spi.c    | 16 +++++-
 sound/soc/codecs/rt5682s.c       | 12 ++--
 sound/soc/codecs/tlv320aic32x4.c | 94 +++++++++++++++-----------------
 sound/soc/codecs/twl4030.c       | 63 ++++++++++++++-------
 sound/soc/codecs/wm8955.c        | 24 ++++----
 sound/soc/codecs/wm8985.c        | 34 ++++++++----
 21 files changed, 340 insertions(+), 253 deletions(-)

--
2.50.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2026-09-22  2:35 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-21 10:46 [PATCH 00/21] ASoC: codecs: Fix resource leaks across card bind/unbind Chancel Liu
2026-09-21 10:46 ` [PATCH 01/21] ASoC: cpcap: Fix devm " Chancel Liu
2026-09-21 10:46 ` [PATCH 02/21] ASoC: da7218: " Chancel Liu
2026-09-21 10:46 ` [PATCH 03/21] ASoC: tlv320aic32x4: Fix clock leak from runtime callbacks Chancel Liu
2026-09-21 10:46 ` [PATCH 04/21] ASoC: twl4030: Acquire board params and hs_extmute GPIO in the platform probe Chancel Liu
2026-09-21 10:46 ` [PATCH 05/21] ASoC: es8316: Move mclk acquisition to the i2c probe Chancel Liu
2026-09-21 10:46 ` [PATCH 06/21] ASoC: es8323: " Chancel Liu
2026-09-21 13:17   ` Mark Brown
2026-09-21 13:18     ` Mark Brown
2026-09-22  2:18       ` Chancel Liu
2026-09-21 10:46 ` [PATCH 07/21] ASoC: es8311: " Chancel Liu
2026-09-21 10:46 ` [PATCH 08/21] ASoC: es8328: Move clk acquisition to the bus probe Chancel Liu
2026-09-21 10:46 ` [PATCH 09/21] ASoC: rt5640: Move mclk acquisition to the i2c probe Chancel Liu
2026-09-21 18:28   ` Cezary Rojewski
2026-09-21 10:46 ` [PATCH 10/21] ASoC: rt5616: " Chancel Liu
2026-09-21 10:46 ` [PATCH 11/21] ASoC: rt5514: Move clk " Chancel Liu
2026-09-21 10:46 ` [PATCH 12/21] ASoC: rt5682s: Move mclk " Chancel Liu
2026-09-21 18:44   ` Cezary Rojewski
2026-09-22  2:34     ` Chancel Liu
2026-09-21 10:46 ` [PATCH 13/21] ASoC: max98090: " Chancel Liu
2026-09-21 10:46 ` [PATCH 14/21] ASoC: max98095: " Chancel Liu
2026-09-21 10:46 ` [PATCH 15/21] ASoC: wm8985: Move regulator acquisition to the bus probe Chancel Liu
2026-09-21 11:52   ` Charles Keepax
2026-09-22  2:01     ` Chancel Liu
2026-09-21 10:46 ` [PATCH 16/21] ASoC: wm8955: Move regulator acquisition to the i2c probe Chancel Liu
2026-09-21 10:58   ` Charles Keepax
2026-09-21 10:46 ` [PATCH 17/21] ASoC: es8389: Move regulator and mclk " Chancel Liu
2026-09-21 10:46 ` [PATCH 18/21] ASoC: rt5677-spi: Free the DSP context on component remove Chancel Liu
2026-09-21 10:46 ` [PATCH 19/21] ASoC: rt1011: Free the bq/drc coefficient arrays " Chancel Liu
2026-09-21 10:46 ` [PATCH 20/21] ASoC: rt5645: Free the hardware EQ parameters " Chancel Liu
2026-09-21 10:46 ` [PATCH 21/21] ASoC: rt5514-spi: Free the DSP context " Chancel Liu
2026-09-21 13:23   ` Mark Brown
2026-09-22  2:31     ` Chancel Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®