* [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; 5+ 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] 5+ 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; 5+ 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] 5+ 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
2026-11-17 1:07 ` Xiangwu Lai
0 siblings, 1 reply; 5+ 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] 5+ messages in thread
* Re: [PATCH] usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable()
2026-11-16 9:34 ` Greg Kroah-Hartman
@ 2026-11-17 1:07 ` Xiangwu Lai
2026-11-17 5:26 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Xiangwu Lai @ 2026-11-17 1:07 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Xiangwu Lai, linux-usb, linux-kernel
Hi Greg,
thanks for taking a look.
No, I'm not hitting this on a real system. It was found by code
inspection while auditing error paths in USB host drivers, and I
don't have hardware with this controller.
The affected path does have in-tree users: several arch/sh SoC and
board setups (sh7723/sh7366/sh7264/sh7269 and the ecovec24,
ms7724se, kfr2r09 boards) register this driver with on_chip = 1,
and the clock handling only runs for those. It is old SuperH
platform code, so the practical population is small.
The failure it fixes is the driver's own hardware init failure
handling: when the register access poll times out because the
device does not respond, r8a66597_clock_enable() returns -ENXIO
with the clock still prepared and enabled, and the probe cleanup
only does clk_put(), so nothing disables it for the remaining
uptime. The same helper also runs from the resume path, whose
return value is ignored there as well. Not checking
clk_prepare_enable() separately turns a failed clock enable into
a bogus -ENXIO from the unclocked register poll.
I have not seen this reported anywhere, so it is fair to call it a
robustness fix rather than a fix for an observed failure. If you
would like to keep it, I'm happy to note the "found by code
inspection, not observed on hardware" context in the commit message
and/or drop the Fixes tag so it does not go to stable. If you
consider it too theoretical for the tree, dropping the patch is
fine by me.
Best regards,
Xiangwu Lai
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: r8a66597-hcd: Fix clock leak and unchecked clk_prepare_enable()
2026-11-17 1:07 ` Xiangwu Lai
@ 2026-11-17 5:26 ` Greg Kroah-Hartman
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-17 5:26 UTC (permalink / raw)
To: Xiangwu Lai; +Cc: linux-usb, linux-kernel
On Tue, Nov 17, 2026 at 09:07:54AM +0800, Xiangwu Lai wrote:
> Hi Greg,
>
> thanks for taking a look.
At what? Sorry, there is no context here.
Remember, some of us get 1000+ emails a day...
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-17 5:26 UTC | newest]
Thread overview: 5+ 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
2026-11-17 1:07 ` Xiangwu Lai
2026-11-17 5:26 ` 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®