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: 4e127de14f ("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>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
97d83d292b
commit
ed3751860e
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ static int fluke_line_status(const struct gpib_board *board)
|
||||
return status;
|
||||
}
|
||||
|
||||
static unsigned int fluke_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
static int fluke_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
struct fluke_priv *e_priv = board->private_data;
|
||||
struct nec7210_priv *nec_priv = &e_priv->nec7210_priv;
|
||||
|
||||
@@ -261,7 +261,7 @@ static int fmh_gpib_line_status(const struct gpib_board *board)
|
||||
return status;
|
||||
}
|
||||
|
||||
static unsigned int fmh_gpib_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
static int fmh_gpib_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
struct fmh_priv *e_priv = board->private_data;
|
||||
struct nec7210_priv *nec_priv = &e_priv->nec7210_priv;
|
||||
|
||||
@@ -1009,7 +1009,7 @@ static uint8_t bb_serial_poll_status(struct gpib_board *board)
|
||||
return 0; // -ENOENT;
|
||||
}
|
||||
|
||||
static unsigned int bb_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
static int bb_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
struct bb_priv *priv = board->private_data;
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ static int hp82335_line_status(const struct gpib_board *board)
|
||||
return tms9914_line_status(board, &priv->tms9914_priv);
|
||||
}
|
||||
|
||||
static unsigned int hp82335_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
static int hp82335_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
struct hp82335_priv *priv = board->private_data;
|
||||
|
||||
|
||||
@@ -396,7 +396,7 @@ static int hp_82341_line_status(const struct gpib_board *board)
|
||||
return tms9914_line_status(board, &priv->tms9914_priv);
|
||||
}
|
||||
|
||||
static unsigned int hp_82341_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
static int hp_82341_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
struct hp_82341_priv *priv = board->private_data;
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ struct gpib_interface_struct {
|
||||
*/
|
||||
uint8_t (*serial_poll_status)(struct gpib_board *board);
|
||||
/* adjust T1 delay */
|
||||
unsigned int (*t1_delay)(struct gpib_board *board, unsigned int nano_sec);
|
||||
int (*t1_delay)(struct gpib_board *board, unsigned int nano_sec);
|
||||
/* go to local mode */
|
||||
void (*return_to_local)(struct gpib_board *board);
|
||||
/* board does not support 7 bit eos comparisons */
|
||||
|
||||
@@ -108,8 +108,8 @@ void nec7210_parallel_poll_response(struct gpib_board *board,
|
||||
struct nec7210_priv *priv, int ist);
|
||||
uint8_t nec7210_serial_poll_status(struct gpib_board *board,
|
||||
struct nec7210_priv *priv);
|
||||
unsigned int nec7210_t1_delay(struct gpib_board *board,
|
||||
struct nec7210_priv *priv, unsigned int nano_sec);
|
||||
int nec7210_t1_delay(struct gpib_board *board,
|
||||
struct nec7210_priv *priv, unsigned int nano_sec);
|
||||
void nec7210_return_to_local(const struct gpib_board *board, struct nec7210_priv *priv);
|
||||
|
||||
// utility functions
|
||||
|
||||
@@ -60,7 +60,7 @@ void ines_parallel_poll_response(struct gpib_board *board, int ist);
|
||||
void ines_serial_poll_response(struct gpib_board *board, uint8_t status);
|
||||
uint8_t ines_serial_poll_status(struct gpib_board *board);
|
||||
int ines_line_status(const struct gpib_board *board);
|
||||
unsigned int ines_t1_delay(struct gpib_board *board, unsigned int nano_sec);
|
||||
int ines_t1_delay(struct gpib_board *board, unsigned int nano_sec);
|
||||
void ines_return_to_local(struct gpib_board *board);
|
||||
|
||||
// interrupt service routines
|
||||
|
||||
@@ -65,7 +65,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(struct gpib_board *board, unsigned int nano_sec)
|
||||
int ines_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
struct ines_priv *ines_priv = board->private_data;
|
||||
struct nec7210_priv *nec_priv = &ines_priv->nec7210_priv;
|
||||
|
||||
@@ -1044,7 +1044,7 @@ static uint8_t usb_gpib_serial_poll_status(struct gpib_board *board)
|
||||
|
||||
/* t1_delay */
|
||||
|
||||
static unsigned int usb_gpib_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
static int usb_gpib_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -373,8 +373,8 @@ void nec7210_release_rfd_holdoff(struct gpib_board *board, struct nec7210_priv *
|
||||
}
|
||||
EXPORT_SYMBOL(nec7210_release_rfd_holdoff);
|
||||
|
||||
unsigned int nec7210_t1_delay(struct gpib_board *board, struct nec7210_priv *priv,
|
||||
unsigned int nano_sec)
|
||||
int nec7210_t1_delay(struct gpib_board *board, struct nec7210_priv *priv,
|
||||
unsigned int nano_sec)
|
||||
{
|
||||
unsigned int retval;
|
||||
|
||||
|
||||
@@ -1616,7 +1616,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(struct gpib_board *board, unsigned int nano_sec)
|
||||
static int ni_usb_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
int retval;
|
||||
struct ni_usb_priv *ni_priv = board->private_data;
|
||||
@@ -1633,7 +1633,7 @@ static unsigned int ni_usb_t1_delay(struct gpib_board *board, unsigned int nano_
|
||||
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 -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);
|
||||
|
||||
@@ -218,7 +218,7 @@ static uint8_t pc2_serial_poll_status(struct gpib_board *board)
|
||||
return nec7210_serial_poll_status(board, &priv->nec7210_priv);
|
||||
}
|
||||
|
||||
static unsigned int pc2_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
static int pc2_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
struct pc2_priv *priv = board->private_data;
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ static int tnt4882_line_status(const struct gpib_board *board)
|
||||
return status;
|
||||
}
|
||||
|
||||
static unsigned int tnt4882_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
static int tnt4882_t1_delay(struct gpib_board *board, unsigned int nano_sec)
|
||||
{
|
||||
struct tnt4882_priv *tnt_priv = board->private_data;
|
||||
struct nec7210_priv *nec_priv = &tnt_priv->nec7210_priv;
|
||||
|
||||
Reference in New Issue
Block a user