diff mbox series

[v3,3/5] maple_tree: not necessary to check index/last again

Message ID 20241018023943.13860-4-richard.weiyang@gmail.com (mailing list archive)
State New
Headers show
Series refine storing NULL | expand

Commit Message

Wei Yang Oct. 18, 2024, 2:39 a.m. UTC
Before calling mas_new_root(), the range has been checked.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
CC: Sidhartha Kumar <sidhartha.kumar@oracle.com>
CC: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
 lib/maple_tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Liam R. Howlett Oct. 18, 2024, 5:43 p.m. UTC | #1
* Wei Yang <richard.weiyang@gmail.com> [241017 22:40]:
> Before calling mas_new_root(), the range has been checked.
> 
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
> CC: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> CC: Lorenzo Stoakes <lorenzo.stoakes@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 cbbaaf60efa9..db8b89487c98 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -3662,7 +3662,7 @@ static inline void mas_new_root(struct ma_state *mas, void *entry)
>  	void __rcu **slots;
>  	unsigned long *pivots;
>  
> -	if (!entry && !mas->index && mas->last == ULONG_MAX) {
> +	if (!entry) {

Probably good to catch anyone using this wrong with a WARN_ON_ONCE()?
It also has the effect of documenting what is going on, which is always
nice.

Sorry for not realising this earlier.

>  		mas->depth = 0;
>  		mas_set_height(mas);
>  		rcu_assign_pointer(mas->tree->ma_root, entry);
> -- 
> 2.34.1
>
Wei Yang Oct. 19, 2024, 12:28 a.m. UTC | #2
On Fri, Oct 18, 2024 at 01:43:18PM -0400, Liam R. Howlett wrote:
>* Wei Yang <richard.weiyang@gmail.com> [241017 22:40]:
>> Before calling mas_new_root(), the range has been checked.
>> 
>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
>> CC: Sidhartha Kumar <sidhartha.kumar@oracle.com>
>> CC: Lorenzo Stoakes <lorenzo.stoakes@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 cbbaaf60efa9..db8b89487c98 100644
>> --- a/lib/maple_tree.c
>> +++ b/lib/maple_tree.c
>> @@ -3662,7 +3662,7 @@ static inline void mas_new_root(struct ma_state *mas, void *entry)
>>  	void __rcu **slots;
>>  	unsigned long *pivots;
>>  
>> -	if (!entry && !mas->index && mas->last == ULONG_MAX) {
>> +	if (!entry) {
>
>Probably good to catch anyone using this wrong with a WARN_ON_ONCE()?
>It also has the effect of documenting what is going on, which is always
>nice.
>

Sure, will add a WARN_ON_ONCE().

>Sorry for not realising this earlier.
>
>>  		mas->depth = 0;
>>  		mas_set_height(mas);
>>  		rcu_assign_pointer(mas->tree->ma_root, entry);
>> -- 
>> 2.34.1
>>
diff mbox series

Patch

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index cbbaaf60efa9..db8b89487c98 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -3662,7 +3662,7 @@  static inline void mas_new_root(struct ma_state *mas, void *entry)
 	void __rcu **slots;
 	unsigned long *pivots;
 
-	if (!entry && !mas->index && mas->last == ULONG_MAX) {
+	if (!entry) {
 		mas->depth = 0;
 		mas_set_height(mas);
 		rcu_assign_pointer(mas->tree->ma_root, entry);