Linux USB
 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-02 10:11 ` sashiko-bot
  0 siblings, 1 reply; 2+ 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 related	[flat|nested] 2+ 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-02 10:11 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-02 10:11 UTC (permalink / raw)
  To: Xiangwu Lai; +Cc: linux-usb

> 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>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261102100455.600-1-laixiangwu@cmss.chinamobile.com?part=1


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

end of thread, other threads:[~2026-11-02 10:11 UTC | newest]

Thread overview: 2+ 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-02 10:11 ` sashiko-bot

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