Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: ehci-hcd: fix call balance of clocks handling routines

If the clocks priv->iclk and priv->fclk were not enabled in ehci_hcd_sh_probe,
they should not be disabled in any path.

Conversely, if they was enabled in ehci_hcd_sh_probe, they must be disabled
in all error paths to ensure proper cleanup.

Found by Linux Verification Center (linuxtesting.org) with Klever.

Fixes: 63c845522263 ("usb: ehci-hcd: Add support for SuperH EHCI.")
Cc: stable@vger.kernel.org # ff30bd6a6618: sh: clk: Fix clk_enable() to return 0 on NULL clk
Signed-off-by: Vitalii Mordan <mordan@ispras.ru>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20241121114700.2100520-1-mordan@ispras.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Vitalii Mordan and committed by
Greg Kroah-Hartman
97264eaa cdd30ebb

+7 -2
+7 -2
drivers/usb/host/ehci-sh.c
··· 119 119 if (IS_ERR(priv->iclk)) 120 120 priv->iclk = NULL; 121 121 122 - clk_enable(priv->fclk); 123 - clk_enable(priv->iclk); 122 + ret = clk_enable(priv->fclk); 123 + if (ret) 124 + goto fail_request_resource; 125 + ret = clk_enable(priv->iclk); 126 + if (ret) 127 + goto fail_iclk; 124 128 125 129 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 126 130 if (ret != 0) { ··· 140 136 141 137 fail_add_hcd: 142 138 clk_disable(priv->iclk); 139 + fail_iclk: 143 140 clk_disable(priv->fclk); 144 141 145 142 fail_request_resource: