linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] maple_tree: Use correct variable type in sizeof
@ 2023-04-10  9:14 Peng Zhang
  2023-04-10  9:46 ` Gang Li
  2023-04-10 12:58 ` Liam R. Howlett
  0 siblings, 2 replies; 6+ messages in thread
From: Peng Zhang @ 2023-04-10  9:14 UTC (permalink / raw)
  To: Liam.Howlett
  Cc: akpm, linux-mm, linux-kernel, maple-tree, Peng Zhang, David Binderman

The original code is:
	memset(pivs + tmp, 0, sizeof(unsigned long *) * (max_p - tmp));

The type of variable pointed to by pivs is unsigned long, but the type
used in sizeof is a pointer type. Change it to unsigned long.

Suggested-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 88c44f6d6cee..b06fc5f19b31 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -3255,7 +3255,7 @@ static inline void mas_destroy_rebalance(struct ma_state *mas, unsigned char end
 
 		if (tmp < max_p)
 			memset(pivs + tmp, 0,
-			       sizeof(unsigned long *) * (max_p - tmp));
+			       sizeof(unsigned long) * (max_p - tmp));
 
 		if (tmp < mt_slots[mt])
 			memset(slots + tmp, 0, sizeof(void *) * (max_s - tmp));
-- 
2.20.1



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

* Re: [PATCH] maple_tree: Use correct variable type in sizeof
  2023-04-10  9:14 [PATCH] maple_tree: Use correct variable type in sizeof Peng Zhang
@ 2023-04-10  9:46 ` Gang Li
  2023-04-10 10:09   ` Peng Zhang
  2023-04-10 12:58 ` Liam R. Howlett
  1 sibling, 1 reply; 6+ messages in thread
From: Gang Li @ 2023-04-10  9:46 UTC (permalink / raw)
  To: Peng Zhang; +Cc: akpm, linux-mm, linux-kernel, maple-tree, David Binderman

On 2023/4/10 17:14, Peng Zhang wrote:
> The original code is:
> 	memset(pivs + tmp, 0, sizeof(unsigned long *) * (max_p - tmp));
> 
> The type of variable pointed to by pivs is unsigned long, but the type
> used in sizeof is a pointer type. Change it to unsigned long.
> 

Maybe add a fix tag?

Fixes: 54a611b60590 ("Maple Tree: add new data structure")

> Suggested-by: David Binderman <dcb314@hotmail.com>
> Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
> ---
>   lib/maple_tree.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 88c44f6d6cee..b06fc5f19b31 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -3255,7 +3255,7 @@ static inline void mas_destroy_rebalance(struct ma_state *mas, unsigned char end
>   
>   		if (tmp < max_p)
>   			memset(pivs + tmp, 0,
> -			       sizeof(unsigned long *) * (max_p - tmp));
> +			       sizeof(unsigned long) * (max_p - tmp));
>   
>   		if (tmp < mt_slots[mt])
>   			memset(slots + tmp, 0, sizeof(void *) * (max_s - tmp));


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

* Re: [PATCH] maple_tree: Use correct variable type in sizeof
  2023-04-10  9:46 ` Gang Li
@ 2023-04-10 10:09   ` Peng Zhang
  2023-04-10 13:51     ` Matthew Wilcox
  2023-04-11 10:16     ` David Laight
  0 siblings, 2 replies; 6+ messages in thread
From: Peng Zhang @ 2023-04-10 10:09 UTC (permalink / raw)
  To: Gang Li; +Cc: akpm, linux-mm, linux-kernel, maple-tree, David Binderman


在 2023/4/10 17:46, Gang Li 写道:
> On 2023/4/10 17:14, Peng Zhang wrote:
>> The original code is:
>>     memset(pivs + tmp, 0, sizeof(unsigned long *) * (max_p - tmp));
>>
>> The type of variable pointed to by pivs is unsigned long, but the type
>> used in sizeof is a pointer type. Change it to unsigned long.
>>
>
> Maybe add a fix tag?
>
> Fixes: 54a611b60590 ("Maple Tree: add new data structure")

Maybe sizeof(void *) is equal to sizeof(unsigned long)
in most architectures, so I don't know if it counts as a fix.

Thanks.

>
>> Suggested-by: David Binderman <dcb314@hotmail.com>
>> Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
>> ---
>>   lib/maple_tree.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
>> index 88c44f6d6cee..b06fc5f19b31 100644
>> --- a/lib/maple_tree.c
>> +++ b/lib/maple_tree.c
>> @@ -3255,7 +3255,7 @@ static inline void mas_destroy_rebalance(struct 
>> ma_state *mas, unsigned char end
>>             if (tmp < max_p)
>>               memset(pivs + tmp, 0,
>> -                   sizeof(unsigned long *) * (max_p - tmp));
>> +                   sizeof(unsigned long) * (max_p - tmp));
>>             if (tmp < mt_slots[mt])
>>               memset(slots + tmp, 0, sizeof(void *) * (max_s - tmp));
>


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

* Re: [PATCH] maple_tree: Use correct variable type in sizeof
  2023-04-10  9:14 [PATCH] maple_tree: Use correct variable type in sizeof Peng Zhang
  2023-04-10  9:46 ` Gang Li
@ 2023-04-10 12:58 ` Liam R. Howlett
  1 sibling, 0 replies; 6+ messages in thread
From: Liam R. Howlett @ 2023-04-10 12:58 UTC (permalink / raw)
  To: Peng Zhang; +Cc: akpm, linux-mm, linux-kernel, maple-tree, David Binderman

* Peng Zhang <zhangpeng.00@bytedance.com> [230410 05:17]:
> The original code is:
> 	memset(pivs + tmp, 0, sizeof(unsigned long *) * (max_p - tmp));

Please don't quote the code for these changes.

> 
> The type of variable pointed to by pivs is unsigned long, but the type
> used in sizeof is a pointer type. Change it to unsigned long.
> 
> Suggested-by: David Binderman <dcb314@hotmail.com>
> Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>

Cc stable, fixes line is probably needed here.

Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>


> ---
>  lib/maple_tree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 88c44f6d6cee..b06fc5f19b31 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -3255,7 +3255,7 @@ static inline void mas_destroy_rebalance(struct ma_state *mas, unsigned char end
>  
>  		if (tmp < max_p)
>  			memset(pivs + tmp, 0,
> -			       sizeof(unsigned long *) * (max_p - tmp));
> +			       sizeof(unsigned long) * (max_p - tmp));
>  
>  		if (tmp < mt_slots[mt])
>  			memset(slots + tmp, 0, sizeof(void *) * (max_s - tmp));
> -- 
> 2.20.1
> 


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

* Re: [PATCH] maple_tree: Use correct variable type in sizeof
  2023-04-10 10:09   ` Peng Zhang
@ 2023-04-10 13:51     ` Matthew Wilcox
  2023-04-11 10:16     ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: Matthew Wilcox @ 2023-04-10 13:51 UTC (permalink / raw)
  To: Peng Zhang
  Cc: Gang Li, akpm, linux-mm, linux-kernel, maple-tree, David Binderman

On Mon, Apr 10, 2023 at 06:09:27PM +0800, Peng Zhang wrote:
> Maybe sizeof(void *) is equal to sizeof(unsigned long)
> in most architectures, so I don't know if it counts as a fix.

This is actually required inside the Linux kernel.  The only programming
model I know where sizeof(void *) != sizeof(unsigned long) is Windows
64-bit userspace.


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

* RE: [PATCH] maple_tree: Use correct variable type in sizeof
  2023-04-10 10:09   ` Peng Zhang
  2023-04-10 13:51     ` Matthew Wilcox
@ 2023-04-11 10:16     ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: David Laight @ 2023-04-11 10:16 UTC (permalink / raw)
  To: 'Peng Zhang', Gang Li
  Cc: akpm, linux-mm, linux-kernel, maple-tree, David Binderman

From: Peng Zhang
> Sent: 10 April 2023 11:09
> 
> 在 2023/4/10 17:46, Gang Li 写道:
> > On 2023/4/10 17:14, Peng Zhang wrote:
> >> The original code is:
> >>     memset(pivs + tmp, 0, sizeof(unsigned long *) * (max_p - tmp));
> >>
> >> The type of variable pointed to by pivs is unsigned long, but the type
> >> used in sizeof is a pointer type. Change it to unsigned long.
> >>
> >
> > Maybe add a fix tag?
> >
> > Fixes: 54a611b60590 ("Maple Tree: add new data structure")
> 
> Maybe sizeof(void *) is equal to sizeof(unsigned long)
> in most architectures, so I don't know if it counts as a fix.

Might be worth adding; "Fortunately the sizes are the same."

> >>             if (tmp < max_p)
> >>               memset(pivs + tmp, 0,
> >> -                   sizeof(unsigned long *) * (max_p - tmp));
> >> +                   sizeof(unsigned long) * (max_p - tmp));
	sizeof (*pivs)

> >>             if (tmp < mt_slots[mt])
> >>               memset(slots + tmp, 0, sizeof(void *) * (max_s - tmp));
	and sizeof (*slots)


	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

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

end of thread, other threads:[~2023-04-11 10:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-10  9:14 [PATCH] maple_tree: Use correct variable type in sizeof Peng Zhang
2023-04-10  9:46 ` Gang Li
2023-04-10 10:09   ` Peng Zhang
2023-04-10 13:51     ` Matthew Wilcox
2023-04-11 10:16     ` David Laight
2023-04-10 12:58 ` Liam R. Howlett

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