* [PATCH v3] ALSA: hda: cs35l41: Fix ACPI device reference leak on probe failure
@ 2026-10-12 8:41 Ma Ke
2026-10-12 15:05 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2026-10-12 8:41 UTC (permalink / raw)
To: david.rhodes, rf, perex, tiwai, sbinding
Cc: linux-sound, patches, linux-kernel, akpm, Ma Ke, stable
cs35l41_hda_probe() takes an acpi_device through
cs35l41_hda_read_acpi() and stores it in cs35l41->dacpi. Only the
failures that happen later reach the err: label, which is where that
reference and cs35l41->acpi_subsystem_id are released, so the early
return taken when cs35l41_hda_read_acpi() fails leaves both behind.
Keep the ownership in the caller instead of dropping the reference
inside cs35l41_hda_read_acpi(). That removes the need to work out
whether a given failure path has already released it, and with it the
double put that cs35l41_hda_parse_acpi() would otherwise cause when it
fails after having released the device itself.
cs35l41_hda_parse_acpi() and the !physdev path no longer put the
reference, and the early failure enters the existing err: cleanup tail
through a new err_acpi label.
The label sits between the reset of the codec and the gpio cleanup, so
an early failure also releases the reset and chip-select descriptors
that cs35l41_hda_parse_acpi() may already have taken, while still
skipping cs35l41_safe_reset() on a codec that was never brought up.
cs35l41->dacpi comes from devm_kzalloc() and is only assigned once the
ACPI device has been found, so the put is a no-op when the lookup
itself failed.
Found by code review.
Fixes: 447106e92a0c ("ALSA: hda: cs35l41: Support mute notifications for CS35L41 HDA")
Cc: stable@vger.kernel.org
Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
Changes in v3:
- Modify the patch. Thanks for Takashi Iwai and Sashiko's suggestions.
Changes in v2:
- cs35l41_hda_parse_acpi() drops cs35l41->dacpi in its own err: label, so
the err_acpi path added by v1 would have dropped that reference a second
time. Clear cs35l41->dacpi there as well, not only on the !physdev path.
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index 62296be45c55..d50c3d8f5303 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -1907,7 +1907,6 @@ int cs35l41_hda_parse_acpi(struct cs35l41_hda *cs35l41, struct device *physdev,
hw_cfg->valid = false;
hw_cfg->gpio1.valid = false;
hw_cfg->gpio2.valid = false;
- acpi_dev_put(cs35l41->dacpi);
return ret;
}
@@ -1928,10 +1927,8 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
cs35l41->dacpi = adev;
struct device *physdev __free(put_device) =
get_device(acpi_get_first_physical_node(adev));
- if (!physdev) {
- acpi_dev_put(adev);
+ if (!physdev)
return -ENODEV;
- }
sub = acpi_get_subsystem_id(ACPI_HANDLE(physdev));
if (IS_ERR(sub))
@@ -1986,8 +1983,10 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
dev_set_drvdata(dev, cs35l41);
ret = cs35l41_hda_read_acpi(cs35l41, device_name, id);
- if (ret)
- return dev_err_probe(cs35l41->dev, ret, "Platform not supported\n");
+ if (ret) {
+ dev_err_probe(cs35l41->dev, ret, "Platform not supported\n");
+ goto err_acpi;
+ }
if (IS_ERR(cs35l41->reset_gpio)) {
ret = PTR_ERR(cs35l41->reset_gpio);
@@ -2074,6 +2073,7 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
err:
if (cs35l41_safe_reset(cs35l41->regmap, cs35l41->hw_cfg.bst_type))
gpiod_set_value_cansleep(cs35l41->reset_gpio, 0);
+err_acpi:
gpiod_put(cs35l41->reset_gpio);
gpiod_put(cs35l41->cs_gpio);
acpi_dev_put(cs35l41->dacpi);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v3] ALSA: hda: cs35l41: Fix ACPI device reference leak on probe failure
2026-10-12 8:41 [PATCH v3] ALSA: hda: cs35l41: Fix ACPI device reference leak on probe failure Ma Ke
@ 2026-10-12 15:05 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-10-12 15:05 UTC (permalink / raw)
To: Ma Ke
Cc: david.rhodes, rf, perex, tiwai, sbinding, linux-sound, patches,
linux-kernel, akpm, stable
On Mon, 12 Oct 2026 10:41:52 +0200,
Ma Ke wrote:
>
> cs35l41_hda_probe() takes an acpi_device through
> cs35l41_hda_read_acpi() and stores it in cs35l41->dacpi. Only the
> failures that happen later reach the err: label, which is where that
> reference and cs35l41->acpi_subsystem_id are released, so the early
> return taken when cs35l41_hda_read_acpi() fails leaves both behind.
>
> Keep the ownership in the caller instead of dropping the reference
> inside cs35l41_hda_read_acpi(). That removes the need to work out
> whether a given failure path has already released it, and with it the
> double put that cs35l41_hda_parse_acpi() would otherwise cause when it
> fails after having released the device itself.
>
> cs35l41_hda_parse_acpi() and the !physdev path no longer put the
> reference, and the early failure enters the existing err: cleanup tail
> through a new err_acpi label.
>
> The label sits between the reset of the codec and the gpio cleanup, so
> an early failure also releases the reset and chip-select descriptors
> that cs35l41_hda_parse_acpi() may already have taken, while still
> skipping cs35l41_safe_reset() on a codec that was never brought up.
>
> cs35l41->dacpi comes from devm_kzalloc() and is only assigned once the
> ACPI device has been found, so the put is a no-op when the lookup
> itself failed.
>
> Found by code review.
>
> Fixes: 447106e92a0c ("ALSA: hda: cs35l41: Support mute notifications for CS35L41 HDA")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
Applied to for-next branch now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-12 15:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-12 8:41 [PATCH v3] ALSA: hda: cs35l41: Fix ACPI device reference leak on probe failure Ma Ke
2026-10-12 15:05 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox