usb: ehci-spear: fix call balance of sehci clk handling routines
authorVitalii Mordan <mordan@ispras.ru>
Thu, 14 Nov 2024 23:03:10 +0000 (02:03 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 16 Nov 2024 08:04:06 +0000 (09:04 +0100)
If the clock sehci->clk was not enabled in spear_ehci_hcd_drv_probe,
it should not be disabled in any path.

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

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

Fixes: 7675d6ba436f ("USB: EHCI: make ehci-spear a separate driver")
Cc: stable@vger.kernel.org
Signed-off-by: Vitalii Mordan <mordan@ispras.ru>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20241114230310.432213-1-mordan@ispras.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/ehci-spear.c

index 0b1fc2563dd69e583fe83509aa370d3ca8f96570..e96710192d6b026171ba552f91d969c9ddf0bd6c 100644 (file)
@@ -105,7 +105,9 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
        /* registers start at offset 0x0 */
        hcd_to_ehci(hcd)->caps = hcd->regs;
 
-       clk_prepare_enable(sehci->clk);
+       retval = clk_prepare_enable(sehci->clk);
+       if (retval)
+               goto err_put_hcd;
        retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
        if (retval)
                goto err_stop_ehci;
@@ -130,8 +132,7 @@ static void spear_ehci_hcd_drv_remove(struct platform_device *pdev)
 
        usb_remove_hcd(hcd);
 
-       if (sehci->clk)
-               clk_disable_unprepare(sehci->clk);
+       clk_disable_unprepare(sehci->clk);
        usb_put_hcd(hcd);
 }