From: Chancel Liu <chancel.liu@oss.nxp.com>
To: Mark Brown <broonie@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Oder Chiou <oder_chiou@realtek.com>,
Cezary Rojewski <cezary.rojewski@intel.com>
Cc: Support Opensource <support.opensource@diasemi.com>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@opensource.cirrus.com
Subject: [PATCH v2 00/21] ASoC: codecs: Fix resource leaks across card bind/unbind
Date: Wed, 23 Sep 2026 15:12:44 +0900 [thread overview]
Message-ID: <20260923061305.4041197-1-chancel.liu@oss.nxp.com> (raw)
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.
Changes in v2:
- All patches: prefix the subject with "ASoC: codecs:" (Cezary Rojewski).
- da7218: also move the device tree parsing (da7218_of_to_pdata(), which
allocates with devm) to the i2c probe (Mark Brown).
- rt5514-spi: keep the original behaviour of continuing probe when the
IRQ request fails (Mark Brown).
- wm8985: move the "Failed to request supplies" error message into the
wm8985_get_regulators() helper instead of duplicating it in both the
i2c and spi probes (Charles Keepax).
- rt5640: acquire the mclk near the start of the i2c probe, before the
ldo1_en handling and its msleep(400), so a deferred probe does not
repeat the long hardware delays on every retry. Reported by Sashiko.
- rt5677-spi: serialize the DSP context teardown in the component .remove
against the exported rt5677_spi_hotword_detected() callback with a
dedicated lock, to avoid a use-after-free. Reported by Sashiko.
- es8389: drop the now-unused variable "i" in es8389_probe() left behind
after moving the regulator loop to the i2c probe. Reported by Sashiko.
v1: https://lore.kernel.org/linux-sound/20260921104640.1941554-1-chancel.liu@oss.nxp.com/
Chancel Liu (21):
ASoC: codecs: cpcap: Fix devm resource leaks across card bind/unbind
ASoC: codecs: da7218: Fix devm resource leaks across card bind/unbind
ASoC: codecs: tlv320aic32x4: Fix clock leak from runtime callbacks
ASoC: codecs: twl4030: Acquire board params and hs_extmute GPIO in the
platform probe
ASoC: codecs: es8316: Move mclk acquisition to the i2c probe
ASoC: codecs: es8323: Move mclk acquisition to the i2c probe
ASoC: codecs: es8311: Move mclk acquisition to the i2c probe
ASoC: codecs: es8328: Move clk acquisition to the bus probe
ASoC: codecs: rt5640: Move mclk acquisition to the i2c probe
ASoC: codecs: rt5616: Move mclk acquisition to the i2c probe
ASoC: codecs: rt5514: Move clk acquisition to the i2c probe
ASoC: codecs: rt5682s: Move mclk acquisition to the i2c probe
ASoC: codecs: max98090: Move mclk acquisition to the i2c probe
ASoC: codecs: max98095: Move mclk acquisition to the i2c probe
ASoC: codecs: wm8985: Move regulator acquisition to the bus probe
ASoC: codecs: wm8955: Move regulator acquisition to the i2c probe
ASoC: codecs: es8389: Move regulator and mclk acquisition to the i2c
probe
ASoC: codecs: rt5677-spi: Free the DSP context on component remove
ASoC: codecs: rt1011: Free the bq/drc coefficient arrays on component
remove
ASoC: codecs: rt5645: Free the hardware EQ parameters on component
remove
ASoC: codecs: rt5514-spi: Free the DSP context on component remove
sound/soc/codecs/cpcap.c | 74 +++++++++++-------
sound/soc/codecs/da7218.c | 129 ++++++++++++++++---------------
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 | 36 ++++-----
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 | 21 ++++-
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 | 35 ++++++---
21 files changed, 388 insertions(+), 293 deletions(-)
--
2.50.1
next reply other threads:[~2026-09-23 6:13 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 6:12 Chancel Liu [this message]
2026-09-23 6:12 ` [PATCH v2 01/21] ASoC: codecs: cpcap: Fix devm " Chancel Liu
2026-09-23 6:12 ` [PATCH v2 02/21] ASoC: codecs: da7218: " Chancel Liu
2026-09-23 6:12 ` [PATCH v2 03/21] ASoC: codecs: tlv320aic32x4: Fix clock leak from runtime callbacks Chancel Liu
2026-09-23 6:12 ` [PATCH v2 04/21] ASoC: codecs: twl4030: Acquire board params and hs_extmute GPIO in the platform probe Chancel Liu
2026-09-23 6:12 ` [PATCH v2 05/21] ASoC: codecs: es8316: Move mclk acquisition to the i2c probe Chancel Liu
2026-09-23 8:19 ` Cezary Rojewski
2026-09-23 6:12 ` [PATCH v2 06/21] ASoC: codecs: es8323: " Chancel Liu
2026-09-23 6:12 ` [PATCH v2 07/21] ASoC: codecs: es8311: " Chancel Liu
2026-09-23 6:12 ` [PATCH v2 08/21] ASoC: codecs: es8328: Move clk acquisition to the bus probe Chancel Liu
2026-09-23 6:12 ` [PATCH v2 09/21] ASoC: codecs: rt5640: Move mclk acquisition to the i2c probe Chancel Liu
2026-09-23 8:16 ` Cezary Rojewski
2026-09-23 8:22 ` Chancel Liu
2026-09-23 6:12 ` [PATCH v2 10/21] ASoC: codecs: rt5616: " Chancel Liu
2026-09-23 6:12 ` [PATCH v2 11/21] ASoC: codecs: rt5514: Move clk " Chancel Liu
2026-09-23 8:19 ` Cezary Rojewski
2026-09-23 6:12 ` [PATCH v2 12/21] ASoC: codecs: rt5682s: Move mclk " Chancel Liu
2026-09-23 6:12 ` [PATCH v2 13/21] ASoC: codecs: max98090: " Chancel Liu
2026-09-23 6:12 ` [PATCH v2 14/21] ASoC: codecs: max98095: " Chancel Liu
2026-09-23 6:12 ` [PATCH v2 15/21] ASoC: codecs: wm8985: Move regulator acquisition to the bus probe Chancel Liu
2026-09-23 8:56 ` Charles Keepax
2026-09-23 6:13 ` [PATCH v2 16/21] ASoC: codecs: wm8955: Move regulator acquisition to the i2c probe Chancel Liu
2026-09-23 6:13 ` [PATCH v2 17/21] ASoC: codecs: es8389: Move regulator and mclk " Chancel Liu
2026-09-23 6:13 ` [PATCH v2 18/21] ASoC: codecs: rt5677-spi: Free the DSP context on component remove Chancel Liu
2026-09-23 6:13 ` [PATCH v2 19/21] ASoC: codecs: rt1011: Free the bq/drc coefficient arrays " Chancel Liu
2026-09-23 6:13 ` [PATCH v2 20/21] ASoC: codecs: rt5645: Free the hardware EQ parameters " Chancel Liu
2026-09-23 6:13 ` [PATCH v2 21/21] ASoC: codecs: rt5514-spi: Free the DSP context " Chancel Liu
2026-09-23 12:27 ` [PATCH v2 00/21] ASoC: codecs: Fix resource leaks across card bind/unbind Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260923061305.4041197-1-chancel.liu@oss.nxp.com \
--to=chancel.liu@oss.nxp.com \
--cc=broonie@kernel.org \
--cc=cezary.rojewski@intel.com \
--cc=ckeepax@opensource.cirrus.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=oder_chiou@realtek.com \
--cc=patches@opensource.cirrus.com \
--cc=perex@perex.cz \
--cc=support.opensource@diasemi.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®