linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: fix type mismacth
@ 2021-09-05 20:52 Pavel Skripkin
  2021-09-05 21:40 ` Michael Straube
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Pavel Skripkin @ 2021-09-05 20:52 UTC (permalink / raw)
  To: Larry.Finger, phil, gregkh, straube.linux, fmdefrancesco
  Cc: linux-staging, linux-kernel, Pavel Skripkin

smatch says:
rtw_cmd.c:1165 rtw_setassocsta_cmd() warn: struct type mismatch 'set_stakey_rsp vs set_assocsta_rsp'

Since psetassocsta_rsp has struct set_stakey_rsp * type, it looks like
copy-paste failure. This error didn't cause any bugs, because
sizeof(struct set_assocsta_parm) > sizeof(struct set_stakey_rsp), but
there is no reason for allocation extra unused memory

Fixes: 15865124feed ("staging: r8188eu: introduce new core dir for RTL8188eu driver")
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 drivers/staging/r8188eu/core/rtw_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
index fee4208dacba..afe6c7fa594d 100644
--- a/drivers/staging/r8188eu/core/rtw_cmd.c
+++ b/drivers/staging/r8188eu/core/rtw_cmd.c
@@ -1162,7 +1162,7 @@ u8 rtw_setassocsta_cmd(struct adapter  *padapter, u8 *mac_addr)
 		goto exit;
 	}
 
-	psetassocsta_rsp = kzalloc(sizeof(struct set_assocsta_rsp), GFP_ATOMIC);
+	psetassocsta_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_ATOMIC);
 	if (!psetassocsta_rsp) {
 		kfree(ph2c);
 		kfree(psetassocsta_para);
-- 
2.33.0


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

* Re: [PATCH] staging: r8188eu: fix type mismacth
  2021-09-05 20:52 [PATCH] staging: r8188eu: fix type mismacth Pavel Skripkin
@ 2021-09-05 21:40 ` Michael Straube
  2021-09-06  6:56 ` Dan Carpenter
  2021-09-06  9:44 ` Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Straube @ 2021-09-05 21:40 UTC (permalink / raw)
  To: Pavel Skripkin, Larry.Finger, phil, gregkh, fmdefrancesco
  Cc: linux-staging, linux-kernel

Hi Pavel,

On 9/5/21 22:52, Pavel Skripkin wrote:
> diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
> index fee4208dacba..afe6c7fa594d 100644
> --- a/drivers/staging/r8188eu/core/rtw_cmd.c
> +++ b/drivers/staging/r8188eu/core/rtw_cmd.c
> @@ -1162,7 +1162,7 @@ u8 rtw_setassocsta_cmd(struct adapter  *padapter, u8 *mac_addr)
>   		goto exit;
>   	}
>   
> -	psetassocsta_rsp = kzalloc(sizeof(struct set_assocsta_rsp), GFP_ATOMIC);
> +	psetassocsta_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_ATOMIC);

this should be

psetassocsta_rsp = kzalloc(sizeof(*psetassocsta_rsp), GFP_ATOMIC);


This way you get always the correct size, no matter what's the type of
psetassocsta_rsp. Checkpatch suggests this too. ;)

Best regards,
Michael

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

* Re: [PATCH] staging: r8188eu: fix type mismacth
  2021-09-05 20:52 [PATCH] staging: r8188eu: fix type mismacth Pavel Skripkin
  2021-09-05 21:40 ` Michael Straube
@ 2021-09-06  6:56 ` Dan Carpenter
  2021-09-06 15:59   ` Pavel Skripkin
  2021-09-06  9:44 ` Greg KH
  2 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2021-09-06  6:56 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: Larry.Finger, phil, gregkh, straube.linux, fmdefrancesco,
	linux-staging, linux-kernel

On Sun, Sep 05, 2021 at 11:52:16PM +0300, Pavel Skripkin wrote:
> smatch says:
> rtw_cmd.c:1165 rtw_setassocsta_cmd() warn: struct type mismatch 'set_stakey_rsp vs set_assocsta_rsp'
> 
> Since psetassocsta_rsp has struct set_stakey_rsp * type, it looks like
> copy-paste failure. This error didn't cause any bugs, because
> sizeof(struct set_assocsta_parm) > sizeof(struct set_stakey_rsp), but
> there is no reason for allocation extra unused memory
> 
> Fixes: 15865124feed ("staging: r8188eu: introduce new core dir for RTL8188eu driver")
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
> ---
>  drivers/staging/r8188eu/core/rtw_cmd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
> index fee4208dacba..afe6c7fa594d 100644
> --- a/drivers/staging/r8188eu/core/rtw_cmd.c
> +++ b/drivers/staging/r8188eu/core/rtw_cmd.c
> @@ -1162,7 +1162,7 @@ u8 rtw_setassocsta_cmd(struct adapter  *padapter, u8 *mac_addr)
>  		goto exit;
>  	}
>  
> -	psetassocsta_rsp = kzalloc(sizeof(struct set_assocsta_rsp), GFP_ATOMIC);
> +	psetassocsta_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_ATOMIC);
>  	if (!psetassocsta_rsp) {
>  		kfree(ph2c);
>  		kfree(psetassocsta_para);

I'm not sure this is correct.  Might be, might be not.  But we use
sizeof(struct set_assocsta_rsp) later in the function so it likely leads
to memory corruption.

        ph2c->rsp = (u8 *)psetassocsta_rsp;
        ph2c->rspsz = sizeof(struct set_assocsta_rsp);

regards,
dan carpenter


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

* Re: [PATCH] staging: r8188eu: fix type mismacth
  2021-09-05 20:52 [PATCH] staging: r8188eu: fix type mismacth Pavel Skripkin
  2021-09-05 21:40 ` Michael Straube
  2021-09-06  6:56 ` Dan Carpenter
@ 2021-09-06  9:44 ` Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2021-09-06  9:44 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: Larry.Finger, phil, straube.linux, fmdefrancesco, linux-staging,
	linux-kernel

On Sun, Sep 05, 2021 at 11:52:16PM +0300, Pavel Skripkin wrote:
> smatch says:
> rtw_cmd.c:1165 rtw_setassocsta_cmd() warn: struct type mismatch 'set_stakey_rsp vs set_assocsta_rsp'
> 
> Since psetassocsta_rsp has struct set_stakey_rsp * type, it looks like
> copy-paste failure. This error didn't cause any bugs, because
> sizeof(struct set_assocsta_parm) > sizeof(struct set_stakey_rsp), but
> there is no reason for allocation extra unused memory
> 
> Fixes: 15865124feed ("staging: r8188eu: introduce new core dir for RTL8188eu driver")
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
> ---
>  drivers/staging/r8188eu/core/rtw_cmd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
> index fee4208dacba..afe6c7fa594d 100644
> --- a/drivers/staging/r8188eu/core/rtw_cmd.c
> +++ b/drivers/staging/r8188eu/core/rtw_cmd.c
> @@ -1162,7 +1162,7 @@ u8 rtw_setassocsta_cmd(struct adapter  *padapter, u8 *mac_addr)
>  		goto exit;
>  	}
>  
> -	psetassocsta_rsp = kzalloc(sizeof(struct set_assocsta_rsp), GFP_ATOMIC);
> +	psetassocsta_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_ATOMIC);

Best way to fix this is to use the variable in the call itself, like:
	psetassocsta_rsp = kzalloc(sizeof(*psetassocsta_rsp), GFP_ATOMIC);

But as Dan said, this looks odd overall, please make sure that the code
is correct here.

thanks,

greg k-h

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

* Re: [PATCH] staging: r8188eu: fix type mismacth
  2021-09-06  6:56 ` Dan Carpenter
@ 2021-09-06 15:59   ` Pavel Skripkin
  0 siblings, 0 replies; 5+ messages in thread
From: Pavel Skripkin @ 2021-09-06 15:59 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Larry.Finger, phil, gregkh, straube.linux, fmdefrancesco,
	linux-staging, linux-kernel

On 9/6/21 09:56, Dan Carpenter wrote:
> On Sun, Sep 05, 2021 at 11:52:16PM +0300, Pavel Skripkin wrote:
>> smatch says:
>> rtw_cmd.c:1165 rtw_setassocsta_cmd() warn: struct type mismatch 'set_stakey_rsp vs set_assocsta_rsp'
>> 
>> Since psetassocsta_rsp has struct set_stakey_rsp * type, it looks like
>> copy-paste failure. This error didn't cause any bugs, because
>> sizeof(struct set_assocsta_parm) > sizeof(struct set_stakey_rsp), but
>> there is no reason for allocation extra unused memory
>> 
>> Fixes: 15865124feed ("staging: r8188eu: introduce new core dir for RTL8188eu driver")
>> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
>> ---
>>  drivers/staging/r8188eu/core/rtw_cmd.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
>> index fee4208dacba..afe6c7fa594d 100644
>> --- a/drivers/staging/r8188eu/core/rtw_cmd.c
>> +++ b/drivers/staging/r8188eu/core/rtw_cmd.c
>> @@ -1162,7 +1162,7 @@ u8 rtw_setassocsta_cmd(struct adapter  *padapter, u8 *mac_addr)
>>  		goto exit;
>>  	}
>>  
>> -	psetassocsta_rsp = kzalloc(sizeof(struct set_assocsta_rsp), GFP_ATOMIC);
>> +	psetassocsta_rsp = kzalloc(sizeof(struct set_stakey_rsp), GFP_ATOMIC);
>>  	if (!psetassocsta_rsp) {
>>  		kfree(ph2c);
>>  		kfree(psetassocsta_para);
> 
> I'm not sure this is correct.  Might be, might be not.  But we use
> sizeof(struct set_assocsta_rsp) later in the function so it likely leads
> to memory corruption.
> 
>          ph2c->rsp = (u8 *)psetassocsta_rsp;
>          ph2c->rspsz = sizeof(struct set_assocsta_rsp);
> 

Hi, Dan!


Unfortunately, this function is unused, so I will just remove it in v2 :)


With regards,
Pavel Skripkin

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

end of thread, other threads:[~2021-09-06 16:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-05 20:52 [PATCH] staging: r8188eu: fix type mismacth Pavel Skripkin
2021-09-05 21:40 ` Michael Straube
2021-09-06  6:56 ` Dan Carpenter
2021-09-06 15:59   ` Pavel Skripkin
2021-09-06  9:44 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).