2021-12-07 12:57:17

by 王擎

[permalink] [raw]
Subject: [PATCH] sound: fsl: add missing put_device() call in imx_hdmi_probe()

From: Wang Qing <[email protected]>

of_find_device_by_node() takes a reference to the embedded struct device
which needs to be dropped when error return.

Signed-off-by: Wang Qing <[email protected]>
---
sound/soc/fsl/imx-hdmi.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/sound/soc/fsl/imx-hdmi.c b/sound/soc/fsl/imx-hdmi.c
index 929f69b..89fd8ad
--- a/sound/soc/fsl/imx-hdmi.c
+++ b/sound/soc/fsl/imx-hdmi.c
@@ -125,6 +125,7 @@ static int imx_hdmi_probe(struct platform_device *pdev)

data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
+ put_device(&cpu_pdev->dev);
ret = -ENOMEM;
goto fail;
}
--
2.7.4



2021-12-08 14:05:15

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] sound: fsl: add missing put_device() call in imx_hdmi_probe()

On Tue, Dec 07, 2021 at 04:56:58AM -0800, Qing Wang wrote:
> From: Wang Qing <[email protected]>
>
> of_find_device_by_node() takes a reference to the embedded struct device
> which needs to be dropped when error return.

...

> data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> if (!data) {
> + put_device(&cpu_pdev->dev);

If it's of_find_device_by_node() you need an of_node_put() since you're
dropping a reference on the OF node.


Attachments:
(No filename) (453.00 B)
signature.asc (488.00 B)
Download all attachments

2021-12-09 09:58:58

by 王擎

[permalink] [raw]
Subject: RE: [PATCH] sound: fsl: add missing put_device() call in imx_hdmi_probe()


>> From: Wang Qing <[email protected]>
>>
>> of_find_device_by_node() takes a reference to the embedded struct device
>> which needs to be dropped when error return.
>
>...
>
>>        data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
>>        if (!data) {
>> +             put_device(&cpu_pdev->dev);
>
>If it's of_find_device_by_node() you need an of_node_put() since you're
>dropping a reference on the OF node.
>

Label fail will drop a reference on the OF node.
Also, put_device() is called later except this branch,
we just need to add put_device() here.

Thanks,
Qing

>> ret = -ENOMEM;
>> goto fail;

2021-12-20 11:33:59

by Shengjiu Wang

[permalink] [raw]
Subject: Re: [PATCH] sound: fsl: add missing put_device() call in imx_hdmi_probe()

On Thu, Dec 9, 2021 at 5:58 PM 王擎 <[email protected]> wrote:
>
>
> >> From: Wang Qing <[email protected]>
> >>
> >> of_find_device_by_node() takes a reference to the embedded struct device
> >> which needs to be dropped when error return.
> >
> >...
> >
> >> data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> >> if (!data) {
> >> + put_device(&cpu_pdev->dev);
> >
> >If it's of_find_device_by_node() you need an of_node_put() since you're
> >dropping a reference on the OF node.
> >
>
> Label fail will drop a reference on the OF node.
> Also, put_device() is called later except this branch,
> we just need to add put_device() here.
>
I agree with you. But could you please add the info in this
commit that
the commit:
f670b274f7f6 ASoC: imx-hdmi: add put_device() after of_find_device_by_node()
is partially fixing the original issue, so we still need this fix.

Best regards
Wang Shengjiu