FAILED: patch "[PATCH] ALSA: hda: cs35l41: Fix ACPI device reference leak on probe failure" failed to apply to 6.18-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 8d70e364e866bdfca81eee24d0688fac9472cfb9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 8d70e364e866bdfca81eee24d0688fac9472cfb9 Mon Sep 17 00:00:00 2001
From: Ma Ke <[email protected]>
Date: Mon, 12 Oct 2026 16:41:52 +0800
Subject: [PATCH] ALSA: hda: cs35l41: Fix ACPI device reference leak on probe
failure
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.
--- sound/hda/codecs/side-codecs/cs35l41_hda.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
sound/hda/codecs/side-codecs/cs35l41_hda.c +6 -6
@@ -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 idev_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);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 ALSA: hda: cs35l41: Use auto-cleanup for put_device()
From: Takashi Iwai <[email protected]>
[ Upstream commit c437a83cc69645edab8e0bfc450a3b706abe759e ]
A temporary refcount management of a struct device can be done gracefully with __clean(put_device) for avoiding potential leaks.
No functional change but just a code cleanup.
Stable-dep-of: 8d70e364e866 ("ALSA: hda: cs35l41: Fix ACPI device reference leak on probe failure")
--- sound/hda/codecs/side-codecs/cs35l41_hda.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
sound/hda/codecs/side-codecs/cs35l41_hda.c +3 -7
@@ -1929,7 +1929,6 @@ int cs35l41_hda_parse_acpi(struct cs35l41_hda *cs35l41, struct device *physdev,static int cs35l41_hda_read_acpi (struct cs35l41_hda *cs35l41,const char *hid,int id) {struct acpi_device *adev; -struct device *physdev;struct spi_device *spi;const char *sub;int ret;
@@ -1941,7 +1940,8 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i } cs35l41->dacpi = adev; - physdev =get_device (acpi_get_first_physical_node (adev)); + struct device *physdev __free(put_device) = +get_device (acpi_get_first_physical_node (adev));if (!physdev) {acpi_dev_put (adev);return -ENODEV ;
@@ -1959,13 +1959,9 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i } ret =cs35l41_hda_parse_acpi (cs35l41, physdev, id); -if (ret) { -put_device (physdev); +if (ret)return ret; - } out: -put_device (physdev); - cs35l41->bypass_fw = false;if (cs35l41->control_bus ==SPI ) { spi =to_spi_device (cs35l41->dev);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 ALSA: hda: cs35l41: Fix ACPI device reference leak on probe failure
From: Ma Ke <[email protected]>
[ Upstream commit 8d70e364e866bdfca81eee24d0688fac9472cfb9 ]
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.
--- sound/hda/codecs/side-codecs/cs35l41_hda.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
sound/hda/codecs/side-codecs/cs35l41_hda.c +6 -6
@@ -1921,7 +1921,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; }
@@ -1942,10 +1941,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))
@@ -2000,8 +1997,10 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int idev_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);
@@ -2088,6 +2087,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);
Signature · 1 line
2.53.0