2024-02-18 06:58:11

by Li Qiang

[permalink] [raw]
Subject: [RESEND PATCH] llist: Make llist_del_first return only the first node

Set the next of the returned node of llist_del_first
to NULL, which can prevent subsequent nodes in llist
from being exposed, and is more consistent with the
logic of this interface.

Signed-off-by: liqiang <[email protected]>
---
lib/llist.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/lib/llist.c b/lib/llist.c
index f21d0cf..c33fff5 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -61,6 +61,7 @@ struct llist_node *llist_del_first(struct llist_head *head)
next = READ_ONCE(entry->next);
} while (!try_cmpxchg(&head->first, &entry, next));

+ entry->next = NULL;
return entry;
}
EXPORT_SYMBOL_GPL(llist_del_first);
--
2.23.0.windows.1



2024-02-18 07:45:39

by Huang, Ying

[permalink] [raw]
Subject: Re: [RESEND PATCH] llist: Make llist_del_first return only the first node

liqiang <[email protected]> writes:

> Set the next of the returned node of llist_del_first
> to NULL, which can prevent subsequent nodes in llist
> from being exposed, and is more consistent with the
> logic of this interface.
>
> Signed-off-by: liqiang <[email protected]>
> ---
> lib/llist.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/lib/llist.c b/lib/llist.c
> index f21d0cf..c33fff5 100644
> --- a/lib/llist.c
> +++ b/lib/llist.c
> @@ -61,6 +61,7 @@ struct llist_node *llist_del_first(struct llist_head *head)
> next = READ_ONCE(entry->next);
> } while (!try_cmpxchg(&head->first, &entry, next));
>
> + entry->next = NULL;
> return entry;
> }
> EXPORT_SYMBOL_GPL(llist_del_first);

This isn't needed for functionality correctness. Many users of llist
ask for performance. So, it may be better to let the users to decide
whether to set entry->next to NULL.

--
Best Regards,
Huang, Ying

2024-02-18 09:24:05

by Li Qiang

[permalink] [raw]
Subject: Re: [RESEND PATCH] llist: Make llist_del_first return only the first node



在 2024/2/18 15:43, Huang, Ying 写道:
> liqiang <[email protected]> writes:
>
>> Set the next of the returned node of llist_del_first
>> to NULL, which can prevent subsequent nodes in llist
>> from being exposed, and is more consistent with the
>> logic of this interface.
>>
>> Signed-off-by: liqiang <[email protected]>
>> ---
>> lib/llist.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/lib/llist.c b/lib/llist.c
>> index f21d0cf..c33fff5 100644
>> --- a/lib/llist.c
>> +++ b/lib/llist.c
>> @@ -61,6 +61,7 @@ struct llist_node *llist_del_first(struct llist_head *head)
>> next = READ_ONCE(entry->next);
>> } while (!try_cmpxchg(&head->first, &entry, next));
>>
>> + entry->next = NULL;
>> return entry;
>> }
>> EXPORT_SYMBOL_GPL(llist_del_first);
>
> This isn't needed for functionality correctness. Many users of llist
> ask for performance. So, it may be better to let the users to decide
> whether to set entry->next to NULL.
>

Ok, get it, thanks for your reply.

--
Best regards,
Li Qiang