[PATCH 9/9] Correct check for max secondary address

Dave Penkler posted 9 patches 3 weeks, 2 days ago
[PATCH 9/9] Correct check for max secondary address
Posted by Dave Penkler 3 weeks, 2 days ago
  GPIB secondary addresses can be between 0 and 31 inclusive
  unlike primary addresses where address 31 is used for UNT and UNL

Signed-off-by: Dave Penkler <dpenkler@gmail.com>
---
 drivers/staging/gpib/common/gpib_os.c | 3 +--
 drivers/staging/gpib/common/iblib.c   | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/gpib/common/gpib_os.c b/drivers/staging/gpib/common/gpib_os.c
index c0b774a831a6..65ab190ac68e 100644
--- a/drivers/staging/gpib/common/gpib_os.c
+++ b/drivers/staging/gpib/common/gpib_os.c
@@ -525,7 +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 +537,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 > 30 || sad > 31) {
 		pr_err("gpib: bad address for serial poll");
 		return -1;
 	}
diff --git a/drivers/staging/gpib/common/iblib.c b/drivers/staging/gpib/common/iblib.c
index fc57e760c144..5678e8bd709b 100644
--- a/drivers/staging/gpib/common/iblib.c
+++ b/drivers/staging/gpib/common/iblib.c
@@ -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 > 31) {
+		pr_err("gpib: invalid secondary address %i, must be 0-31\n", addr);
 		return -1;
 	}
 	board->sad = addr;
-- 
2.46.2
Re: [PATCH 9/9] Correct check for max secondary address
Posted by Dan Carpenter 3 weeks, 2 days ago
On Fri, Nov 01, 2024 at 06:47:05PM +0100, Dave Penkler wrote:
>   GPIB secondary addresses can be between 0 and 31 inclusive
>   unlike primary addresses where address 31 is used for UNT and UNL

What do UNT and UNL stand for?  I don't know what those words mean.

I can tell from looking at the patch that this is a behavior change, but I don't
know from the commit what the change will look like to the user.  Please,
explain that better in the commit message.

> 
> Signed-off-by: Dave Penkler <dpenkler@gmail.com>
> ---
>  drivers/staging/gpib/common/gpib_os.c | 3 +--
>  drivers/staging/gpib/common/iblib.c   | 4 ++--
>  2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/gpib/common/gpib_os.c b/drivers/staging/gpib/common/gpib_os.c
> index c0b774a831a6..65ab190ac68e 100644
> --- a/drivers/staging/gpib/common/gpib_os.c
> +++ b/drivers/staging/gpib/common/gpib_os.c
> @@ -525,7 +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 */
>  

You'd want to delete the blank line as well otherwise you're left with two
blank lines in a row.

>  int dvrsp(gpib_board_t *board, unsigned int pad, int sad,
>  	  unsigned int usec_timeout, uint8_t *result)
> @@ -538,7 +537,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 > 30 || sad > 31) {

These should be a define instead of a magic number.

regards,
dan carpenter