Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: gpib: change return type of t1_delay function to report errors

The current code returns "unsigned int" and it doesn't handle errors
correctly if it happens during ioctl call for t1 delay configuration.

The ni_usb_t1_delay(), from NI, is the only function returning -1
at this point. The caller, t1_delay_ioctl(), doesn't check for errors
and sets board->t1_nano_sec to -1 and returns success.
The board->t1_nano_sec value is also used in ni_usb_setup_t1_delay()
besides the ioctl call and a value of -1 is treated as being above 1100ns.
It may or may not have a noticeable effect, but it's obviously not right
considering the content of ni_usb_setup_t1_delay().

Typical delays are in the 200-2000 range, but definitely not more
than INT_MAX so we can fix this code by changing the return type to int
and adding a check for errors. While we're at it, lets change the error
code in ni_usb_t1_delay() from -1 and instead propagate the error from
ni_usb_write_registers().

Fixes: 4e127de14fa7 ("staging: gpib: Add National Instruments USB GPIB driver")
Signed-off-by: Rodrigo Gobbi <rodrigo.gobbi.7@gmail.com>
Link: https://lore.kernel.org/r/20250225014811.77995-1-rodrigo.gobbi.7@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rodrigo Gobbi and committed by
Greg Kroah-Hartman
ed375186 97d83d29

+25 -23
+1 -2
drivers/staging/gpib/agilent_82350b/agilent_82350b.c
··· 455 455 return tms9914_line_status(board, &priv->tms9914_priv); 456 456 } 457 457 458 - static unsigned int agilent_82350b_t1_delay(struct gpib_board *board, 459 - unsigned int nanosec) 458 + static int agilent_82350b_t1_delay(struct gpib_board *board, unsigned int nanosec) 460 459 { 461 460 struct agilent_82350b_priv *a_priv = board->private_data; 462 461 static const int nanosec_per_clock = 30;
+1 -1
drivers/staging/gpib/agilent_82357a/agilent_82357a.c
··· 1071 1071 return bits; 1072 1072 } 1073 1073 1074 - static unsigned int agilent_82357a_t1_delay(struct gpib_board *board, unsigned int nanosec) 1074 + static int agilent_82357a_t1_delay(struct gpib_board *board, unsigned int nanosec) 1075 1075 { 1076 1076 struct agilent_82357a_priv *a_priv = board->private_data; 1077 1077 struct usb_device *usb_dev;
+1 -1
drivers/staging/gpib/cb7210/cb7210.c
··· 408 408 return status; 409 409 } 410 410 411 - static unsigned int cb7210_t1_delay(struct gpib_board *board, unsigned int nano_sec) 411 + static int cb7210_t1_delay(struct gpib_board *board, unsigned int nano_sec) 412 412 { 413 413 struct cb7210_priv *cb_priv = board->private_data; 414 414 struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
+1 -1
drivers/staging/gpib/cec/cec_gpib.c
··· 174 174 return nec7210_serial_poll_status(board, &priv->nec7210_priv); 175 175 } 176 176 177 - static unsigned int cec_t1_delay(struct gpib_board *board, unsigned int nano_sec) 177 + static int cec_t1_delay(struct gpib_board *board, unsigned int nano_sec) 178 178 { 179 179 struct cec_priv *priv = board->private_data; 180 180
+4 -1
drivers/staging/gpib/common/gpib_os.c
··· 1990 1990 1991 1991 delay = cmd; 1992 1992 1993 - board->t1_nano_sec = board->interface->t1_delay(board, delay); 1993 + retval = board->interface->t1_delay(board, delay); 1994 + if (retval < 0) 1995 + return retval; 1994 1996 1997 + board->t1_nano_sec = retval; 1995 1998 return 0; 1996 1999 } 1997 2000
+1 -1
drivers/staging/gpib/eastwood/fluke_gpib.c
··· 224 224 return status; 225 225 } 226 226 227 - static unsigned int fluke_t1_delay(struct gpib_board *board, unsigned int nano_sec) 227 + static int fluke_t1_delay(struct gpib_board *board, unsigned int nano_sec) 228 228 { 229 229 struct fluke_priv *e_priv = board->private_data; 230 230 struct nec7210_priv *nec_priv = &e_priv->nec7210_priv;
+1 -1
drivers/staging/gpib/fmh_gpib/fmh_gpib.c
··· 261 261 return status; 262 262 } 263 263 264 - static unsigned int fmh_gpib_t1_delay(struct gpib_board *board, unsigned int nano_sec) 264 + static int fmh_gpib_t1_delay(struct gpib_board *board, unsigned int nano_sec) 265 265 { 266 266 struct fmh_priv *e_priv = board->private_data; 267 267 struct nec7210_priv *nec_priv = &e_priv->nec7210_priv;
+1 -1
drivers/staging/gpib/gpio/gpib_bitbang.c
··· 1009 1009 return 0; // -ENOENT; 1010 1010 } 1011 1011 1012 - static unsigned int bb_t1_delay(struct gpib_board *board, unsigned int nano_sec) 1012 + static int bb_t1_delay(struct gpib_board *board, unsigned int nano_sec) 1013 1013 { 1014 1014 struct bb_priv *priv = board->private_data; 1015 1015
+1 -1
drivers/staging/gpib/hp_82335/hp82335.c
··· 165 165 return tms9914_line_status(board, &priv->tms9914_priv); 166 166 } 167 167 168 - static unsigned int hp82335_t1_delay(struct gpib_board *board, unsigned int nano_sec) 168 + static int hp82335_t1_delay(struct gpib_board *board, unsigned int nano_sec) 169 169 { 170 170 struct hp82335_priv *priv = board->private_data; 171 171
+1 -1
drivers/staging/gpib/hp_82341/hp_82341.c
··· 396 396 return tms9914_line_status(board, &priv->tms9914_priv); 397 397 } 398 398 399 - static unsigned int hp_82341_t1_delay(struct gpib_board *board, unsigned int nano_sec) 399 + static int hp_82341_t1_delay(struct gpib_board *board, unsigned int nano_sec) 400 400 { 401 401 struct hp_82341_priv *priv = board->private_data; 402 402
+1 -1
drivers/staging/gpib/include/gpib_types.h
··· 170 170 */ 171 171 uint8_t (*serial_poll_status)(struct gpib_board *board); 172 172 /* adjust T1 delay */ 173 - unsigned int (*t1_delay)(struct gpib_board *board, unsigned int nano_sec); 173 + int (*t1_delay)(struct gpib_board *board, unsigned int nano_sec); 174 174 /* go to local mode */ 175 175 void (*return_to_local)(struct gpib_board *board); 176 176 /* board does not support 7 bit eos comparisons */
+2 -2
drivers/staging/gpib/include/nec7210.h
··· 108 108 struct nec7210_priv *priv, int ist); 109 109 uint8_t nec7210_serial_poll_status(struct gpib_board *board, 110 110 struct nec7210_priv *priv); 111 - unsigned int nec7210_t1_delay(struct gpib_board *board, 112 - struct nec7210_priv *priv, unsigned int nano_sec); 111 + int nec7210_t1_delay(struct gpib_board *board, 112 + struct nec7210_priv *priv, unsigned int nano_sec); 113 113 void nec7210_return_to_local(const struct gpib_board *board, struct nec7210_priv *priv); 114 114 115 115 // utility functions
+1 -1
drivers/staging/gpib/ines/ines.h
··· 60 60 void ines_serial_poll_response(struct gpib_board *board, uint8_t status); 61 61 uint8_t ines_serial_poll_status(struct gpib_board *board); 62 62 int ines_line_status(const struct gpib_board *board); 63 - unsigned int ines_t1_delay(struct gpib_board *board, unsigned int nano_sec); 63 + int ines_t1_delay(struct gpib_board *board, unsigned int nano_sec); 64 64 void ines_return_to_local(struct gpib_board *board); 65 65 66 66 // interrupt service routines
+1 -1
drivers/staging/gpib/ines/ines_gpib.c
··· 65 65 ines_outb(priv, count & 0xff, XFER_COUNT_LOWER); 66 66 } 67 67 68 - unsigned int ines_t1_delay(struct gpib_board *board, unsigned int nano_sec) 68 + int ines_t1_delay(struct gpib_board *board, unsigned int nano_sec) 69 69 { 70 70 struct ines_priv *ines_priv = board->private_data; 71 71 struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv;
+1 -1
drivers/staging/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
··· 1044 1044 1045 1045 /* t1_delay */ 1046 1046 1047 - static unsigned int usb_gpib_t1_delay(struct gpib_board *board, unsigned int nano_sec) 1047 + static int usb_gpib_t1_delay(struct gpib_board *board, unsigned int nano_sec) 1048 1048 { 1049 1049 return 0; 1050 1050 }
+2 -2
drivers/staging/gpib/nec7210/nec7210.c
··· 373 373 } 374 374 EXPORT_SYMBOL(nec7210_release_rfd_holdoff); 375 375 376 - unsigned int nec7210_t1_delay(struct gpib_board *board, struct nec7210_priv *priv, 377 - unsigned int nano_sec) 376 + int nec7210_t1_delay(struct gpib_board *board, struct nec7210_priv *priv, 377 + unsigned int nano_sec) 378 378 { 379 379 unsigned int retval; 380 380
+2 -2
drivers/staging/gpib/ni_usb/ni_usb_gpib.c
··· 1616 1616 return i; 1617 1617 } 1618 1618 1619 - static unsigned int ni_usb_t1_delay(struct gpib_board *board, unsigned int nano_sec) 1619 + static int ni_usb_t1_delay(struct gpib_board *board, unsigned int nano_sec) 1620 1620 { 1621 1621 int retval; 1622 1622 struct ni_usb_priv *ni_priv = board->private_data; ··· 1633 1633 retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta); 1634 1634 if (retval < 0) { 1635 1635 dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval); 1636 - return -1; //FIXME should change return type to int for error reporting 1636 + return retval; 1637 1637 } 1638 1638 board->t1_nano_sec = actual_ns; 1639 1639 ni_usb_soft_update_status(board, ibsta, 0);
+1 -1
drivers/staging/gpib/pc2/pc2_gpib.c
··· 218 218 return nec7210_serial_poll_status(board, &priv->nec7210_priv); 219 219 } 220 220 221 - static unsigned int pc2_t1_delay(struct gpib_board *board, unsigned int nano_sec) 221 + static int pc2_t1_delay(struct gpib_board *board, unsigned int nano_sec) 222 222 { 223 223 struct pc2_priv *priv = board->private_data; 224 224
+1 -1
drivers/staging/gpib/tnt4882/tnt4882_gpib.c
··· 178 178 return status; 179 179 } 180 180 181 - static unsigned int tnt4882_t1_delay(struct gpib_board *board, unsigned int nano_sec) 181 + static int tnt4882_t1_delay(struct gpib_board *board, unsigned int nano_sec) 182 182 { 183 183 struct tnt4882_priv *tnt_priv = board->private_data; 184 184 struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;