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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4f560559491207b85cd1997d9e351e417f048068.1746133676.git.thomas.andreatta2000@gmail.com>
Date: Thu,  1 May 2025 23:30:37 +0200
From: Thomas Andreatta <thomasandreatta2000@...il.com>
To: dpenkler@...il.com
Cc: gregkh@...uxfoundation.org,
	linux-kernel@...r.kernel.org,
	linux-staging@...ts.linux.dev,
	Thomas Andreatta <thomas.andreatta2000@...il.com>
Subject: [PATCH 8/8] Staging: gpib: Optimize error handling in agilent_82357a_driver_resume

Refactor the agilent_82357a_driver_resume function to consistently use
the resume_exit label for all error paths. Initialize retval to 0 at the
beginning of the function and return it at the end, ensuring the mutex is
always properly unlocked regardless of the execution path.

Simplifies error handling and fixes potential mutex lock leaks by
ensuring all code paths go through the same cleanup code.

Signed-off-by: Thomas Andreatta <thomas.andreatta2000@...il.com>
---
 .../staging/gpib/agilent_82357a/agilent_82357a.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
index 4fdf6d42f63e..92bbdd57083f 100644
--- a/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
+++ b/drivers/staging/gpib/agilent_82357a/agilent_82357a.c
@@ -1590,7 +1590,7 @@ static int agilent_82357a_driver_resume(struct usb_interface *interface)
 {
 	struct usb_device *usb_dev = interface_to_usbdev(interface);
 	struct gpib_board *board;
-	int i, retval;
+	int i, retval = 0;
 
 	mutex_lock(&agilent_82357a_hotplug_lock);
 
@@ -1614,23 +1614,19 @@ static int agilent_82357a_driver_resume(struct usb_interface *interface)
 				dev_err(&usb_dev->dev, "failed to resubmit interrupt urb in resume, retval=%i\n",
 					retval);
 				mutex_unlock(&a_priv->interrupt_alloc_lock);
-				mutex_unlock(&agilent_82357a_hotplug_lock);
-				return retval;
+				goto resume_exit;
 			}
 			mutex_unlock(&a_priv->interrupt_alloc_lock);
 		}
 		retval = agilent_82357a_init(board);
-		if (retval < 0) {
-			mutex_unlock(&agilent_82357a_hotplug_lock);
-			return retval;
-		}
+		if (retval < 0)
+			goto resume_exit;
 		// set/unset system controller
 		retval = agilent_82357a_request_system_control(board, board->master);
 		if (retval) {
 			dev_err(&usb_dev->dev, "failed to request system control in resume, retval=%i\n",
 				retval);
-			mutex_unlock(&agilent_82357a_hotplug_lock);
-			return retval;
+			goto resume_exit;
 		}
 		// toggle ifc if master
 		if (board->master) {
@@ -1649,7 +1645,7 @@ static int agilent_82357a_driver_resume(struct usb_interface *interface)
 resume_exit:
 	mutex_unlock(&agilent_82357a_hotplug_lock);
 
-	return 0;
+	return retval;
 }
 
 static struct usb_driver agilent_82357a_bus_driver = {
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ