Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: sdw_utils: fix device reference leak in is_sdca_endpoint_present()

The bus_find_device_by_name() function returns a device pointer with an
incremented reference count, but the original code was missing put_device()
calls in some return paths, leading to reference count leaks.

Fix this by ensuring put_device() is called before function exit after
bus_find_device_by_name() succeeds

This follows the same pattern used elsewhere in the kernel where
bus_find_device_by_name() is properly paired with put_device().

Found via static analysis and code review.

Fixes: 4f8ef33dd44a ("ASoC: soc_sdw_utils: skip the endpoint that doesn't present")
Cc: stable@vger.kernel.org
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Link: https://patch.msgid.link/20251029071804.8425-1-linmq006@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Miaoqian Lin and committed by
Mark Brown
1a58d865 6b6eddc6

+14 -6
+14 -6
sound/soc/sdw_utils/soc_sdw_utils.c
··· 1277 1277 struct sdw_slave *slave; 1278 1278 struct device *sdw_dev; 1279 1279 const char *sdw_codec_name; 1280 - int i; 1280 + int ret, i; 1281 1281 1282 1282 dlc = kzalloc(sizeof(*dlc), GFP_KERNEL); 1283 1283 if (!dlc) ··· 1307 1307 } 1308 1308 1309 1309 slave = dev_to_sdw_dev(sdw_dev); 1310 - if (!slave) 1311 - return -EINVAL; 1310 + if (!slave) { 1311 + ret = -EINVAL; 1312 + goto put_device; 1313 + } 1312 1314 1313 1315 /* Make sure BIOS provides SDCA properties */ 1314 1316 if (!slave->sdca_data.interface_revision) { 1315 1317 dev_warn(&slave->dev, "SDCA properties not found in the BIOS\n"); 1316 - return 1; 1318 + ret = 1; 1319 + goto put_device; 1317 1320 } 1318 1321 1319 1322 for (i = 0; i < slave->sdca_data.num_functions; i++) { ··· 1325 1322 if (dai_type == dai_info->dai_type) { 1326 1323 dev_dbg(&slave->dev, "DAI type %d sdca function %s found\n", 1327 1324 dai_type, slave->sdca_data.function[i].name); 1328 - return 1; 1325 + ret = 1; 1326 + goto put_device; 1329 1327 } 1330 1328 } 1331 1329 ··· 1334 1330 "SDCA device function for DAI type %d not supported, skip endpoint\n", 1335 1331 dai_info->dai_type); 1336 1332 1337 - return 0; 1333 + ret = 0; 1334 + 1335 + put_device: 1336 + put_device(sdw_dev); 1337 + return ret; 1338 1338 } 1339 1339 1340 1340 int asoc_sdw_parse_sdw_endpoints(struct snd_soc_card *card,