Skip to content

Commit 4e65bda

Browse files
Ma Kebroonie
authored andcommitted
ASoC: wcd934x: fix error handling in wcd934x_codec_parse_data()
wcd934x_codec_parse_data() contains a device reference count leak in of_slim_get_device() where device_find_child() increases the reference count of the device but this reference is not properly decreased in the success path. Add put_device() in wcd934x_codec_parse_data() and add devm_add_action_or_reset() in the probe function, which ensures that the reference count of the device is correctly managed. Memory leak in regmap_init_slimbus() as the allocated regmap is not released when the device is removed. Using devm_regmap_init_slimbus() instead of regmap_init_slimbus() to ensure automatic regmap cleanup on device removal. Calling path: of_slim_get_device() -> of_find_slim_device() -> device_find_child(). As comment of device_find_child() says, 'NOTE: you will need to drop the reference with put_device() after use.'. Found by code review. Cc: [email protected] Fixes: a61f3b4 ("ASoC: wcd934x: add support to wcd9340/wcd9341 codec") Signed-off-by: Ma Ke <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 87cab86 commit 4e65bda

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

sound/soc/codecs/wcd934x.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5831,6 +5831,13 @@ static const struct snd_soc_component_driver wcd934x_component_drv = {
58315831
.endianness = 1,
58325832
};
58335833

5834+
static void wcd934x_put_device_action(void *data)
5835+
{
5836+
struct device *dev = data;
5837+
5838+
put_device(dev);
5839+
}
5840+
58345841
static int wcd934x_codec_parse_data(struct wcd934x_codec *wcd)
58355842
{
58365843
struct device *dev = &wcd->sdev->dev;
@@ -5847,11 +5854,13 @@ static int wcd934x_codec_parse_data(struct wcd934x_codec *wcd)
58475854
return dev_err_probe(dev, -EINVAL, "Unable to get SLIM Interface device\n");
58485855

58495856
slim_get_logical_addr(wcd->sidev);
5850-
wcd->if_regmap = regmap_init_slimbus(wcd->sidev,
5857+
wcd->if_regmap = devm_regmap_init_slimbus(wcd->sidev,
58515858
&wcd934x_ifc_regmap_config);
5852-
if (IS_ERR(wcd->if_regmap))
5859+
if (IS_ERR(wcd->if_regmap)) {
5860+
put_device(&wcd->sidev->dev);
58535861
return dev_err_probe(dev, PTR_ERR(wcd->if_regmap),
58545862
"Failed to allocate ifc register map\n");
5863+
}
58555864

58565865
of_property_read_u32(dev->parent->of_node, "qcom,dmic-sample-rate",
58575866
&wcd->dmic_sample_rate);
@@ -5893,6 +5902,10 @@ static int wcd934x_codec_probe(struct platform_device *pdev)
58935902
if (ret)
58945903
return ret;
58955904

5905+
ret = devm_add_action_or_reset(dev, wcd934x_put_device_action, &wcd->sidev->dev);
5906+
if (ret)
5907+
return ret;
5908+
58965909
/* set default rate 9P6MHz */
58975910
regmap_update_bits(wcd->regmap, WCD934X_CODEC_RPM_CLK_MCLK_CFG,
58985911
WCD934X_CODEC_RPM_CLK_MCLK_CFG_MCLK_MASK,

0 commit comments

Comments
 (0)