staging: gpib: Correct check for max secondary address
authorDave Penkler <dpenkler@gmail.com>
Mon, 4 Nov 2024 17:50:13 +0000 (18:50 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 7 Nov 2024 08:27:35 +0000 (09:27 +0100)
GPIB secondary addresses can be between 0 and 31 inclusive
unlike primary addresses where address 31 is not a valid device
address.  When 31 is used as a primary talk address it
forms the UNT (Untalk) command and when used as a listener address it
forms the UNL (Unlisten) commmand.
The library was incorrectly not allowing a secondary address
with a value of 31 to be used.

Fixes: 9dde4559e939 ("staging: gpib: Add GPIB common core driver")
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/20241104175014.12317-13-dpenkler@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/gpib/common/gpib_os.c
drivers/staging/gpib/common/iblib.c
drivers/staging/gpib/common/ibsys.h

index e84097ac8f69c69c975832111d4d5a87c07ab1d8..0285180ae1f02e3f30ea93a6583f5eef25a49663 100644 (file)
@@ -525,8 +525,6 @@ int serial_poll_all(gpib_board_t *board, unsigned int usec_timeout)
  * SPD and UNT are sent at the completion of the poll.
  */
 
-static const int gpib_addr_max = 30;   /* max address for primary/secondary gpib addresses */
-
 int dvrsp(gpib_board_t *board, unsigned int pad, int sad,
          unsigned int usec_timeout, uint8_t *result)
 {
@@ -538,7 +536,7 @@ int dvrsp(gpib_board_t *board, unsigned int pad, int sad,
                return -1;
        }
 
-       if (pad > gpib_addr_max || sad > gpib_addr_max) {
+       if (pad > MAX_GPIB_PRIMARY_ADDRESS || sad > MAX_GPIB_SECONDARY_ADDRESS) {
                pr_err("gpib: bad address for serial poll");
                return -1;
        }
index fc57e760c1441caa4a98849606b04e7a745ffc8f..db1911cc1b263836484f3e37e0e102745e7c3ce7 100644 (file)
@@ -479,7 +479,7 @@ int ibsre(gpib_board_t *board, int enable)
  */
 int ibpad(gpib_board_t *board, unsigned int addr)
 {
-       if (addr > 30) {
+       if (addr > MAX_GPIB_PRIMARY_ADDRESS) {
                pr_err("gpib: invalid primary address %u\n", addr);
                return -1;
        }
@@ -498,8 +498,8 @@ int ibpad(gpib_board_t *board, unsigned int addr)
  */
 int ibsad(gpib_board_t *board, int addr)
 {
-       if (addr > 30) {
-               pr_err("gpib: invalid secondary address %i, must be 0-30\n", addr);
+       if (addr > MAX_GPIB_SECONDARY_ADDRESS) {
+               pr_err("gpib: invalid secondary address %i\n", addr);
                return -1;
        }
        board->sad = addr;
index b78ca5ea4da12798a0353ba3427673f591b201d9..da20971e9c7ee05e857dab4972f0f2fecf9f8a9f 100644 (file)
@@ -16,6 +16,9 @@
 #include <asm/irq.h>
 #include <asm/dma.h>
 
+#define MAX_GPIB_PRIMARY_ADDRESS 30
+#define MAX_GPIB_SECONDARY_ADDRESS 31
+
 int gpib_allocate_board(gpib_board_t *board);
 void gpib_deallocate_board(gpib_board_t *board);