public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] char: mwave: smapi: Make usSmapiOK signed to fix warning
@ 2025-04-09 21:19 Purva Yeshi
  2025-04-15 14:52 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Purva Yeshi @ 2025-04-09 21:19 UTC (permalink / raw)
  To: arnd, gregkh; +Cc: linux-kernel, 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.

Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
---
 drivers/char/mwave/smapi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/mwave/smapi.c b/drivers/char/mwave/smapi.c
index f8d79d393b69..37da1339357e 100644
--- a/drivers/char/mwave/smapi.c
+++ b/drivers/char/mwave/smapi.c
@@ -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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] char: mwave: smapi: Make usSmapiOK signed to fix warning
  2025-04-09 21:19 [PATCH] char: mwave: smapi: Make usSmapiOK signed to fix warning Purva Yeshi
@ 2025-04-15 14:52 ` Greg KH
  2025-04-17  5:59   ` Purva Yeshi
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2025-04-15 14:52 UTC (permalink / raw)
  To: Purva Yeshi; +Cc: arnd, linux-kernel

On Thu, Apr 10, 2025 at 02:49:29AM +0530, Purva Yeshi wrote:
> 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.
> 
> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
> ---
>  drivers/char/mwave/smapi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/char/mwave/smapi.c b/drivers/char/mwave/smapi.c
> index f8d79d393b69..37da1339357e 100644
> --- a/drivers/char/mwave/smapi.c
> +++ b/drivers/char/mwave/smapi.c
> @@ -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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] char: mwave: smapi: Make usSmapiOK signed to fix warning
  2025-04-15 14:52 ` Greg KH
@ 2025-04-17  5:59   ` Purva Yeshi
  0 siblings, 0 replies; 3+ messages in thread
From: Purva Yeshi @ 2025-04-17  5:59 UTC (permalink / raw)
  To: Greg KH; +Cc: arnd, linux-kernel

On 15/04/25 20:22, Greg KH wrote:
> On Thu, Apr 10, 2025 at 02:49:29AM +0530, Purva Yeshi wrote:
>> 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.
>>
>> Signed-off-by: Purva Yeshi <purvayeshi550@gmail.com>
>> ---
>>   drivers/char/mwave/smapi.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/char/mwave/smapi.c b/drivers/char/mwave/smapi.c
>> index f8d79d393b69..37da1339357e 100644
>> --- a/drivers/char/mwave/smapi.c
>> +++ b/drivers/char/mwave/smapi.c
>> @@ -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

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-17  5:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-09 21:19 [PATCH] char: mwave: smapi: Make usSmapiOK signed to fix warning Purva Yeshi
2025-04-15 14:52 ` Greg KH
2025-04-17  5:59   ` Purva Yeshi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox