Skip to content

Commit ed37518

Browse files
losgobbigregkh
authored andcommitted
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: 4e127de ("staging: gpib: Add National Instruments USB GPIB driver") Signed-off-by: Rodrigo Gobbi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 97d83d2 commit ed37518

File tree

19 files changed

+25
-23
lines changed

19 files changed

+25
-23
lines changed

drivers/staging/gpib/agilent_82350b/agilent_82350b.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,7 @@ static int agilent_82350b_line_status(const struct gpib_board *board)
455455
return tms9914_line_status(board, &priv->tms9914_priv);
456456
}
457457

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)
460459
{
461460
struct agilent_82350b_priv *a_priv = board->private_data;
462461
static const int nanosec_per_clock = 30;

drivers/staging/gpib/agilent_82357a/agilent_82357a.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ static unsigned short nanosec_to_fast_talker_bits(unsigned int *nanosec)
10711071
return bits;
10721072
}
10731073

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)
10751075
{
10761076
struct agilent_82357a_priv *a_priv = board->private_data;
10771077
struct usb_device *usb_dev;

drivers/staging/gpib/cb7210/cb7210.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static int cb7210_line_status(const struct gpib_board *board)
408408
return status;
409409
}
410410

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)
412412
{
413413
struct cb7210_priv *cb_priv = board->private_data;
414414
struct nec7210_priv *nec_priv = &cb_priv->nec7210_priv;

drivers/staging/gpib/cec/cec_gpib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static uint8_t cec_serial_poll_status(struct gpib_board *board)
174174
return nec7210_serial_poll_status(board, &priv->nec7210_priv);
175175
}
176176

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)
178178
{
179179
struct cec_priv *priv = board->private_data;
180180

drivers/staging/gpib/common/gpib_os.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,8 +1990,11 @@ static int t1_delay_ioctl(struct gpib_board *board, unsigned long arg)
19901990

19911991
delay = cmd;
19921992

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;
19941996

1997+
board->t1_nano_sec = retval;
19951998
return 0;
19961999
}
19972000

drivers/staging/gpib/eastwood/fluke_gpib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static int fluke_line_status(const struct gpib_board *board)
224224
return status;
225225
}
226226

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)
228228
{
229229
struct fluke_priv *e_priv = board->private_data;
230230
struct nec7210_priv *nec_priv = &e_priv->nec7210_priv;

drivers/staging/gpib/fmh_gpib/fmh_gpib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static int fmh_gpib_line_status(const struct gpib_board *board)
261261
return status;
262262
}
263263

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)
265265
{
266266
struct fmh_priv *e_priv = board->private_data;
267267
struct nec7210_priv *nec_priv = &e_priv->nec7210_priv;

drivers/staging/gpib/gpio/gpib_bitbang.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ static uint8_t bb_serial_poll_status(struct gpib_board *board)
10091009
return 0; // -ENOENT;
10101010
}
10111011

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)
10131013
{
10141014
struct bb_priv *priv = board->private_data;
10151015

drivers/staging/gpib/hp_82335/hp82335.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static int hp82335_line_status(const struct gpib_board *board)
165165
return tms9914_line_status(board, &priv->tms9914_priv);
166166
}
167167

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)
169169
{
170170
struct hp82335_priv *priv = board->private_data;
171171

drivers/staging/gpib/hp_82341/hp_82341.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static int hp_82341_line_status(const struct gpib_board *board)
396396
return tms9914_line_status(board, &priv->tms9914_priv);
397397
}
398398

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)
400400
{
401401
struct hp_82341_priv *priv = board->private_data;
402402

0 commit comments

Comments
 (0)