linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors
@ 2025-11-24  2:22 Haotian Zhang
  2025-11-24  7:43 ` Herve Codina
  2025-11-24 13:15 ` Geert Uytterhoeven
  0 siblings, 2 replies; 4+ messages in thread
From: Haotian Zhang @ 2025-11-24  2:22 UTC (permalink / raw)
  To: herve.codina, gregkh
  Cc: linux-renesas-soc, linux-usb, linux-kernel, Haotian Zhang

devm_pm_runtime_enable() can fail due to memory allocation.
The current code ignores its return value, potentially causing
pm_runtime_resume_and_get() to operate on uninitialized runtime
PM state.

Check the return value of devm_pm_runtime_enable() and return on failure.

Fixes: 3e6e14ffdea4 ("usb: gadget: udc: add Renesas RZ/N1 USBF controller support")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/usb/gadget/udc/renesas_usbf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/renesas_usbf.c b/drivers/usb/gadget/udc/renesas_usbf.c
index 14f4b2cf05a4..4c201574a0af 100644
--- a/drivers/usb/gadget/udc/renesas_usbf.c
+++ b/drivers/usb/gadget/udc/renesas_usbf.c
@@ -3262,7 +3262,9 @@ static int usbf_probe(struct platform_device *pdev)
 	if (IS_ERR(udc->regs))
 		return PTR_ERR(udc->regs);
 
-	devm_pm_runtime_enable(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		return ret;
 	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret < 0)
 		return ret;
-- 
2.50.1.windows.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors
  2025-11-24  2:22 [PATCH] usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors Haotian Zhang
@ 2025-11-24  7:43 ` Herve Codina
  2025-11-24 13:15 ` Geert Uytterhoeven
  1 sibling, 0 replies; 4+ messages in thread
From: Herve Codina @ 2025-11-24  7:43 UTC (permalink / raw)
  To: Haotian Zhang; +Cc: gregkh, linux-renesas-soc, linux-usb, linux-kernel

Hi Haotian,

On Mon, 24 Nov 2025 10:22:15 +0800
Haotian Zhang <vulab@iscas.ac.cn> wrote:

> devm_pm_runtime_enable() can fail due to memory allocation.
> The current code ignores its return value, potentially causing
> pm_runtime_resume_and_get() to operate on uninitialized runtime
> PM state.
> 
> Check the return value of devm_pm_runtime_enable() and return on failure.
> 
> Fixes: 3e6e14ffdea4 ("usb: gadget: udc: add Renesas RZ/N1 USBF controller support")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>

Thanks for the patch.

Acked-by: Herve Codina <herve.codina@bootlin.com>

Best regards,
Hervé

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors
  2025-11-24  2:22 [PATCH] usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors Haotian Zhang
  2025-11-24  7:43 ` Herve Codina
@ 2025-11-24 13:15 ` Geert Uytterhoeven
  2025-11-26 12:47   ` Andy Shevchenko
  1 sibling, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2025-11-24 13:15 UTC (permalink / raw)
  To: Haotian Zhang
  Cc: herve.codina, gregkh, linux-renesas-soc, linux-usb, linux-kernel

Hi Haotian,

On Mon, 24 Nov 2025 at 03:24, Haotian Zhang <vulab@iscas.ac.cn> wrote:
> devm_pm_runtime_enable() can fail due to memory allocation.
> The current code ignores its return value, potentially causing
> pm_runtime_resume_and_get() to operate on uninitialized runtime
> PM state.
>
> Check the return value of devm_pm_runtime_enable() and return on failure.
>
> Fixes: 3e6e14ffdea4 ("usb: gadget: udc: add Renesas RZ/N1 USBF controller support")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>

Thanks for your patch!

> --- a/drivers/usb/gadget/udc/renesas_usbf.c
> +++ b/drivers/usb/gadget/udc/renesas_usbf.c
> @@ -3262,7 +3262,9 @@ static int usbf_probe(struct platform_device *pdev)
>         if (IS_ERR(udc->regs))
>                 return PTR_ERR(udc->regs);
>
> -       devm_pm_runtime_enable(&pdev->dev);
> +       ret = devm_pm_runtime_enable(&pdev->dev);
> +       if (ret)
> +               return ret;

Perhaps insert a blank line here?

>         ret = pm_runtime_resume_and_get(&pdev->dev);
>         if (ret < 0)
>                 return ret;

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors
  2025-11-24 13:15 ` Geert Uytterhoeven
@ 2025-11-26 12:47   ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-11-26 12:47 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Haotian Zhang, herve.codina, gregkh, linux-renesas-soc, linux-usb,
	linux-kernel

On Mon, Nov 24, 2025 at 02:15:14PM +0100, Geert Uytterhoeven wrote:
> On Mon, 24 Nov 2025 at 03:24, Haotian Zhang <vulab@iscas.ac.cn> wrote:

> Thanks for your patch!

...

> > -       devm_pm_runtime_enable(&pdev->dev);
> > +       ret = devm_pm_runtime_enable(&pdev->dev);
> > +       if (ret)
> > +               return ret;
> 
> Perhaps insert a blank line here?
> 
> >         ret = pm_runtime_resume_and_get(&pdev->dev);
> >         if (ret < 0)
> >                 return ret;

FWIW, if not fixed yet, this driver from this line towards the end of
the function leaks the PM runtime reference count.

> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-26 12:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-24  2:22 [PATCH] usb: gadget: renesas_usbf: Handle devm_pm_runtime_enable() errors Haotian Zhang
2025-11-24  7:43 ` Herve Codina
2025-11-24 13:15 ` Geert Uytterhoeven
2025-11-26 12:47   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).