diff mbox series

usb: aspeed-vhub: fix call balance of vhub->clk handling routines

Message ID 20241127093547.3000267-1-mordan@ispras.ru (mailing list archive)
State New
Headers show
Series usb: aspeed-vhub: fix call balance of vhub->clk handling routines | expand

Commit Message

Vitalii Mordan Nov. 27, 2024, 9:35 a.m. UTC
If the clock vhub->clk was not enabled in ast_vhub_probe,
vhub->clk will contain a non-NULL value leading to the clock being
incorrectly disabled later in ast_vhub_remove().

Use the devm_clk_get_enabled helper function to ensure proper call
balance for vhub->clk.

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

Fixes: 7ecca2a4080c ("usb/gadget: Add driver for Aspeed SoC virtual hub")
Cc: stable@vger.kernel.org
Signed-off-by: Vitalii Mordan <mordan@ispras.ru>
---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/usb/gadget/udc/aspeed-vhub/core.c b/drivers/usb/gadget/udc/aspeed-vhub/core.c
index f60a019bb173..7566594fc447 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/core.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/core.c
@@ -277,9 +277,6 @@  static void ast_vhub_remove(struct platform_device *pdev)
 	       VHUB_CTRL_PHY_RESET_DIS,
 	       vhub->regs + AST_VHUB_CTRL);
 
-	if (vhub->clk)
-		clk_disable_unprepare(vhub->clk);
-
 	spin_unlock_irqrestore(&vhub->lock, flags);
 
 	if (vhub->ep0_bufs)
@@ -337,14 +334,10 @@  static int ast_vhub_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, vhub);
 
-	vhub->clk = devm_clk_get(&pdev->dev, NULL);
+	vhub->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(vhub->clk)) {
 		rc = PTR_ERR(vhub->clk);
-		goto err;
-	}
-	rc = clk_prepare_enable(vhub->clk);
-	if (rc) {
-		dev_err(&pdev->dev, "Error couldn't enable clock (%d)\n", rc);
+		dev_err(&pdev->dev, "Error couldn't get and enable clock (%d)\n", rc);
 		goto err;
 	}