2023-04-18 09:10:11

by Li Yang

[permalink] [raw]
Subject: [PATCH] usb: phy: phy-tahvo: fix memory leak in tahvo_usb_probe()

Smatch reports:
drivers/usb/phy/phy-tahvo.c: tahvo_usb_probe()
warn: missing unwind goto?

After geting irq, if ret < 0, it will return without error handling to
free memory.
Just add error handling to fix this problem.

Fixes: 0d45a1373e66 ("usb: phy: tahvo: add IRQ check")
Signed-off-by: Li Yang <[email protected]>
Reviewed-by: Dongliang Mu <[email protected]>
---
The issue is found by static analysis, and the patch remains untest.
---
drivers/usb/phy/phy-tahvo.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
index f2d2cc586c5b..184a5f3d7473 100644
--- a/drivers/usb/phy/phy-tahvo.c
+++ b/drivers/usb/phy/phy-tahvo.c
@@ -390,8 +390,11 @@ static int tahvo_usb_probe(struct platform_device *pdev)
dev_set_drvdata(&pdev->dev, tu);

tu->irq = ret = platform_get_irq(pdev, 0);
- if (ret < 0)
- return ret;
+ if (ret < 0) {
+ dev_err(&pdev->dev, "could not get irq: %d\n",
+ ret);
+ goto err_remove_phy;
+ }
ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt,
IRQF_ONESHOT,
"tahvo-vbus", tu);
--
2.34.1


2023-04-18 09:26:10

by 李阳

[permalink] [raw]
Subject: Re: [PATCH] usb: phy: phy-tahvo: fix memory leak in tahvo_usb_probe()




> -----Original Messages-----
> From: "Li Yang" <[email protected]>
> Sent Time: 2023-04-18 17:07:57 (Tuesday)
> To: "Greg Kroah-Hartman" <[email protected]>, "Felipe Balbi" <[email protected]>, "Sergey Shtylyov" <[email protected]>
> Cc: "Li Yang" <[email protected]>, "Dongliang Mu" <[email protected]>, [email protected], [email protected]
> Subject: [PATCH] usb: phy: phy-tahvo: fix memory leak in tahvo_usb_probe()
>
> Smatch reports:
> drivers/usb/phy/phy-tahvo.c: tahvo_usb_probe()
> warn: missing unwind goto?
>
> After geting irq, if ret < 0, it will return without error handling to
> free memory.
> Just add error handling to fix this problem.
>
> Fixes: 0d45a1373e66 ("usb: phy: tahvo: add IRQ check")
> Signed-off-by: Li Yang <[email protected]>
> Reviewed-by: Dongliang Mu <[email protected]>
> ---
> The issue is found by static analysis, and the patch remains untest.
> ---
> drivers/usb/phy/phy-tahvo.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
> index f2d2cc586c5b..184a5f3d7473 100644
> --- a/drivers/usb/phy/phy-tahvo.c
> +++ b/drivers/usb/phy/phy-tahvo.c
> @@ -390,8 +390,11 @@ static int tahvo_usb_probe(struct platform_device *pdev)
> dev_set_drvdata(&pdev->dev, tu);
>
> tu->irq = ret = platform_get_irq(pdev, 0);
> - if (ret < 0)
> - return ret;
> + if (ret < 0) {
> + dev_err(&pdev->dev, "could not get irq: %d\n",
> + ret);
> + goto err_remove_phy;
> + }
> ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt,
> IRQF_ONESHOT,
> "tahvo-vbus", tu);
> --
> 2.34.1
cc [email protected]

2023-04-18 09:31:30

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] usb: phy: phy-tahvo: fix memory leak in tahvo_usb_probe()

On Tue, Apr 18, 2023 at 05:07:57PM +0800, Li Yang wrote:
> Smatch reports:
> drivers/usb/phy/phy-tahvo.c: tahvo_usb_probe()
> warn: missing unwind goto?
>
> After geting irq, if ret < 0, it will return without error handling to
> free memory.
> Just add error handling to fix this problem.
>
> Fixes: 0d45a1373e66 ("usb: phy: tahvo: add IRQ check")
> Signed-off-by: Li Yang <[email protected]>
> Reviewed-by: Dongliang Mu <[email protected]>
> ---
> The issue is found by static analysis, and the patch remains untest.
> ---
> drivers/usb/phy/phy-tahvo.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
> index f2d2cc586c5b..184a5f3d7473 100644
> --- a/drivers/usb/phy/phy-tahvo.c
> +++ b/drivers/usb/phy/phy-tahvo.c
> @@ -390,8 +390,11 @@ static int tahvo_usb_probe(struct platform_device *pdev)
> dev_set_drvdata(&pdev->dev, tu);
>
> tu->irq = ret = platform_get_irq(pdev, 0);
> - if (ret < 0)
> - return ret;
> + if (ret < 0) {
> + dev_err(&pdev->dev, "could not get irq: %d\n",
> + ret);

Why print this out? And why the odd line-wrapping?

thanks,

greg k-h

2023-04-18 11:07:01

by 李阳

[permalink] [raw]
Subject: Re: Re: [PATCH] usb: phy: phy-tahvo: fix memory leak in tahvo_usb_probe()




> -----Original Messages-----
> From: "Greg Kroah-Hartman" <[email protected]>
> Sent Time: 2023-04-18 17:19:12 (Tuesday)
> To: "Li Yang" <[email protected]>
> Cc: "Felipe Balbi" <[email protected]>, "Sergey Shtylyov" <[email protected]>, "Dongliang Mu" <[email protected]>, [email protected], [email protected]
> Subject: Re: [PATCH] usb: phy: phy-tahvo: fix memory leak in tahvo_usb_probe()
>
> On Tue, Apr 18, 2023 at 05:07:57PM +0800, Li Yang wrote:
> > Smatch reports:
> > drivers/usb/phy/phy-tahvo.c: tahvo_usb_probe()
> > warn: missing unwind goto?
> >
> > After geting irq, if ret < 0, it will return without error handling to
> > free memory.
> > Just add error handling to fix this problem.
> >
> > Fixes: 0d45a1373e66 ("usb: phy: tahvo: add IRQ check")
> > Signed-off-by: Li Yang <[email protected]>
> > Reviewed-by: Dongliang Mu <[email protected]>
> > ---
> > The issue is found by static analysis, and the patch remains untest.
> > ---
> > drivers/usb/phy/phy-tahvo.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
> > index f2d2cc586c5b..184a5f3d7473 100644
> > --- a/drivers/usb/phy/phy-tahvo.c
> > +++ b/drivers/usb/phy/phy-tahvo.c
> > @@ -390,8 +390,11 @@ static int tahvo_usb_probe(struct platform_device *pdev)
> > dev_set_drvdata(&pdev->dev, tu);
> >
> > tu->irq = ret = platform_get_irq(pdev, 0);
> > - if (ret < 0)
> > - return ret;
> > + if (ret < 0) {
> > + dev_err(&pdev->dev, "could not get irq: %d\n",
> > + ret);
>
> Why print this out? And why the odd line-wrapping?
>
> thanks,
>
> greg k-h
For the first question, I am just emulating the coding style of the original author who outputs corresponding information after each error. If there is anything unreasonable about doing so, please let me know. As for the second question, it's my mistake and I will correct it immediately.

regrads,
Li Yang

2023-04-18 11:35:16

by Sergey Shtylyov

[permalink] [raw]
Subject: Re: [PATCH] usb: phy: phy-tahvo: fix memory leak in tahvo_usb_probe()

Hello!

On 4/18/23 12:07 PM, Li Yang wrote:

> Smatch reports:
> drivers/usb/phy/phy-tahvo.c: tahvo_usb_probe()
> warn: missing unwind goto?
>
> After geting irq, if ret < 0, it will return without error handling to
> free memory.
> Just add error handling to fix this problem.

Oops, I'm sorry for missing that one...

> Fixes: 0d45a1373e66 ("usb: phy: tahvo: add IRQ check")
> Signed-off-by: Li Yang <[email protected]>
> Reviewed-by: Dongliang Mu <[email protected]>
> ---
> The issue is found by static analysis, and the patch remains untest.
> ---
> drivers/usb/phy/phy-tahvo.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
> index f2d2cc586c5b..184a5f3d7473 100644
> --- a/drivers/usb/phy/phy-tahvo.c
> +++ b/drivers/usb/phy/phy-tahvo.c
> @@ -390,8 +390,11 @@ static int tahvo_usb_probe(struct platform_device *pdev)
> dev_set_drvdata(&pdev->dev, tu);
>
> tu->irq = ret = platform_get_irq(pdev, 0);
> - if (ret < 0)
> - return ret;
> + if (ret < 0) {
> + dev_err(&pdev->dev, "could not get irq: %d\n",
> + ret);

Adding the error message needs another patch, strictly speaking...

> + goto err_remove_phy;
> + }
> ret = request_threaded_irq(tu->irq, NULL, tahvo_usb_vbus_interrupt,
> IRQF_ONESHOT,
> "tahvo-vbus", tu);

MBR, Sergey

2023-04-19 09:03:53

by Sergey Shtylyov

[permalink] [raw]
Subject: Re: [PATCH] usb: phy: phy-tahvo: fix memory leak in tahvo_usb_probe()

On 4/18/23 2:17 PM, Sergey Shtylyov wrote:
[...]
>> Smatch reports:
>> drivers/usb/phy/phy-tahvo.c: tahvo_usb_probe()
>> warn: missing unwind goto?
>>
>> After geting irq, if ret < 0, it will return without error handling to
>> free memory.
>> Just add error handling to fix this problem.
>
> Oops, I'm sorry for missing that one...
>
>> Fixes: 0d45a1373e66 ("usb: phy: tahvo: add IRQ check")
>> Signed-off-by: Li Yang <[email protected]>
>> Reviewed-by: Dongliang Mu <[email protected]>
>> ---
>> The issue is found by static analysis, and the patch remains untest.
>> ---
>> drivers/usb/phy/phy-tahvo.c | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
>> index f2d2cc586c5b..184a5f3d7473 100644
>> --- a/drivers/usb/phy/phy-tahvo.c
>> +++ b/drivers/usb/phy/phy-tahvo.c
>> @@ -390,8 +390,11 @@ static int tahvo_usb_probe(struct platform_device *pdev)
>> dev_set_drvdata(&pdev->dev, tu);
>>
>> tu->irq = ret = platform_get_irq(pdev, 0);
>> - if (ret < 0)
>> - return ret;
>> + if (ret < 0) {
>> + dev_err(&pdev->dev, "could not get irq: %d\n",
>> + ret);
>
> Adding the error message needs another patch, strictly speaking...

And if you look at platform_get_irq(), you'll see that it prints an error msg
itself...

[...]

MBR, Sergey