Commit ed375186 authored by Rodrigo Gobbi's avatar Rodrigo Gobbi Committed by Greg Kroah-Hartman
Browse files

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: 4e127de1 ("staging: gpib: Add National Instruments USB GPIB driver")
Signed-off-by: default avatarRodrigo Gobbi <rodrigo.gobbi.7@gmail.com>
Link: https://lore.kernel.org/r/20250225014811.77995-1-rodrigo.gobbi.7@gmail.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 97d83d29
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -455,8 +455,7 @@ static int agilent_82350b_line_status(const struct gpib_board *board)
	return tms9914_line_status(board, &priv->tms9914_priv);
}

static unsigned int agilent_82350b_t1_delay(struct gpib_board *board,
					    unsigned int nanosec)
static int agilent_82350b_t1_delay(struct gpib_board *board, unsigned int nanosec)
{
	struct agilent_82350b_priv *a_priv = board->private_data;
	static const int nanosec_per_clock = 30;
+1 −1
Original line number Diff line number Diff line
@@ -1071,7 +1071,7 @@ static unsigned short nanosec_to_fast_talker_bits(unsigned int *nanosec)
	return bits;
}

static unsigned int agilent_82357a_t1_delay(struct gpib_board *board, unsigned int nanosec)
static int agilent_82357a_t1_delay(struct gpib_board *board, unsigned int nanosec)
{
	struct agilent_82357a_priv *a_priv = board->private_data;
	struct usb_device *usb_dev;
+1 −1
Original line number Diff line number Diff line
@@ -408,7 +408,7 @@ static int cb7210_line_status(const struct gpib_board *board)
	return status;
}

static unsigned int cb7210_t1_delay(struct gpib_board *board, unsigned int nano_sec)
static int cb7210_t1_delay(struct gpib_board *board, unsigned int nano_sec)
{
	struct cb7210_priv *cb_priv = board->private_data;
	struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;
+1 −1
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ static uint8_t cec_serial_poll_status(struct gpib_board *board)
	return nec7210_serial_poll_status(board, &priv->nec7210_priv);
}

static unsigned int cec_t1_delay(struct gpib_board *board, unsigned int nano_sec)
static int cec_t1_delay(struct gpib_board *board, unsigned int nano_sec)
{
	struct cec_priv *priv = board->private_data;

+4 −1
Original line number Diff line number Diff line
@@ -1990,8 +1990,11 @@ static int t1_delay_ioctl(struct gpib_board *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;
}

Loading