Skip to contentSkip to conversation

staging: gpib: Add lower bound check for secondary address

PATCH New Dave Penkler 1 participant 1 message Dec 7, 2024 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: gpib: Add lower bound check for secondary address

Commit 9dde4559e939 ("staging: gpib: Add GPIB common core driver") from Sep 18, 2024 (linux-next), leads to the following Smatch static checker warning:

drivers/staging/gpib/common/gpib_os.c:541 dvrsp()
warn: no lower bound on 'sad' rl='s32min-30'

The value -1 was introduced in user land to signify No secondary address to the driver so that a lower bound check could be added.

This patch adds that check.

---
 drivers/staging/gpib/common/gpib_os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gpib/common/gpib_os.c +1 -1
index 405237d8cb47..f25e7c458581 100644
@@ -536,7 +536,7 @@ int dvrsp(gpib_board_t *board, unsigned int pad, int sad,
 		return -1;
 	}
 
-	if (pad > MAX_GPIB_PRIMARY_ADDRESS || sad > MAX_GPIB_SECONDARY_ADDRESS) {
+	if (pad > MAX_GPIB_PRIMARY_ADDRESS || sad > MAX_GPIB_SECONDARY_ADDRESS || sad < -1) {
 		pr_err("gpib: bad address for serial poll");
 		return -1;
 	}
Signature · 1 line
2.47.1