Skip to contentSkip to conversation

char: mwave: smapi: Make usSmapiOK signed to fix warning

PATCH In review Purva Yeshi 2 participants 3 messages Apr 9, 2025 – Apr 17, 2025 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 char: mwave: smapi: Make usSmapiOK signed to fix warning

Fix Smatch-detected warning:
drivers/char/mwave/smapi.c:69 smapi_request() warn:
assigning (-5) to unsigned variable 'usSmapiOK'

Assigning a negative value (-EIO, which is -5) to an unsigned short (usSmapiOK) causes a Smatch warning because negative values cannot be correctly represented in an unsigned type, leading to unexpected behavior.

Change the type of usSmapiOK from unsigned short to short to allow storing negative values like -EIO without causing a type mismatch or logic error.

---
 drivers/char/mwave/smapi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/mwave/smapi.c +1 -1
index f8d79d393b69..37da1339357e 100644
@@ -66,7 +66,7 @@ static int smapi_request(unsigned short inBX, unsigned short inCX,
 	unsigned short myoutDX = 5, *pmyoutDX = &myoutDX;
 	unsigned short myoutDI = 6, *pmyoutDI = &myoutDI;
 	unsigned short myoutSI = 7, *pmyoutSI = &myoutSI;
-	unsigned short usSmapiOK = -EIO, *pusSmapiOK = &usSmapiOK;
+	short usSmapiOK = -EIO, *pusSmapiOK = &usSmapiOK;
 	unsigned int inBXCX = (inBX << 16) | inCX;
 	unsigned int inDISI = (inDI << 16) | inSI;
 	int retval = 0;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 23 lines · Purva Yeshi

Fix Smatch-detected warning:
drivers/char/mwave/smapi.c:69 smapi_request() warn:
assigning (-5) to unsigned variable 'usSmapiOK'

Assigning a negative value (-EIO, which is -5) to an unsigned short (usSmapiOK) causes a Smatch warning because negative values cannot be correctly represented in an unsigned type, leading to unexpected behavior.

Change the type of usSmapiOK from unsigned short to short to allow storing negative values like -EIO without causing a type mismatch or logic error.

---
 drivers/char/mwave/smapi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/mwave/smapi.c +0 -0
index f8d79d393b69..37da1339357e 100644

drivers/char/mwave/smapi.c static int smapi_request(unsigned short inBX, unsigned short inCX, · line 69

Quoted 5 lines
drivers/char/mwave/smapi.c +1 -1
@@ -66,7 +66,7 @@ static int smapi_request(unsigned short inBX, unsigned short inCX,
 	unsigned short myoutDX = 5, *pmyoutDX = &myoutDX;
 	unsigned short myoutDI = 6, *pmyoutDI = &myoutDI;
 	unsigned short myoutSI = 7, *pmyoutSI = &myoutSI;
-	unsigned short usSmapiOK = -EIO, *pusSmapiOK = &usSmapiOK;
+	short usSmapiOK = -EIO, *pusSmapiOK = &usSmapiOK;

This no longer a "us" variable type :(

The joy of using this type of notation, ick. Please fix this up to use an explicit type (like s16), and fix the variable name at the same time.

thanks,

greg k-h

#2 lore raw
Quoted 32 lines · Greg KH
Quoted 23 lines · Purva Yeshi

Fix Smatch-detected warning:
drivers/char/mwave/smapi.c:69 smapi_request() warn:
assigning (-5) to unsigned variable 'usSmapiOK'

Assigning a negative value (-EIO, which is -5) to an unsigned short (usSmapiOK) causes a Smatch warning because negative values cannot be correctly represented in an unsigned type, leading to unexpected behavior.

Change the type of usSmapiOK from unsigned short to short to allow storing negative values like -EIO without causing a type mismatch or logic error.

---
  drivers/char/mwave/smapi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/mwave/smapi.c +0 -0
index f8d79d393b69..37da1339357e 100644

drivers/char/mwave/smapi.c static int smapi_request(unsigned short inBX, unsigned short inCX, · line 69

Quoted 5 lines
drivers/char/mwave/smapi.c +1 -1
@@ -66,7 +66,7 @@ static int smapi_request(unsigned short inBX, unsigned short inCX,
  	unsigned short myoutDX = 5, *pmyoutDX = &myoutDX;
  	unsigned short myoutDI = 6, *pmyoutDI = &myoutDI;
  	unsigned short myoutSI = 7, *pmyoutSI = &myoutSI;
-	unsigned short usSmapiOK = -EIO, *pusSmapiOK = &usSmapiOK;
+	short usSmapiOK = -EIO, *pusSmapiOK = &usSmapiOK;

This no longer a "us" variable type :(

Quoted 6 lines

The joy of using this type of notation, ick. Please fix this up to use an explicit type (like s16), and fix the variable name at the same time.

thanks,

greg k-h

Hi Greg,

Thanks for the feedback.

I’ll update the patch to use an explicit s16 type and rename the usSmapiOK with SmapiOK to match the new type. I’ll send a v2 shortly.

Best regards,
Purva