[PATCH] ASoC: sdw_utils: Use auto-cleanup for put_device()

Takashi Iwai posted 1 patch 1 month, 4 weeks ago
sound/soc/sdw_utils/soc_sdw_utils.c | 36 ++++++++++-------------------
1 file changed, 12 insertions(+), 24 deletions(-)
[PATCH] ASoC: sdw_utils: Use auto-cleanup for put_device()
Posted by Takashi Iwai 1 month, 4 weeks ago
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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/sdw_utils/soc_sdw_utils.c | 36 ++++++++++-------------------
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/soc_sdw_utils.c
index d4074309fa81..8a07ba2a29e5 100644
--- a/sound/soc/sdw_utils/soc_sdw_utils.c
+++ b/sound/soc/sdw_utils/soc_sdw_utils.c
@@ -1818,9 +1818,7 @@ static int is_sdca_aux_dev_present(struct device *dev,
 				   int adr_index)
 {
 	struct sdw_slave *slave;
-	struct device *sdw_dev;
 	const char *sdw_codec_name;
-	int ret = 0;
 	int i;
 
 	if (!aux_codec_name)
@@ -1830,7 +1828,8 @@ static int is_sdca_aux_dev_present(struct device *dev,
 	if (!sdw_codec_name)
 		return -ENOMEM;
 
-	sdw_dev = bus_find_device_by_name(&sdw_bus_type, NULL, sdw_codec_name);
+	struct device *sdw_dev __free(put_device) =
+		bus_find_device_by_name(&sdw_bus_type, NULL, sdw_codec_name);
 	if (!sdw_dev) {
 		dev_err(dev, "codec %s not found\n", sdw_codec_name);
 		return -EINVAL;
@@ -1840,24 +1839,19 @@ static int is_sdca_aux_dev_present(struct device *dev,
 
 	if (!slave->sdca_data.interface_revision) {
 		dev_warn(dev, "No SDCA properties, assuming aux '%s' present\n", aux_codec_name);
-		ret = 1;
-		goto put_dev;
+		return 1;
 	}
 
 	for (i = 0; i < slave->sdca_data.num_functions; i++) {
 		const char *fname = slave->sdca_data.function[i].name;
 
-		if (fname && strstr(aux_codec_name, fname)) {
-			ret = 1;
-			goto put_dev;
-		}
+		if (fname && strstr(aux_codec_name, fname))
+			return 1;
 	}
 
 	dev_dbg(dev, "SDCA function for aux '%s' NOT FOUND on slave, skipping\n", aux_codec_name);
 
-put_dev:
-	put_device(sdw_dev);
-	return ret;
+	return 0;
 }
 
 int asoc_sdw_count_sdw_endpoints(struct snd_soc_card *card,
@@ -1957,9 +1951,8 @@ static int is_sdca_endpoint_present(struct device *dev,
 	const struct snd_soc_acpi_endpoint *adr_end;
 	const struct asoc_sdw_dai_info *dai_info;
 	struct sdw_slave *slave;
-	struct device *sdw_dev;
 	const char *sdw_codec_name;
-	int ret, i;
+	int i;
 
 	adr_end = &adr_dev->endpoints[end_index];
 	dai_info = &codec_info->dais[adr_end->num];
@@ -1968,7 +1961,8 @@ static int is_sdca_endpoint_present(struct device *dev,
 	if (!sdw_codec_name)
 		return -ENOMEM;
 
-	sdw_dev = bus_find_device_by_name(&sdw_bus_type, NULL, sdw_codec_name);
+	struct device *sdw_dev __free(put_device) =
+		bus_find_device_by_name(&sdw_bus_type, NULL, sdw_codec_name);
 	if (!sdw_dev) {
 		dev_err(dev, "codec %s not found\n", sdw_codec_name);
 		return -EINVAL;
@@ -1979,8 +1973,7 @@ static int is_sdca_endpoint_present(struct device *dev,
 	/* Make sure BIOS provides SDCA properties */
 	if (!slave->sdca_data.interface_revision) {
 		dev_warn(&slave->dev, "SDCA properties not found in the BIOS\n");
-		ret = 1;
-		goto put_device;
+		return 1;
 	}
 
 	for (i = 0; i < slave->sdca_data.num_functions; i++) {
@@ -1989,8 +1982,7 @@ static int is_sdca_endpoint_present(struct device *dev,
 		if (dai_type == dai_info->dai_type) {
 			dev_dbg(&slave->dev, "DAI type %d sdca function %s found\n",
 				dai_type, slave->sdca_data.function[i].name);
-			ret = 1;
-			goto put_device;
+			return 1;
 		}
 	}
 
@@ -1998,11 +1990,7 @@ static int is_sdca_endpoint_present(struct device *dev,
 		"SDCA device function for DAI type %d not supported, skip endpoint\n",
 		dai_info->dai_type);
 
-	ret = 0;
-
-put_device:
-	put_device(sdw_dev);
-	return ret;
+	return 0;
 }
 
 int asoc_sdw_parse_sdw_endpoints(struct device *dev,
-- 
2.55.0
Re: [PATCH] ASoC: sdw_utils: Use auto-cleanup for put_device()
Posted by Mark Brown 1 month, 4 weeks ago
On Mon, 03 Aug 2026 15:56:12 +0200, Takashi Iwai wrote:
> ASoC: sdw_utils: Use auto-cleanup for put_device()

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.3

Thanks!

[1/1] ASoC: sdw_utils: Use auto-cleanup for put_device()
      https://git.kernel.org/broonie/sound/c/cf07f148068c

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark