mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Andreatta <thomasandreatta2000@gmail.com>
To: dpenkler@gmail.com
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	linux-staging@lists.linux.dev,
	Thomas Andreatta <thomas.andreatta2000@gmail.com>
Subject: [PATCH 8/8] Staging: gpib: Optimize error handling in agilent_82357a_driver_resume
Date: Thu,  1 May 2025 23:30:37 +0200	[thread overview]
Message-ID: <4f560559491207b85cd1997d9e351e417f048068.1746133676.git.thomas.andreatta2000@gmail.com> (raw)
In-Reply-To: <cover.1746133676.git.thomas.andreatta2000@gmail.com>

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@gmail.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


      parent reply	other threads:[~2025-05-01 21:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-01 21:30 [PATCH 0/8] Staging: gpib: Update return types and error handling for request_system_control Thomas Andreatta
2025-05-01 21:30 ` [PATCH 1/8] Staging: gpib: agilent_82357a: changing return type void in int Thomas Andreatta
2025-05-02  7:16   ` Dan Carpenter
2025-05-02  7:35     ` Thomas Andreatta
2025-05-01 21:30 ` [PATCH 2/8] Staging: gpib: Updated return type `request_system_control` Thomas Andreatta
2025-05-02  8:33   ` kernel test robot
2025-05-02  9:25   ` kernel test robot
2025-05-01 21:30 ` [PATCH 3/8] Staging: gpib: Updated return type for `request_system_control` Thomas Andreatta
2025-05-01 21:30 ` [PATCH 4/8] Staging: gpib: Updated return type `ines_request_system_control` Thomas Andreatta
2025-05-01 21:30 ` [PATCH 5/8] Staging: gpib: Updated return type for `ines_request_system_control` Thomas Andreatta
2025-05-01 21:30 ` [PATCH 6/8] Staging: gpib: Updated return type for `request_system_control` Thomas Andreatta
2025-05-01 21:30 ` [PATCH 7/8] Staging: gpib: `request_system_control` error handling in resume Thomas Andreatta
2025-05-01 21:30 ` Thomas Andreatta [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4f560559491207b85cd1997d9e351e417f048068.1746133676.git.thomas.andreatta2000@gmail.com \
    --to=thomasandreatta2000@gmail.com \
    --cc=dpenkler@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=thomas.andreatta2000@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®