Skip to content

Commit 1a58d86

Browse files
Yuuoniybroonie
authored andcommitted
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: 4f8ef33 ("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>
1 parent 6b6eddc commit 1a58d86

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

sound/soc/sdw_utils/soc_sdw_utils.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ static int is_sdca_endpoint_present(struct device *dev,
12771277
struct sdw_slave *slave;
12781278
struct device *sdw_dev;
12791279
const char *sdw_codec_name;
1280-
int i;
1280+
int ret, i;
12811281

12821282
dlc = kzalloc(sizeof(*dlc), GFP_KERNEL);
12831283
if (!dlc)
@@ -1307,13 +1307,16 @@ static int is_sdca_endpoint_present(struct device *dev,
13071307
}
13081308

13091309
slave = dev_to_sdw_dev(sdw_dev);
1310-
if (!slave)
1311-
return -EINVAL;
1310+
if (!slave) {
1311+
ret = -EINVAL;
1312+
goto put_device;
1313+
}
13121314

13131315
/* Make sure BIOS provides SDCA properties */
13141316
if (!slave->sdca_data.interface_revision) {
13151317
dev_warn(&slave->dev, "SDCA properties not found in the BIOS\n");
1316-
return 1;
1318+
ret = 1;
1319+
goto put_device;
13171320
}
13181321

13191322
for (i = 0; i < slave->sdca_data.num_functions; i++) {
@@ -1322,15 +1325,20 @@ static int is_sdca_endpoint_present(struct device *dev,
13221325
if (dai_type == dai_info->dai_type) {
13231326
dev_dbg(&slave->dev, "DAI type %d sdca function %s found\n",
13241327
dai_type, slave->sdca_data.function[i].name);
1325-
return 1;
1328+
ret = 1;
1329+
goto put_device;
13261330
}
13271331
}
13281332

13291333
dev_dbg(&slave->dev,
13301334
"SDCA device function for DAI type %d not supported, skip endpoint\n",
13311335
dai_info->dai_type);
13321336

1333-
return 0;
1337+
ret = 0;
1338+
1339+
put_device:
1340+
put_device(sdw_dev);
1341+
return ret;
13341342
}
13351343

13361344
int asoc_sdw_parse_sdw_endpoints(struct snd_soc_card *card,

0 commit comments

Comments
 (0)