staging: gpib: change return type of t1_delay function to report errors
PATCH v2 1/1 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().
---
Changelog:
v2: merge patchset into one commit;
minor change at return statement; improve commit msg as suggested by Dan; v1: https://lore.kernel.org/linux-staging/[email protected]/ --- drivers/staging/gpib/agilent_82350b/agilent_82350b.c | 2 +- drivers/staging/gpib/agilent_82357a/agilent_82357a.c | 2 +- drivers/staging/gpib/cb7210/cb7210.c | 2 +- drivers/staging/gpib/cec/cec_gpib.c | 2 +- drivers/staging/gpib/common/gpib_os.c | 5 ++++- drivers/staging/gpib/eastwood/fluke_gpib.c | 2 +- drivers/staging/gpib/fmh_gpib/fmh_gpib.c | 2 +- drivers/staging/gpib/gpio/gpib_bitbang.c | 2 +- drivers/staging/gpib/hp_82335/hp82335.c | 2 +- drivers/staging/gpib/hp_82341/hp_82341.c | 2 +- drivers/staging/gpib/include/gpib_types.h | 2 +- drivers/staging/gpib/include/nec7210.h | 4 ++-- drivers/staging/gpib/ines/ines.h | 2 +- drivers/staging/gpib/ines/ines_gpib.c | 2 +- drivers/staging/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c | 3 +-- drivers/staging/gpib/nec7210/nec7210.c | 4 ++-- drivers/staging/gpib/ni_usb/ni_usb_gpib.c | 4 ++-- drivers/staging/gpib/pc2/pc2_gpib.c | 2 +- drivers/staging/gpib/tnt4882/tnt4882_gpib.c | 2 +- 19 files changed, 25 insertions(+), 23 deletions(-)
drivers/staging/gpib/agilent_82350b/agilent_82350b.c +1 -1
@@ -475,7 +475,7 @@ static int agilent_82350b_line_status(const gpib_board_t *board)return tms9914_line_status (board, &priv->tms9914_priv); } -static unsigned int agilent_82350b_t1_delay (gpib_board_t *board,unsigned int nanosec) +static int agilent_82350b_t1_delay (gpib_board_t *board,unsigned int nanosec) {struct agilent_82350b_priv *a_priv = board->private_data;static const int nanosec_per_clock =30 ;
drivers/staging/gpib/agilent_82357a/agilent_82357a.c +1 -1
@@ -1044,7 +1044,7 @@ static unsigned short nanosec_to_fast_talker_bits(unsigned int *nanosec)return bits; } -static unsigned int agilent_82357a_t1_delay (gpib_board_t *board,unsigned int nanosec) +static int agilent_82357a_t1_delay (gpib_board_t *board,unsigned int nanosec) {struct agilent_82357a_priv *a_priv = board->private_data;struct usb_device *usb_dev =interface_to_usbdev (a_priv->bus_interface);
drivers/staging/gpib/cb7210/cb7210.c +1 -1
@@ -410,7 +410,7 @@ static int cb7210_line_status(const gpib_board_t *board)return status; } -static unsigned int cb7210_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int cb7210_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct cb7210_priv *cb_priv = board->private_data;struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
drivers/staging/gpib/cec/cec_gpib.c +1 -1
@@ -169,7 +169,7 @@ static uint8_t cec_serial_poll_status(gpib_board_t *board)return nec7210_serial_poll_status (board, &priv->nec7210_priv); } -static unsigned int cec_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int cec_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct cec_priv *priv = board->private_data;
drivers/staging/gpib/common/gpib_os.c +4 -1
@@ -2018,8 +2018,11 @@ static int t1_delay_ioctl(gpib_board_t *board, unsigned long arg) delay = cmd; - board->t1_nano_sec = board->interface->t1_delay (board, delay); + retval = board->interface->t1_delay (board, delay); +if (retval <0 ) +return retval; + board->t1_nano_sec = retval;return 0 ; }
drivers/staging/gpib/eastwood/fluke_gpib.c +1 -1
@@ -221,7 +221,7 @@ static int fluke_line_status(const gpib_board_t *board)return status; } -static unsigned int fluke_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int fluke_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct fluke_priv *e_priv = board->private_data;struct nec7210_priv *nec_priv = &e_priv->nec7210_priv;
drivers/staging/gpib/fmh_gpib/fmh_gpib.c +1 -1
@@ -255,7 +255,7 @@ static int fmh_gpib_line_status(const gpib_board_t *board)return status; } -static unsigned int fmh_gpib_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int fmh_gpib_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct fmh_priv *e_priv = board->private_data;struct nec7210_priv *nec_priv = &e_priv->nec7210_priv;
drivers/staging/gpib/gpio/gpib_bitbang.c +1 -1
@@ -1012,7 +1012,7 @@ static uint8_t bb_serial_poll_status(gpib_board_t *board)return 0 ;// -ENOSYS; } -static unsigned int bb_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int bb_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct bb_priv *priv = board->private_data;
drivers/staging/gpib/hp_82335/hp82335.c +1 -1
@@ -161,7 +161,7 @@ static int hp82335_line_status(const gpib_board_t *board)return tms9914_line_status (board, &priv->tms9914_priv); } -static unsigned int hp82335_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int hp82335_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct hp82335_priv *priv = board->private_data;
drivers/staging/gpib/hp_82341/hp_82341.c +1 -1
@@ -397,7 +397,7 @@ static int hp_82341_line_status(const gpib_board_t *board)return tms9914_line_status (board, &priv->tms9914_priv); } -static unsigned int hp_82341_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int hp_82341_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct hp_82341_priv *priv = board->private_data;
drivers/staging/gpib/include/gpib_types.h +1 -1
@@ -170,7 +170,7 @@ struct gpib_interface_struct {*/ uint8_t (*serial_poll_status)(gpib_board_t *board);/* adjust T1 delay */ -unsigned int (*t1_delay)(gpib_board_t *board,unsigned int nano_sec); +int (*t1_delay)(gpib_board_t *board,unsigned int nano_sec);/* go to local mode */ void (*return_to_local)(gpib_board_t *board);/* board does not support 7 bit eos comparisons */
drivers/staging/gpib/include/nec7210.h +2 -2
@@ -108,8 +108,8 @@ void nec7210_parallel_poll_response(gpib_board_t *board, struct nec7210_priv *priv, int ist);uint8_t nec7210_serial_poll_status (gpib_board_t *board,struct nec7210_priv *priv); -unsigned int nec7210_t1_delay (gpib_board_t *board, -struct nec7210_priv *priv,unsigned int nano_sec); +int nec7210_t1_delay (gpib_board_t *board, +struct nec7210_priv *priv,unsigned int nano_sec);void nec7210_return_to_local (const gpib_board_t *board,struct nec7210_priv *priv);// utility functions
drivers/staging/gpib/ines/ines.h +1 -1
@@ -60,7 +60,7 @@ void ines_parallel_poll_response(gpib_board_t *board, int ist);void ines_serial_poll_response (gpib_board_t *board,uint8_t status);uint8_t ines_serial_poll_status (gpib_board_t *board);int ines_line_status (const gpib_board_t *board); -unsigned int ines_t1_delay (gpib_board_t *board,unsigned int nano_sec); +int ines_t1_delay (gpib_board_t *board,unsigned int nano_sec);void ines_return_to_local (gpib_board_t *board);// interrupt service routines
drivers/staging/gpib/ines/ines_gpib.c +1 -1
@@ -63,7 +63,7 @@ void ines_set_xfer_counter(struct ines_priv *priv, unsigned int count)ines_outb (priv, count &0xff ,XFER_COUNT_LOWER ); } -unsigned int ines_t1_delay (gpib_board_t *board,unsigned int nano_sec) +int ines_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct ines_priv *ines_priv = board->private_data;struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv;
drivers/staging/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c +1 -2
@@ -1120,8 +1120,7 @@ static uint8_t usb_gpib_serial_poll_status(gpib_board_t *board) }/* t1_delay */ - -static unsigned int usb_gpib_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int usb_gpib_t1_delay (gpib_board_t *board,unsigned int nano_sec) {dev_alert (board->gpib_dev,"%s:%s - currently a NOP\n" ,NAME , __func__);return 0 ;
drivers/staging/gpib/nec7210/nec7210.c +2 -2
@@ -373,8 +373,8 @@ void nec7210_release_rfd_holdoff(gpib_board_t *board, struct nec7210_priv *priv) }EXPORT_SYMBOL (nec7210_release_rfd_holdoff); -unsigned int nec7210_t1_delay (gpib_board_t *board,struct nec7210_priv *priv, -unsigned int nano_sec) +int nec7210_t1_delay (gpib_board_t *board,struct nec7210_priv *priv, +unsigned int nano_sec) {unsigned int retval;
drivers/staging/gpib/ni_usb/ni_usb_gpib.c +2 -2
@@ -1591,7 +1591,7 @@ static int ni_usb_setup_t1_delay(struct ni_usb_register *reg, unsigned int nano_return i; } -static unsigned int ni_usb_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int ni_usb_t1_delay (gpib_board_t *board,unsigned int nano_sec) {int retval;struct ni_usb_priv *ni_priv = board->private_data;
@@ -1605,7 +1605,7 @@ static unsigned int ni_usb_t1_delay(gpib_board_t *board, unsigned int nano_sec) retval =ni_usb_write_registers (ni_priv, writes, i, &ibsta);if (retval <0 ) {dev_err (&usb_dev->dev,"%s: register write failed, retval=%i\n" , __func__, retval); -return -1 ;//FIXME should change return type to int for error reporting +return retval; } board->t1_nano_sec = actual_ns;ni_usb_soft_update_status (board, ibsta,0 );
drivers/staging/gpib/pc2/pc2_gpib.c +1 -1
@@ -215,7 +215,7 @@ static uint8_t pc2_serial_poll_status(gpib_board_t *board)return nec7210_serial_poll_status (board, &priv->nec7210_priv); } -static unsigned int pc2_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int pc2_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct pc2_priv *priv = board->private_data;
drivers/staging/gpib/tnt4882/tnt4882_gpib.c +1 -1
@@ -176,7 +176,7 @@ static int tnt4882_line_status(const gpib_board_t *board)return status; } -static unsigned int tnt4882_t1_delay (gpib_board_t *board,unsigned int nano_sec) +static int tnt4882_t1_delay (gpib_board_t *board,unsigned int nano_sec) {struct tnt4882_priv *tnt_priv = board->private_data;struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
Signature · 1 line
2.47.0
Quoted 17 lines · Rodrigo Gobbi
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 setsboard->t1_nano_secto -1 and returns success.
Theboard->t1_nano_secvalue is also used inni_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 ofni_usb_setup_t1_delay().Typical delays are in the 200-2000 range, but definitely not more than
INT_MAXso 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 inni_usb_t1_delay()from -1 and instead propagate the error fromni_usb_write_registers().
Quoted 8 lines
Fixes 4e127de14fa7 ("staging: gpib: Add National Instruments USB GPIB driver")Signed-off-by Rodrigo Gobbi <[email protected]>---
Changelog:
v2: merge patchset into one commit;minor change at return statement; improve commit msg as suggested by Dan;v1: https://lore.kernel.org/linux-staging/[email protected]/
Thank you!
regards,
dan carpenter
Greg KH
maintainerQuoted 11 lines · Rodrigo Gobbi
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 setsboard->t1_nano_secto -1 and returns success.
Theboard->t1_nano_secvalue is also used inni_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 ofni_usb_setup_t1_delay().
Quoted 8 lines
Typical delays are in the 200-2000 range, but definitely not more than
INT_MAXso 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 inni_usb_t1_delay()from -1 and instead propagate the error fromni_usb_write_registers().Fixes 4e127de14fa7 ("staging: gpib: Add National Instruments USB GPIB driver")Signed-off-by Rodrigo Gobbi <[email protected]>
Can you rebase against my latest staging-testing branch, as this no longer applies there due to other changes that were sent before yours.
thanks,
greg k-h
Quoted 2 lines
Can you rebase against my latest staging-testing branch, as this no longer applies there due to other changes that were sent before yours.
Yes, I've submitted a v3 at [1].
Tks for pointing that, now it should work, regards!
[1] https://lore.kernel.org/linux-staging/[email protected]/T/#u