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

staging: gpib: Add return value to request_control

A number of drivers are unable to release control due to hardware or
software limitations. As request_system_control was defined as void,
no error could be signalled.

This patch changes the prototype of request_system_control to int and
adds the appropriate checking and returns. In the case that a board
cannot release control EINVAL is returned. If a driver does not
implement request_system_control EPERM is returned.

Signed-off-by: Dave Penkler <dpenkler@gmail.com>
Link: https://lore.kernel.org/r/20250418133537.22491-1-dpenkler@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dave Penkler and committed by
Greg Kroah-Hartman
4960bce3 a5df13cd

+76 -70
+2 -4
drivers/staging/gpib/agilent_82350b/agilent_82350b.c
··· 341 341 return tms9914_go_to_standby(board, &priv->tms9914_priv); 342 342 } 343 343 344 - static void agilent_82350b_request_system_control(struct gpib_board *board, 345 - int request_control) 346 - 344 + static int agilent_82350b_request_system_control(struct gpib_board *board, int request_control) 347 345 { 348 346 struct agilent_82350b_priv *a_priv = board->private_data; 349 347 ··· 355 357 writeb(0, a_priv->gpib_base + INTERNAL_CONFIG_REG); 356 358 } 357 359 writeb(a_priv->card_mode_bits, a_priv->gpib_base + CARD_MODE_REG); 358 - tms9914_request_system_control(board, &a_priv->tms9914_priv, request_control); 360 + return tms9914_request_system_control(board, &a_priv->tms9914_priv, request_control); 359 361 } 360 362 361 363 static void agilent_82350b_interface_clear(struct gpib_board *board, int assert)
+10 -12
drivers/staging/gpib/agilent_82357a/agilent_82357a.c
··· 756 756 return 0; 757 757 } 758 758 759 - //FIXME should change prototype to return int 760 - static void agilent_82357a_request_system_control(struct gpib_board *board, 761 - int request_control) 759 + static int agilent_82357a_request_system_control(struct gpib_board *board, int request_control) 762 760 { 763 761 struct agilent_82357a_priv *a_priv = board->private_data; 764 762 struct usb_device *usb_dev; ··· 765 767 int i = 0; 766 768 767 769 if (!a_priv->bus_interface) 768 - return; // -ENODEV; 770 + return -ENODEV; 769 771 770 772 usb_dev = interface_to_usbdev(a_priv->bus_interface); 771 773 /* 82357B needs bit to be set in 9914 AUXCR register */ ··· 774 776 writes[i].value = AUX_RQC; 775 777 a_priv->hw_control_bits |= SYSTEM_CONTROLLER; 776 778 } else { 777 - writes[i].value = AUX_RLC; 778 - a_priv->is_cic = 0; 779 - a_priv->hw_control_bits &= ~SYSTEM_CONTROLLER; 779 + return -EINVAL; 780 780 } 781 781 ++i; 782 782 writes[i].address = HW_CONTROL; ··· 783 787 retval = agilent_82357a_write_registers(a_priv, writes, i); 784 788 if (retval) 785 789 dev_err(&usb_dev->dev, "write_registers() returned error\n"); 786 - return;// retval; 790 + return retval; 787 791 } 788 792 789 793 static void agilent_82357a_interface_clear(struct gpib_board *board, int assert) ··· 1589 1593 { 1590 1594 struct usb_device *usb_dev = interface_to_usbdev(interface); 1591 1595 struct gpib_board *board; 1592 - int i, retval; 1596 + int i, retval = 0; 1593 1597 1594 1598 mutex_lock(&agilent_82357a_hotplug_lock); 1595 1599 ··· 1600 1604 break; 1601 1605 } 1602 1606 } 1603 - if (i == MAX_NUM_82357A_INTERFACES) 1607 + if (i == MAX_NUM_82357A_INTERFACES) { 1608 + retval = -ENOENT; 1604 1609 goto resume_exit; 1610 + } 1605 1611 1606 1612 struct agilent_82357a_priv *a_priv = board->private_data; 1607 1613 ··· 1626 1628 return retval; 1627 1629 } 1628 1630 // set/unset system controller 1629 - agilent_82357a_request_system_control(board, board->master); 1631 + retval = agilent_82357a_request_system_control(board, board->master); 1630 1632 // toggle ifc if master 1631 1633 if (board->master) { 1632 1634 agilent_82357a_interface_clear(board, 1); ··· 1644 1646 resume_exit: 1645 1647 mutex_unlock(&agilent_82357a_hotplug_lock); 1646 1648 1647 - return 0; 1649 + return retval; 1648 1650 } 1649 1651 1650 1652 static struct usb_driver agilent_82357a_bus_driver = {
+2 -2
drivers/staging/gpib/cb7210/cb7210.c
··· 578 578 return nec7210_go_to_standby(board, &priv->nec7210_priv); 579 579 } 580 580 581 - static void cb7210_request_system_control(struct gpib_board *board, int request_control) 581 + static int cb7210_request_system_control(struct gpib_board *board, int request_control) 582 582 { 583 583 struct cb7210_priv *priv = board->private_data; 584 584 struct nec7210_priv *nec_priv = &priv->nec7210_priv; ··· 589 589 priv->hs_mode_bits &= ~HS_SYS_CONTROL; 590 590 591 591 cb7210_write_byte(priv, priv->hs_mode_bits, HS_MODE); 592 - nec7210_request_system_control(board, nec_priv, request_control); 592 + return nec7210_request_system_control(board, nec_priv, request_control); 593 593 } 594 594 595 595 static void cb7210_interface_clear(struct gpib_board *board, int assert)
+2 -2
drivers/staging/gpib/cec/cec_gpib.c
··· 83 83 return nec7210_go_to_standby(board, &priv->nec7210_priv); 84 84 } 85 85 86 - static void cec_request_system_control(struct gpib_board *board, int request_control) 86 + static int cec_request_system_control(struct gpib_board *board, int request_control) 87 87 { 88 88 struct cec_priv *priv = board->private_data; 89 89 90 - nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 90 + return nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 91 91 } 92 92 93 93 static void cec_interface_clear(struct gpib_board *board, int assert)
+1 -3
drivers/staging/gpib/common/gpib_os.c
··· 1988 1988 if (retval) 1989 1989 return -EFAULT; 1990 1990 1991 - ibrsc(board, request_control); 1992 - 1993 - return 0; 1991 + return ibrsc(board, request_control); 1994 1992 } 1995 1993 1996 1994 static int t1_delay_ioctl(struct gpib_board *board, unsigned long arg)
+13 -4
drivers/staging/gpib/common/iblib.c
··· 422 422 return 0; 423 423 } 424 424 425 - /* FIXME make int */ 426 - void ibrsc(struct gpib_board *board, int request_control) 425 + int ibrsc(struct gpib_board *board, int request_control) 427 426 { 427 + int retval; 428 + 429 + if (!board->interface->request_system_control) 430 + return -EPERM; 431 + 432 + retval = board->interface->request_system_control(board, request_control); 433 + 434 + if (retval) 435 + return retval; 436 + 428 437 board->master = request_control != 0; 429 - if (board->interface->request_system_control) 430 - board->interface->request_system_control(board, request_control); 438 + 439 + return 0; 431 440 } 432 441 433 442 /*
+2 -2
drivers/staging/gpib/eastwood/fluke_gpib.c
··· 94 94 return nec7210_go_to_standby(board, &priv->nec7210_priv); 95 95 } 96 96 97 - static void fluke_request_system_control(struct gpib_board *board, int request_control) 97 + static int fluke_request_system_control(struct gpib_board *board, int request_control) 98 98 { 99 99 struct fluke_priv *priv = board->private_data; 100 100 struct nec7210_priv *nec_priv = &priv->nec7210_priv; 101 101 102 - nec7210_request_system_control(board, nec_priv, request_control); 102 + return nec7210_request_system_control(board, nec_priv, request_control); 103 103 } 104 104 105 105 static void fluke_interface_clear(struct gpib_board *board, int assert)
+2 -2
drivers/staging/gpib/fmh_gpib/fmh_gpib.c
··· 86 86 return nec7210_go_to_standby(board, &priv->nec7210_priv); 87 87 } 88 88 89 - static void fmh_gpib_request_system_control(struct gpib_board *board, int request_control) 89 + static int fmh_gpib_request_system_control(struct gpib_board *board, int request_control) 90 90 { 91 91 struct fmh_priv *priv = board->private_data; 92 92 struct nec7210_priv *nec_priv = &priv->nec7210_priv; 93 93 94 - nec7210_request_system_control(board, nec_priv, request_control); 94 + return nec7210_request_system_control(board, nec_priv, request_control); 95 95 } 96 96 97 97 static void fmh_gpib_interface_clear(struct gpib_board *board, int assert)
+8 -8
drivers/staging/gpib/gpio/gpib_bitbang.c
··· 883 883 return 0; 884 884 } 885 885 886 - static void bb_request_system_control(struct gpib_board *board, int request_control) 886 + static int bb_request_system_control(struct gpib_board *board, int request_control) 887 887 { 888 888 dbg_printk(2, "%d\n", request_control); 889 - if (request_control) { 890 - set_bit(CIC_NUM, &board->status); 891 - // drive DAV & EOI false, enable NRFD & NDAC irqs 892 - SET_DIR_WRITE(board->private_data); 893 - } else { 894 - clear_bit(CIC_NUM, &board->status); 895 - } 889 + if (!request_control) 890 + return -EINVAL; 891 + 892 + set_bit(CIC_NUM, &board->status); 893 + // drive DAV & EOI false, enable NRFD & NDAC irqs 894 + SET_DIR_WRITE(board->private_data); 895 + return 0; 896 896 } 897 897 898 898 static void bb_interface_clear(struct gpib_board *board, int assert)
+2 -2
drivers/staging/gpib/hp_82335/hp82335.c
··· 68 68 return tms9914_go_to_standby(board, &priv->tms9914_priv); 69 69 } 70 70 71 - static void hp82335_request_system_control(struct gpib_board *board, int request_control) 71 + static int hp82335_request_system_control(struct gpib_board *board, int request_control) 72 72 { 73 73 struct hp82335_priv *priv = board->private_data; 74 74 75 - tms9914_request_system_control(board, &priv->tms9914_priv, request_control); 75 + return tms9914_request_system_control(board, &priv->tms9914_priv, request_control); 76 76 } 77 77 78 78 static void hp82335_interface_clear(struct gpib_board *board, int assert)
+2 -2
drivers/staging/gpib/hp_82341/hp_82341.c
··· 294 294 return tms9914_go_to_standby(board, &priv->tms9914_priv); 295 295 } 296 296 297 - static void hp_82341_request_system_control(struct gpib_board *board, int request_control) 297 + static int hp_82341_request_system_control(struct gpib_board *board, int request_control) 298 298 { 299 299 struct hp_82341_priv *priv = board->private_data; 300 300 ··· 303 303 else 304 304 priv->mode_control_bits &= ~SYSTEM_CONTROLLER_BIT; 305 305 outb(priv->mode_control_bits, priv->iobase[0] + MODE_CONTROL_STATUS_REG); 306 - tms9914_request_system_control(board, &priv->tms9914_priv, request_control); 306 + return tms9914_request_system_control(board, &priv->tms9914_priv, request_control); 307 307 } 308 308 309 309 static void hp_82341_interface_clear(struct gpib_board *board, int assert)
+1 -1
drivers/staging/gpib/include/gpib_proto.h
··· 31 31 int ibrd(struct gpib_board *board, u8 *buf, size_t length, int *end_flag, size_t *bytes_read); 32 32 int ibrpp(struct gpib_board *board, u8 *buf); 33 33 int ibrsv2(struct gpib_board *board, u8 status_byte, int new_reason_for_service); 34 - void ibrsc(struct gpib_board *board, int request_control); 34 + int ibrsc(struct gpib_board *board, int request_control); 35 35 int ibsic(struct gpib_board *board, unsigned int usec_duration); 36 36 int ibsre(struct gpib_board *board, int enable); 37 37 int ibpad(struct gpib_board *board, unsigned int addr);
+1 -1
drivers/staging/gpib/include/gpib_types.h
··· 100 100 */ 101 101 int (*go_to_standby)(struct gpib_board *board); 102 102 /* request/release control of the IFC and REN lines (system controller) */ 103 - void (*request_system_control)(struct gpib_board *board, int request_control); 103 + int (*request_system_control)(struct gpib_board *board, int request_control); 104 104 /* 105 105 * Asserts or de-asserts 'interface clear' (IFC) depending on 106 106 * boolean value of 'assert'
+2 -2
drivers/staging/gpib/include/nec7210.h
··· 86 86 size_t length, size_t *bytes_written); 87 87 int nec7210_take_control(struct gpib_board *board, struct nec7210_priv *priv, int syncronous); 88 88 int nec7210_go_to_standby(struct gpib_board *board, struct nec7210_priv *priv); 89 - void nec7210_request_system_control(struct gpib_board *board, 90 - struct nec7210_priv *priv, int request_control); 89 + int nec7210_request_system_control(struct gpib_board *board, 90 + struct nec7210_priv *priv, int request_control); 91 91 void nec7210_interface_clear(struct gpib_board *board, struct nec7210_priv *priv, int assert); 92 92 void nec7210_remote_enable(struct gpib_board *board, struct nec7210_priv *priv, int enable); 93 93 int nec7210_enable_eos(struct gpib_board *board, struct nec7210_priv *priv, u8 eos_bytes,
+2 -2
drivers/staging/gpib/include/tms9914.h
··· 93 93 int tms9914_take_control_workaround(struct gpib_board *board, struct tms9914_priv *priv, 94 94 int syncronous); 95 95 int tms9914_go_to_standby(struct gpib_board *board, struct tms9914_priv *priv); 96 - void tms9914_request_system_control(struct gpib_board *board, struct tms9914_priv *priv, 97 - int request_control); 96 + int tms9914_request_system_control(struct gpib_board *board, struct tms9914_priv *priv, 97 + int request_control); 98 98 void tms9914_interface_clear(struct gpib_board *board, struct tms9914_priv *priv, int assert); 99 99 void tms9914_remote_enable(struct gpib_board *board, struct tms9914_priv *priv, int enable); 100 100 int tms9914_enable_eos(struct gpib_board *board, struct tms9914_priv *priv, u8 eos_bytes,
+1 -1
drivers/staging/gpib/ines/ines.h
··· 47 47 int ines_command(struct gpib_board *board, u8 *buffer, size_t length, size_t *bytes_written); 48 48 int ines_take_control(struct gpib_board *board, int synchronous); 49 49 int ines_go_to_standby(struct gpib_board *board); 50 - void ines_request_system_control(struct gpib_board *board, int request_control); 50 + int ines_request_system_control(struct gpib_board *board, int request_control); 51 51 void ines_interface_clear(struct gpib_board *board, int assert); 52 52 void ines_remote_enable(struct gpib_board *board, int enable); 53 53 int ines_enable_eos(struct gpib_board *board, u8 eos_byte, int compare_8_bits);
+2 -2
drivers/staging/gpib/ines/ines_gpib.c
··· 441 441 return nec7210_go_to_standby(board, &priv->nec7210_priv); 442 442 } 443 443 444 - void ines_request_system_control(struct gpib_board *board, int request_control) 444 + int ines_request_system_control(struct gpib_board *board, int request_control) 445 445 { 446 446 struct ines_priv *priv = board->private_data; 447 447 448 - nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 448 + return nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 449 449 } 450 450 451 451 void ines_interface_clear(struct gpib_board *board, int assert)
+5 -6
drivers/staging/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
··· 911 911 912 912 /* request_system_control */ 913 913 914 - static void usb_gpib_request_system_control(struct gpib_board *board, 915 - int request_control) 914 + static int usb_gpib_request_system_control(struct gpib_board *board, int request_control) 916 915 { 917 - if (request_control) 918 - set_bit(CIC_NUM, &board->status); 919 - else 920 - clear_bit(CIC_NUM, &board->status); 916 + if (!request_control) 917 + return -EINVAL; 921 918 919 + set_bit(CIC_NUM, &board->status); 922 920 DIA_LOG(1, "done with %d -> %lx\n", request_control, board->status); 921 + return 0; 923 922 } 924 923 925 924 /* take_control */
+3 -2
drivers/staging/gpib/nec7210/nec7210.c
··· 332 332 } 333 333 EXPORT_SYMBOL(nec7210_go_to_standby); 334 334 335 - void nec7210_request_system_control(struct gpib_board *board, struct nec7210_priv *priv, 336 - int request_control) 335 + int nec7210_request_system_control(struct gpib_board *board, struct nec7210_priv *priv, 336 + int request_control) 337 337 { 338 338 if (request_control == 0) { 339 339 write_byte(priv, AUX_CREN, AUXMR); 340 340 write_byte(priv, AUX_CIFC, AUXMR); 341 341 write_byte(priv, AUX_DSC, AUXMR); 342 342 } 343 + return 0; 343 344 } 344 345 EXPORT_SYMBOL(nec7210_request_system_control); 345 346
+4 -4
drivers/staging/gpib/ni_usb/ni_usb_gpib.c
··· 1055 1055 return 0; 1056 1056 } 1057 1057 1058 - static void ni_usb_request_system_control(struct gpib_board *board, int request_control) 1058 + static int ni_usb_request_system_control(struct gpib_board *board, int request_control) 1059 1059 { 1060 1060 int retval; 1061 1061 struct ni_usb_priv *ni_priv = board->private_data; ··· 1065 1065 unsigned int ibsta; 1066 1066 1067 1067 if (!ni_priv->bus_interface) 1068 - return; // -ENODEV; 1068 + return -ENODEV; 1069 1069 usb_dev = interface_to_usbdev(ni_priv->bus_interface); 1070 1070 if (request_control) { 1071 1071 writes[i].device = NIUSB_SUBDEV_TNT4882; ··· 1097 1097 retval = ni_usb_write_registers(ni_priv, writes, i, &ibsta); 1098 1098 if (retval < 0) { 1099 1099 dev_err(&usb_dev->dev, "register write failed, retval=%i\n", retval); 1100 - return; // retval; 1100 + return retval; 1101 1101 } 1102 1102 if (!request_control) 1103 1103 ni_priv->ren_state = 0; 1104 1104 ni_usb_soft_update_status(board, ibsta, 0); 1105 - return; // 0; 1105 + return 0; 1106 1106 } 1107 1107 1108 1108 //FIXME maybe the interface should have a "pulse interface clear" function that can return an error?
+2 -2
drivers/staging/gpib/pc2/pc2_gpib.c
··· 128 128 return nec7210_go_to_standby(board, &priv->nec7210_priv); 129 129 } 130 130 131 - static void pc2_request_system_control(struct gpib_board *board, int request_control) 131 + static int pc2_request_system_control(struct gpib_board *board, int request_control) 132 132 { 133 133 struct pc2_priv *priv = board->private_data; 134 134 135 - nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 135 + return nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 136 136 } 137 137 138 138 static void pc2_interface_clear(struct gpib_board *board, int assert)
+3 -2
drivers/staging/gpib/tms9914/tms9914.c
··· 118 118 } 119 119 EXPORT_SYMBOL_GPL(tms9914_remote_enable); 120 120 121 - void tms9914_request_system_control(struct gpib_board *board, struct tms9914_priv *priv, 122 - int request_control) 121 + int tms9914_request_system_control(struct gpib_board *board, struct tms9914_priv *priv, 122 + int request_control) 123 123 { 124 124 if (request_control) { 125 125 write_byte(priv, AUX_RQC, AUXCR); ··· 127 127 clear_bit(CIC_NUM, &board->status); 128 128 write_byte(priv, AUX_RLC, AUXCR); 129 129 } 130 + return 0; 130 131 } 131 132 EXPORT_SYMBOL_GPL(tms9914_request_system_control); 132 133
+4 -2
drivers/staging/gpib/tnt4882/tnt4882_gpib.c
··· 645 645 return nec7210_go_to_standby(board, &priv->nec7210_priv); 646 646 } 647 647 648 - static void tnt4882_request_system_control(struct gpib_board *board, int request_control) 648 + static int tnt4882_request_system_control(struct gpib_board *board, int request_control) 649 649 { 650 650 struct tnt4882_priv *priv = board->private_data; 651 + int retval; 651 652 652 653 if (request_control) { 653 654 tnt_writeb(priv, SETSC, CMDR); 654 655 udelay(1); 655 656 } 656 - nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 657 + retval = nec7210_request_system_control(board, &priv->nec7210_priv, request_control); 657 658 if (!request_control) { 658 659 tnt_writeb(priv, CLRSC, CMDR); 659 660 udelay(1); 660 661 } 662 + return retval; 661 663 } 662 664 663 665 static void tnt4882_interface_clear(struct gpib_board *board, int assert)