Skip to contentSkip to conversation

Staging: gpib: Update return types and error handling for request_system_control

PATCH In review Thomas Andreatta 3 participants 13 messages May 1, 2025 – May 2, 2025 Staging

lore
Share & tools
lore
#0 lore raw

cover Staging: gpib: Update return types and error handling for request_system_control

This patch series improves error propagation in the gpib driver by changing the return type of request_system_control and related functions from void to int, allowing proper error handling.

The changes follow these steps:
* Fix the FIXME comment in agilent_82357a.c by changing the return type from void to int
* Update the function prototype in gpib_types.h
* Update all implementations of the function across drivers to return int
* Implement proper error checking for the new signatures in the resume function
* Improves the mutex unlocking path process in the resume function

All functions that used to be void and didn't had any intended return code are now returning success (0), and the resume code is refactored to ensure mutex unlocking in all execution paths.

Thomas Andreatta (8):
Staging: gpib: agilent_82357a: changing return type void in int
Staging: gpib: Updated return type request_system_control
Staging: gpib: Updated return type for request_system_control
Staging: gpib: Updated return type ines_request_system_control
Staging: gpib: Updated return type for ines_request_system_control
Staging: gpib: Updated return type for request_system_control
Staging: gpib: request_system_control error handling in resume
Staging: gpib: Optimize error handling in agilent_82357a_driver_resume

 .../gpib/agilent_82350b/agilent_82350b.c      |  3 ++-
 .../gpib/agilent_82357a/agilent_82357a.c      | 27 ++++++++++---------
 drivers/staging/gpib/cb7210/cb7210.c          |  3 ++-
 drivers/staging/gpib/cec/cec_gpib.c           |  3 ++-
 drivers/staging/gpib/hp_82335/hp82335.c       |  3 ++-
 drivers/staging/gpib/hp_82341/hp_82341.c      |  3 ++-
 drivers/staging/gpib/include/gpib_types.h     |  2 +-
 drivers/staging/gpib/ines/ines.h              |  2 +-
 drivers/staging/gpib/ines/ines_gpib.c         |  3 ++-
 .../gpib/lpvo_usb_gpib/lpvo_usb_gpib.c        |  3 ++-
 drivers/staging/gpib/ni_usb/ni_usb_gpib.c     |  8 +++---
 drivers/staging/gpib/pc2/pc2_gpib.c           |  3 ++-
 drivers/staging/gpib/tnt4882/tnt4882_gpib.c   |  3 ++-
 13 files changed, 38 insertions(+), 28 deletions(-)
Signature · 2 lines
Best regards,
Thomas
#1 lore raw

PATCH 1/8 Staging: gpib: agilent_82357a: changing return type void in int

Patched FIXME request moving the return type from a void to int.

---
 drivers/staging/gpib/agilent_82357a/agilent_82357a.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/gpib/agilent_82357a/agilent_82357a.c +3 -4
index da229965d98e..ce2d3850ba31 100644
@@ -754,8 +754,7 @@ static int agilent_82357a_go_to_standby(struct gpib_board *board)
 	return 0;
 }
 
-//FIXME should change prototype to return int
-static void agilent_82357a_request_system_control(struct gpib_board *board,
+static int agilent_82357a_request_system_control(struct gpib_board *board,
 						  int request_control)
 {
 	struct agilent_82357a_priv *a_priv = board->private_data;
@@ -765,7 +764,7 @@ static void agilent_82357a_request_system_control(struct gpib_board *board,
 	int i = 0;
 
 	if (!a_priv->bus_interface)
-		return; // -ENODEV;
+		return -ENODEV;
 
 	usb_dev = interface_to_usbdev(a_priv->bus_interface);
 	/* 82357B needs bit to be set in 9914 AUXCR register */
@@ -785,7 +784,7 @@ static void agilent_82357a_request_system_control(struct gpib_board *board,
 	retval = agilent_82357a_write_registers(a_priv, writes, i);
 	if (retval)
 		dev_err(&usb_dev->dev, "write_registers() returned error\n");
-	return;// retval;
+	return retval;
 }
 
 static void agilent_82357a_interface_clear(struct gpib_board *board, int assert)
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/8] Staging: gpib: agilent_82357a: changing return type void in int

This patch will break the build. Also you need to work against linux-next. Dave Penkler already did this work.

regards,
dan carpenter

#3 lore raw

Re: [PATCH 1/8] Staging: gpib: agilent_82357a: changing return type void in int

My bad.
Thanks for the nudge!

Best,
Thomas

#4 lore raw

PATCH 2/8 Staging: gpib: Updated return type `request_system_control`

In reply to Thomas Andreatta

Update request_system_control type from void to int.

---
 drivers/staging/gpib/include/gpib_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gpib/include/gpib_types.h +1 -1
index 2d9b9be683f8..4c28f35606ef 100644
@@ -93,7 +93,7 @@ struct gpib_interface_struct {
 	 */
 	int (*go_to_standby)(struct gpib_board *board);
 	/* request/release control of the IFC and REN lines (system controller) */
-	void (*request_system_control)(struct gpib_board *board, int request_control);
+	int (*request_system_control)(struct gpib_board *board, int request_control);
 	/* Asserts or de-asserts 'interface clear' (IFC) depending on
 	 * boolean value of 'assert'
 	 */
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 2/8] Staging: gpib: Updated return type `request_system_control`

kernel test robot noticed the following build errors:

Hi Thomas,

kernel test robot noticed the following build errors:

[auto build test ERROR on staging/staging-linus]
[also build test ERROR on linus/master v6.15-rc4]
[cannot apply to staging/staging-testing staging/staging-next next-20250501] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Andreatta/Staging-gpib-agilent_82357a-changing-return-type-void-in-int/20250502-053306
base:   staging/staging-linus
patch link:    https://lore.kernel.org/r/28632a0bf5275553e929e8699830377069e921fa.1746133676.git.thomas.andreatta2000%40gmail.com
patch subject: [PATCH 2/8] Staging: gpib: Updated return type `request_system_control`
config: arm64-randconfig-003-20250502 (https://download.01.org/0day-ci/archive/20250502/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250502/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/staging/gpib/eastwood/fluke_gpib.c:710:28: error: initialization of 'int (*)(struct gpib_board *, int)' from incompatible pointer type 'void (*)(struct gpib_board *, int)' [-Werror=incompatible-pointer-types]

.request_system_control = fluke_request_system_control,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/gpib/eastwood/fluke_gpib.c:710:28: note: (near initialization for 'fluke_unaccel_interface.request_system_control') drivers/staging/gpib/eastwood/fluke_gpib.c:745:28: error: initialization of 'int (*)(struct gpib_board *, int)' from incompatible pointer type 'void (*)(struct gpib_board *, int)' [-Werror=incompatible-pointer-types]
.request_system_control = fluke_request_system_control,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/gpib/eastwood/fluke_gpib.c:745:28: note: (near initialization for 'fluke_hybrid_interface.request_system_control') drivers/staging/gpib/eastwood/fluke_gpib.c:772:28: error: initialization of 'int (*)(struct gpib_board *, int)' from incompatible pointer type 'void (*)(struct gpib_board *, int)' [-Werror=incompatible-pointer-types]
.request_system_control = fluke_request_system_control,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/gpib/eastwood/fluke_gpib.c:772:28: note: (near initialization for 'fluke_interface.request_system_control')
cc1: some warnings being treated as errors
--

>> drivers/staging/gpib/fmh_gpib/fmh_gpib.c:1023:28: error: initialization of 'int (*)(struct gpib_board *, int)' from incompatible pointer type 'void (*)(struct gpib_board *, int)' [-Werror=incompatible-pointer-types]

.request_system_control = fmh_gpib_request_system_control,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/gpib/fmh_gpib/fmh_gpib.c:1023:28: note: (near initialization for 'fmh_gpib_unaccel_interface.request_system_control') drivers/staging/gpib/fmh_gpib/fmh_gpib.c:1051:28: error: initialization of 'int (*)(struct gpib_board *, int)' from incompatible pointer type 'void (*)(struct gpib_board *, int)' [-Werror=incompatible-pointer-types]
.request_system_control = fmh_gpib_request_system_control,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/gpib/fmh_gpib/fmh_gpib.c:1051:28: note: (near initialization for 'fmh_gpib_interface.request_system_control')
drivers/staging/gpib/fmh_gpib/fmh_gpib.c:1079:28: error: initialization of 'int (*)(struct gpib_board *, int)' from incompatible pointer type 'void (*)(struct gpib_board *, int)' [-Werror=incompatible-pointer-types]
.request_system_control = fmh_gpib_request_system_control,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/gpib/fmh_gpib/fmh_gpib.c:1079:28: note: (near initialization for 'fmh_gpib_pci_interface.request_system_control')
drivers/staging/gpib/fmh_gpib/fmh_gpib.c:1107:28: error: initialization of 'int (*)(struct gpib_board *, int)' from incompatible pointer type 'void (*)(struct gpib_board *, int)' [-Werror=incompatible-pointer-types]
.request_system_control = fmh_gpib_request_system_control,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/gpib/fmh_gpib/fmh_gpib.c:1107:28: note: (near initialization for 'fmh_gpib_pci_unaccel_interface.request_system_control')
cc1: some warnings being treated as errors

vim +710 drivers/staging/gpib/eastwood/fluke_gpib.c

55936779f49612 Dave Penkler 2024-09-18  700  
95cfc75234534b Dave Penkler 2025-01-11  701  static gpib_interface_t fluke_unaccel_interface = {
95cfc75234534b Dave Penkler 2025-01-11  702  	.name = "fluke_unaccel",
95cfc75234534b Dave Penkler 2025-01-11  703  	.attach = fluke_attach_holdoff_all,
95cfc75234534b Dave Penkler 2025-01-11  704  	.detach = fluke_detach,
95cfc75234534b Dave Penkler 2025-01-11  705  	.read = fluke_read,
95cfc75234534b Dave Penkler 2025-01-11  706  	.write = fluke_write,
95cfc75234534b Dave Penkler 2025-01-11  707  	.command = fluke_command,
95cfc75234534b Dave Penkler 2025-01-11  708  	.take_control = fluke_take_control,
95cfc75234534b Dave Penkler 2025-01-11  709  	.go_to_standby = fluke_go_to_standby,
95cfc75234534b Dave Penkler 2025-01-11 @710  	.request_system_control = fluke_request_system_control,
95cfc75234534b Dave Penkler 2025-01-11  711  	.interface_clear = fluke_interface_clear,
95cfc75234534b Dave Penkler 2025-01-11  712  	.remote_enable = fluke_remote_enable,
95cfc75234534b Dave Penkler 2025-01-11  713  	.enable_eos = fluke_enable_eos,
95cfc75234534b Dave Penkler 2025-01-11  714  	.disable_eos = fluke_disable_eos,
95cfc75234534b Dave Penkler 2025-01-11  715  	.parallel_poll = fluke_parallel_poll,
95cfc75234534b Dave Penkler 2025-01-11  716  	.parallel_poll_configure = fluke_parallel_poll_configure,
95cfc75234534b Dave Penkler 2025-01-11  717  	.parallel_poll_response = fluke_parallel_poll_response,
95cfc75234534b Dave Penkler 2025-01-11  718  	.line_status = fluke_line_status,
95cfc75234534b Dave Penkler 2025-01-11  719  	.update_status = fluke_update_status,
95cfc75234534b Dave Penkler 2025-01-11  720  	.primary_address = fluke_primary_address,
95cfc75234534b Dave Penkler 2025-01-11  721  	.secondary_address = fluke_secondary_address,
95cfc75234534b Dave Penkler 2025-01-11  722  	.serial_poll_response = fluke_serial_poll_response,
95cfc75234534b Dave Penkler 2025-01-11  723  	.serial_poll_status = fluke_serial_poll_status,
95cfc75234534b Dave Penkler 2025-01-11  724  	.t1_delay = fluke_t1_delay,
95cfc75234534b Dave Penkler 2025-01-11  725  	.return_to_local = fluke_return_to_local,
55936779f49612 Dave Penkler 2024-09-18  726  };

55936779f49612 Dave Penkler 2024-09-18 727

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw

Re: [PATCH 2/8] Staging: gpib: Updated return type `request_system_control`

In reply to Thomas Andreatta
kernel test robot noticed the following build errors:

Hi Thomas,

kernel test robot noticed the following build errors:

[auto build test ERROR on staging/staging-linus]
[also build test ERROR on linus/master v6.15-rc4]
[cannot apply to staging/staging-testing staging/staging-next next-20250501] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Andreatta/Staging-gpib-agilent_82357a-changing-return-type-void-in-int/20250502-053306
base:   staging/staging-linus
patch link:    https://lore.kernel.org/r/28632a0bf5275553e929e8699830377069e921fa.1746133676.git.thomas.andreatta2000%40gmail.com
patch subject: [PATCH 2/8] Staging: gpib: Updated return type `request_system_control`
config: arm-randconfig-004-20250502 (https://download.01.org/0day-ci/archive/20250502/[email protected]/config)
compiler: clang version 20.1.2 (https://github.com/llvm/llvm-project 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250502/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/staging/gpib/eastwood/fluke_gpib.c:710:28: error: incompatible function pointer types initializing 'int (*)(struct gpib_board *, int)' with an expression of type 'void (struct gpib_board *, int)' [-Wincompatible-function-pointer-types]

710 | .request_system_control = fluke_request_system_control,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/gpib/eastwood/fluke_gpib.c:745:28: error: incompatible function pointer types initializing 'int (*)(struct gpib_board *, int)' with an expression of type 'void (struct gpib_board *, int)' [-Wincompatible-function-pointer-types]
745 | .request_system_control = fluke_request_system_control,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/staging/gpib/eastwood/fluke_gpib.c:772:28: error: incompatible function pointer types initializing 'int (*)(struct gpib_board *, int)' with an expression of type 'void (struct gpib_board *, int)' [-Wincompatible-function-pointer-types]
772 | .request_system_control = fluke_request_system_control,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 errors generated.

vim +710 drivers/staging/gpib/eastwood/fluke_gpib.c

55936779f49612 Dave Penkler 2024-09-18  700  
95cfc75234534b Dave Penkler 2025-01-11  701  static gpib_interface_t fluke_unaccel_interface = {
95cfc75234534b Dave Penkler 2025-01-11  702  	.name = "fluke_unaccel",
95cfc75234534b Dave Penkler 2025-01-11  703  	.attach = fluke_attach_holdoff_all,
95cfc75234534b Dave Penkler 2025-01-11  704  	.detach = fluke_detach,
95cfc75234534b Dave Penkler 2025-01-11  705  	.read = fluke_read,
95cfc75234534b Dave Penkler 2025-01-11  706  	.write = fluke_write,
95cfc75234534b Dave Penkler 2025-01-11  707  	.command = fluke_command,
95cfc75234534b Dave Penkler 2025-01-11  708  	.take_control = fluke_take_control,
95cfc75234534b Dave Penkler 2025-01-11  709  	.go_to_standby = fluke_go_to_standby,
95cfc75234534b Dave Penkler 2025-01-11 @710  	.request_system_control = fluke_request_system_control,
95cfc75234534b Dave Penkler 2025-01-11  711  	.interface_clear = fluke_interface_clear,
95cfc75234534b Dave Penkler 2025-01-11  712  	.remote_enable = fluke_remote_enable,
95cfc75234534b Dave Penkler 2025-01-11  713  	.enable_eos = fluke_enable_eos,
95cfc75234534b Dave Penkler 2025-01-11  714  	.disable_eos = fluke_disable_eos,
95cfc75234534b Dave Penkler 2025-01-11  715  	.parallel_poll = fluke_parallel_poll,
95cfc75234534b Dave Penkler 2025-01-11  716  	.parallel_poll_configure = fluke_parallel_poll_configure,
95cfc75234534b Dave Penkler 2025-01-11  717  	.parallel_poll_response = fluke_parallel_poll_response,
95cfc75234534b Dave Penkler 2025-01-11  718  	.line_status = fluke_line_status,
95cfc75234534b Dave Penkler 2025-01-11  719  	.update_status = fluke_update_status,
95cfc75234534b Dave Penkler 2025-01-11  720  	.primary_address = fluke_primary_address,
95cfc75234534b Dave Penkler 2025-01-11  721  	.secondary_address = fluke_secondary_address,
95cfc75234534b Dave Penkler 2025-01-11  722  	.serial_poll_response = fluke_serial_poll_response,
95cfc75234534b Dave Penkler 2025-01-11  723  	.serial_poll_status = fluke_serial_poll_status,
95cfc75234534b Dave Penkler 2025-01-11  724  	.t1_delay = fluke_t1_delay,
95cfc75234534b Dave Penkler 2025-01-11  725  	.return_to_local = fluke_return_to_local,
55936779f49612 Dave Penkler 2024-09-18  726  };

55936779f49612 Dave Penkler 2024-09-18 727

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

PATCH 3/8 Staging: gpib: Updated return type for `request_system_control`

In reply to Thomas Andreatta

Updated the functions used by request_system_control to return int. Currently there's no possible return errors in the functions due to them being former void function, for this reason they all return success (0).

---
 drivers/staging/gpib/agilent_82350b/agilent_82350b.c | 3 ++-
 drivers/staging/gpib/cb7210/cb7210.c                 | 3 ++-
 drivers/staging/gpib/cec/cec_gpib.c                  | 3 ++-
 drivers/staging/gpib/hp_82335/hp82335.c              | 3 ++-
 drivers/staging/gpib/hp_82341/hp_82341.c             | 3 ++-
 drivers/staging/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c   | 3 ++-
 drivers/staging/gpib/pc2/pc2_gpib.c                  | 3 ++-
 drivers/staging/gpib/tnt4882/tnt4882_gpib.c          | 3 ++-
 8 files changed, 16 insertions(+), 8 deletions(-)
drivers/staging/gpib/agilent_82350b/agilent_82350b.c +2 -1
index 445b9380ff98..ae60bc674a85 100644
@@ -339,7 +339,7 @@ static int agilent_82350b_go_to_standby(struct gpib_board *board)
 	return tms9914_go_to_standby(board, &priv->tms9914_priv);
 }
 
-static void agilent_82350b_request_system_control(struct gpib_board *board,
+static int agilent_82350b_request_system_control(struct gpib_board *board,
 						  int request_control)
 
 {
@@ -356,6 +356,7 @@ static void agilent_82350b_request_system_control(struct gpib_board *board,
 	}
 	writeb(a_priv->card_mode_bits, a_priv->gpib_base + CARD_MODE_REG);
 	tms9914_request_system_control(board, &a_priv->tms9914_priv, request_control);
+	return 0;
 }
 
 static void agilent_82350b_interface_clear(struct gpib_board *board, int assert)
drivers/staging/gpib/cb7210/cb7210.c +2 -1
index 6b22a33a8c4f..367b70fbb52c 100644
@@ -578,7 +578,7 @@ static int cb7210_go_to_standby(struct gpib_board *board)
 	return nec7210_go_to_standby(board, &priv->nec7210_priv);
 }
 
-static void cb7210_request_system_control(struct gpib_board *board, int request_control)
+static int cb7210_request_system_control(struct gpib_board *board, int request_control)
 {
 	struct cb7210_priv *priv = board->private_data;
 	struct nec7210_priv *nec_priv = &priv->nec7210_priv;
@@ -590,6 +590,7 @@ static void cb7210_request_system_control(struct gpib_board *board, int request_
 
 	cb7210_write_byte(priv, priv->hs_mode_bits, HS_MODE);
 	nec7210_request_system_control(board, nec_priv, request_control);
+	return 0;
 }
 
 static void cb7210_interface_clear(struct gpib_board *board, int assert)
drivers/staging/gpib/cec/cec_gpib.c +2 -1
index a822fa428cd0..ae05f5205b2f 100644
@@ -83,11 +83,12 @@ static int cec_go_to_standby(struct gpib_board *board)
 	return nec7210_go_to_standby(board, &priv->nec7210_priv);
 }
 
-static void cec_request_system_control(struct gpib_board *board, int request_control)
+static int cec_request_system_control(struct gpib_board *board, int request_control)
 {
 	struct cec_priv *priv = board->private_data;
 
 	nec7210_request_system_control(board, &priv->nec7210_priv, request_control);
+	return 0;
 }
 
 static void cec_interface_clear(struct gpib_board *board, int assert)
drivers/staging/gpib/hp_82335/hp82335.c +2 -1
index fd23b1cb80f9..7a47d61cdb2a 100644
@@ -67,11 +67,12 @@ static int hp82335_go_to_standby(struct gpib_board *board)
 	return tms9914_go_to_standby(board, &priv->tms9914_priv);
 }
 
-static void hp82335_request_system_control(struct gpib_board *board, int request_control)
+static int hp82335_request_system_control(struct gpib_board *board, int request_control)
 {
 	struct hp82335_priv *priv = board->private_data;
 
 	tms9914_request_system_control(board, &priv->tms9914_priv, request_control);
+	return 0;
 }
 
 static void hp82335_interface_clear(struct gpib_board *board, int assert)
drivers/staging/gpib/hp_82341/hp_82341.c +2 -1
index f52e673dc869..fad5cca5238a 100644
@@ -293,7 +293,7 @@ static int hp_82341_go_to_standby(struct gpib_board *board)
 	return tms9914_go_to_standby(board, &priv->tms9914_priv);
 }
 
-static void hp_82341_request_system_control(struct gpib_board *board, int request_control)
+static int hp_82341_request_system_control(struct gpib_board *board, int request_control)
 {
 	struct hp_82341_priv *priv = board->private_data;
 
@@ -303,6 +303,7 @@ static void hp_82341_request_system_control(struct gpib_board *board, int reques
 		priv->mode_control_bits &= ~SYSTEM_CONTROLLER_BIT;
 	outb(priv->mode_control_bits, priv->iobase[0] + MODE_CONTROL_STATUS_REG);
 	tms9914_request_system_control(board, &priv->tms9914_priv, request_control);
+	return 0;
 }
 
 static void hp_82341_interface_clear(struct gpib_board *board, int assert)
drivers/staging/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c +2 -1
index faf96e9cc4a1..233dcf40be39 100644
@@ -909,7 +909,7 @@ static void usb_gpib_remote_enable(struct gpib_board *board, int enable)
 
 /* request_system_control */
 
-static void usb_gpib_request_system_control(struct gpib_board *board,
+static int usb_gpib_request_system_control(struct gpib_board *board,
 					    int request_control)
 {
 	if (request_control)
@@ -918,6 +918,7 @@ static void usb_gpib_request_system_control(struct gpib_board *board,
 		clear_bit(CIC_NUM, &board->status);
 
 	DIA_LOG(1, "done with %d -> %lx\n", request_control, board->status);
+	return 0;
 }
 
 /* take_control */
drivers/staging/gpib/pc2/pc2_gpib.c +2 -1
index 96d3c09f2273..324d323b4240 100644
@@ -127,11 +127,12 @@ static int pc2_go_to_standby(struct gpib_board *board)
 	return nec7210_go_to_standby(board, &priv->nec7210_priv);
 }
 
-static void pc2_request_system_control(struct gpib_board *board, int request_control)
+static int pc2_request_system_control(struct gpib_board *board, int request_control)
 {
 	struct pc2_priv *priv = board->private_data;
 
 	nec7210_request_system_control(board, &priv->nec7210_priv, request_control);
+	return 0;
 }
 
 static void pc2_interface_clear(struct gpib_board *board, int assert)
drivers/staging/gpib/tnt4882/tnt4882_gpib.c +2 -1
index c35b084b6fd0..62950518fe49 100644
@@ -642,7 +642,7 @@ static int tnt4882_go_to_standby(struct gpib_board *board)
 	return nec7210_go_to_standby(board, &priv->nec7210_priv);
 }
 
-static void tnt4882_request_system_control(struct gpib_board *board, int request_control)
+static int tnt4882_request_system_control(struct gpib_board *board, int request_control)
 {
 	struct tnt4882_priv *priv = board->private_data;
 
@@ -655,6 +655,7 @@ static void tnt4882_request_system_control(struct gpib_board *board, int request
 		tnt_writeb(priv, CLRSC, CMDR);
 		udelay(1);
 	}
+	return 0;
 }
 
 static void tnt4882_interface_clear(struct gpib_board *board, int assert)
Signature · 1 line
2.34.1
#8 lore raw

PATCH 4/8 Staging: gpib: Updated return type `ines_request_system_control`

In reply to Thomas Andreatta

Update ines_request_system_control type from void to int.

---
 drivers/staging/gpib/ines/ines.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gpib/ines/ines.h +1 -1
index ff27f055a0ff..a82b9cd93129 100644
@@ -46,7 +46,7 @@ int ines_accel_write(struct gpib_board *board, uint8_t *buffer, size_t length,
 int ines_command(struct gpib_board *board, uint8_t *buffer, size_t length, size_t *bytes_written);
 int ines_take_control(struct gpib_board *board, int synchronous);
 int ines_go_to_standby(struct gpib_board *board);
-void ines_request_system_control(struct gpib_board *board, int request_control);
+int ines_request_system_control(struct gpib_board *board, int request_control);
 void ines_interface_clear(struct gpib_board *board, int assert);
 void ines_remote_enable(struct gpib_board *board, int enable);
 int ines_enable_eos(struct gpib_board *board, uint8_t eos_byte, int compare_8_bits);
Signature · 1 line
2.34.1
#9 lore raw

PATCH 5/8 Staging: gpib: Updated return type for `ines_request_system_control`

In reply to Thomas Andreatta

Updated the functions used by ines_request_system_control to return int. Currently there's no possible return errors in the functions due to them being former void function, for this reason they all return success (0).

---
 drivers/staging/gpib/ines/ines_gpib.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/gpib/ines/ines_gpib.c +2 -1
index d93eb05dab90..2ca1b8659ab4 100644
@@ -441,11 +441,12 @@ int ines_go_to_standby(struct gpib_board *board)
 	return nec7210_go_to_standby(board, &priv->nec7210_priv);
 }
 
-void ines_request_system_control(struct gpib_board *board, int request_control)
+int ines_request_system_control(struct gpib_board *board, int request_control)
 {
 	struct ines_priv *priv = board->private_data;
 
 	nec7210_request_system_control(board, &priv->nec7210_priv, request_control);
+	return 0;
 }
 
 void ines_interface_clear(struct gpib_board *board, int assert)
Signature · 1 line
2.34.1
#10 lore raw

PATCH 6/8 Staging: gpib: Updated return type for `request_system_control`

In reply to Thomas Andreatta

Function ni_usb_request_system_control used by request_system_control now returns int. Reinstated return values by removing comments from previously commented-out return statements.

---
 drivers/staging/gpib/ni_usb/ni_usb_gpib.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/gpib/ni_usb/ni_usb_gpib.c +4 -4
index 9f1b9927f025..a41e4f472d89 100644
@@ -1049,7 +1049,7 @@ static int ni_usb_go_to_standby(struct gpib_board *board)
 	return 0;
 }
 
-static void ni_usb_request_system_control(struct gpib_board *board, int request_control)
+static int ni_usb_request_system_control(struct gpib_board *board, int request_control)
 {
 	int retval;
 	struct ni_usb_priv *ni_priv = board->private_data;
@@ -1059,7 +1059,7 @@ static void ni_usb_request_system_control(struct gpib_board *board, int request_
 	unsigned int ibsta;
 
 	if (!ni_priv->bus_interface)
-		return; // -ENODEV;
+		return -ENODEV;
 	usb_dev = interface_to_usbdev(ni_priv->bus_interface);
 	if (request_control) {
 		writes[i].device = NIUSB_SUBDEV_TNT4882;
@@ -1091,12 +1091,12 @@ static void ni_usb_request_system_control(struct gpib_board *board, int request_
 	retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta);
 	if (retval < 0) {
 		dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval);
-		return; // retval;
+		return retval;
 	}
 	if (!request_control)
 		ni_priv->ren_state = 0;
 	ni_usb_soft_update_status(board, ibsta, 0);
-	return; // 0;
+	return 0;
 }
 
 //FIXME maybe the interface should have a "pulse interface clear" function that can return an error?
Signature · 1 line
2.34.1
#11 lore raw

PATCH 7/8 Staging: gpib: `request_system_control` error handling in resume

In reply to Thomas Andreatta

Function agilent_82357a_driver_resume now handles the return value of agilent_82357a_request_system_control unlocking and returning error in case of failure.

---
 drivers/staging/gpib/agilent_82357a/agilent_82357a.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/staging/gpib/agilent_82357a/agilent_82357a.c +7 -1
index ce2d3850ba31..4fdf6d42f63e 100644
@@ -1625,7 +1625,13 @@ static int agilent_82357a_driver_resume(struct usb_interface *interface)
 			return retval;
 		}
 		// set/unset system controller
-		agilent_82357a_request_system_control(board, board->master);
+		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;
+		}
 		// toggle ifc if master
 		if (board->master) {
 			agilent_82357a_interface_clear(board, 1);
Signature · 1 line
2.34.1
#12 lore raw

PATCH 8/8 Staging: gpib: Optimize error handling in agilent_82357a_driver_resume

In reply to Thomas Andreatta

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.

---
 .../staging/gpib/agilent_82357a/agilent_82357a.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/staging/gpib/agilent_82357a/agilent_82357a.c +6 -10
index 4fdf6d42f63e..92bbdd57083f 100644
@@ -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 = {
Signature · 1 line
2.34.1