[PATCH] usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable()

From: Xiangwu Lai

Date: Mon Nov 02 2026 - 05:10:15 EST


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@xxxxxxxxxxxxxxxxxxxx>
---
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);