lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20241205133703.885145-1-mordan@ispras.ru>
Date: Thu,  5 Dec 2024 16:37:03 +0300
From: Vitalii Mordan <mordan@...ras.ru>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Vitalii Mordan <mordan@...ras.ru>,
	Uwe Kleine-König <u.kleine-koenig@...libre.com>,
	Magnus Damm <damm@...l.co.jp>,
	Paul Mundt <lethal@...ux-sh.org>,
	Alan Stern <stern@...land.harvard.edu>,
	linux-usb@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Fedor Pchelkin <pchelkin@...ras.ru>,
	Alexey Khoroshilov <khoroshilov@...ras.ru>,
	Vadim Mutilin <mutilin@...ras.ru>,
	stable@...r.kernel.org
Subject: [PATCH] usb: r8a66597-udc: fix call balance for r8a66597->clk handling routines

If the clock r8a66597->clk was not enabled in r8a66597_probe,
r8a66597->clk will contain a non-NULL value leading to the clock being
incorrectly disabled later in r8a66597_remove.

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

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

Fixes: d2e27bdf2870 ("usb: add clock support to r8a66597 gadget driver")
Cc: stable@...r.kernel.org
Signed-off-by: Vitalii Mordan <mordan@...ras.ru>
---
 drivers/usb/gadget/udc/r8a66597-udc.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c
index ff6f846b1d41..8518feb90792 100644
--- a/drivers/usb/gadget/udc/r8a66597-udc.c
+++ b/drivers/usb/gadget/udc/r8a66597-udc.c
@@ -1812,10 +1812,6 @@ static void r8a66597_remove(struct platform_device *pdev)
 	usb_del_gadget_udc(&r8a66597->gadget);
 	del_timer_sync(&r8a66597->timer);
 	r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
-
-	if (r8a66597->pdata->on_chip) {
-		clk_disable_unprepare(r8a66597->clk);
-	}
 }
 
 static void nop_completion(struct usb_ep *ep, struct usb_request *r)
@@ -1876,12 +1872,11 @@ static int r8a66597_probe(struct platform_device *pdev)
 
 	if (r8a66597->pdata->on_chip) {
 		snprintf(clk_name, sizeof(clk_name), "usb%d", pdev->id);
-		r8a66597->clk = devm_clk_get(dev, clk_name);
+		r8a66597->clk = devm_clk_get_enabled(dev, clk_name);
 		if (IS_ERR(r8a66597->clk)) {
-			dev_err(dev, "cannot get clock \"%s\"\n", clk_name);
+			dev_err(dev, "cannot get and enable clock \"%s\"\n", clk_name);
 			return PTR_ERR(r8a66597->clk);
 		}
-		clk_prepare_enable(r8a66597->clk);
 	}
 
 	if (r8a66597->pdata->sudmac) {
@@ -1953,9 +1948,6 @@ static int r8a66597_probe(struct platform_device *pdev)
 err_add_udc:
 	r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
 clean_up2:
-	if (r8a66597->pdata->on_chip)
-		clk_disable_unprepare(r8a66597->clk);
-
 	if (r8a66597->ep0_req)
 		r8a66597_free_request(&r8a66597->ep[0].ep, r8a66597->ep0_req);
 
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ