mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable()
@ 2026-11-02 10:04 Xiangwu Lai
  2026-11-16  3:10 ` Xiangwu Lai
  0 siblings, 1 reply; 3+ messages in thread
From: Xiangwu Lai @ 2026-11-02 10:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Xiangwu Lai

On on-chip configurations r8a66597_clock_enable() enables the clock
with clk_prepare_enable() but ignores its return value, and if the
subsequent register access times out the function returns -ENXIO
without disabling the clock again. The caller r8a66597_probe() then
only does a clk_put(), so the clock is left prepared and enabled.

Check the return value of clk_prepare_enable() and disable the clock
on the error path.

Fixes: 9b547a882e9f ("usb: r8a66597-hcd: Convert to clk_prepare/unprepare")
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
 drivers/usb/host/r8a66597-hcd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 0a26489a4..e3325df05 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -79,14 +79,18 @@ static int r8a66597_clock_enable(struct r8a66597 *r8a66597)
 {
 	u16 tmp;
 	int i = 0;
+	int ret;
 
 	if (r8a66597->pdata->on_chip) {
-		clk_prepare_enable(r8a66597->clk);
+		ret = clk_prepare_enable(r8a66597->clk);
+		if (ret)
+			return ret;
 		do {
 			r8a66597_write(r8a66597, SCKE, SYSCFG0);
 			tmp = r8a66597_read(r8a66597, SYSCFG0);
 			if (i++ > 1000) {
 				printk(KERN_ERR "r8a66597: reg access fail.\n");
+				clk_disable_unprepare(r8a66597->clk);
 				return -ENXIO;
 			}
 		} while ((tmp & SCKE) != SCKE);



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

* Re: [PATCH] usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable()
  2026-11-02 10:04 [PATCH] usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable() Xiangwu Lai
@ 2026-11-16  3:10 ` Xiangwu Lai
  2026-11-16  9:34   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Xiangwu Lai @ 2026-11-16  3:10 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Xiangwu Lai, linux-usb, linux-kernel

Hi,

gentle ping for:

  usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable()
  https://lore.kernel.org/all/20261102100455.600-1-laixiangwu@cmss.chinamobile.com/

On on-chip configurations r8a66597_clock_enable() ignores the return
value of clk_prepare_enable(), and if the subsequent register access
times out the function returns -ENXIO without disabling the clock
again.  The patch checks the return value and disables the clock on
the error path.

Is there anything blocking this patch, or does it just need more
time?

Best regards,
Xiangwu Lai



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

* Re: [PATCH] usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable()
  2026-11-16  3:10 ` Xiangwu Lai
@ 2026-11-16  9:34   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-16  9:34 UTC (permalink / raw)
  To: Xiangwu Lai; +Cc: linux-usb, linux-kernel

On Mon, Nov 16, 2026 at 11:10:43AM +0800, Xiangwu Lai wrote:
> Hi,
> 
> gentle ping for:
> 
>   usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable()
>   https://lore.kernel.org/all/20261102100455.600-1-laixiangwu@cmss.chinamobile.com/
> 
> On on-chip configurations r8a66597_clock_enable() ignores the return
> value of clk_prepare_enable(), and if the subsequent register access
> times out the function returns -ENXIO without disabling the clock
> again.  The patch checks the return value and disables the clock on
> the error path.

And are you hitting this in a real system, or is this just a theoretical
issue?

thanks,

greg k-h

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

end of thread, other threads:[~2026-11-16  9:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 10:04 [PATCH] usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable() Xiangwu Lai
2026-11-16  3:10 ` Xiangwu Lai
2026-11-16  9:34   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®