question about lists
Hello,
I was wondering what is the point of code like the following:
INIT_LIST_HEAD(&bb->list);
list_add(&bb->list, &s->workload->shadow_bb);As far as I can see, list_add will initialize both fields of the list_head structure without looking at their values, so why is the INIT_LIST_HEAD needed?
thanks,
julia
Quoted 10 lines · Julia Lawall
Hello,
I was wondering what is the point of code like the following:
INIT_LIST_HEAD(&bb->list); list_add(&bb->list, &s->workload->shadow_bb);As far as I can see,
list_addwill initialize both fields of thelist_headstructure without looking at their values, so why is theINIT_LIST_HEADneeded?
Yeah. You're right. It's not needed.
regards,
dan carpenter
Quoted 5 lines · Dan Carpenter
Quoted 4 lines · Julia Lawall
Hello,
I was wondering what is the point of code like the following:
Quoted 8 lines
Quoted 6 lines
INIT_LIST_HEAD(&bb->list); list_add(&bb->list, &s->workload->shadow_bb);As far as I can see,
list_addwill initialize both fields of thelist_headstructure without looking at their values, so why is theINIT_LIST_HEADneeded?Yeah. You're right. It's not needed.
OK, there seem to be a good number of them, so I wondered if I missed something.
thanks,
julia
Le 03/05/2020 à 23:10, Julia Lawall a écrit :
Quoted 7 lines
Hello,
I was wondering what is the point of code like the following:
INIT_LIST_HEAD(&bb->list); list_add(&bb->list, &s->workload->shadow_bb);
Quoted 7 lines
As far as I can see,
list_addwill initialize both fields of thelist_headstructure without looking at their values, so why is theINIT_LIST_HEADneeded?thanks,
julia
Hi,
I agree with you. I don't see the need of 'INIT_LIST_HEAD' here.
The only reasons I could see are:
- initializing an "object" looks a safe thing to do before using it,
even if useless.
- in your example, before commit f52c380a48f52, it was allocated
with kmalloc, so it was maybe to avoid a really unlikely '__list_add_valid' failure. Now that it is kzalloc'ed, this can not happen anymore.
Just my 2c.
CJ
Quoted 3 lines · Christophe JAILLET
- in your example, before commit
f52c380a48f52, it was allocated with kmalloc, so it was maybe to avoid a really unlikely '__list_add_valid' failure. Now that it is kzalloc'ed, this can not happen anymore.
No, it was never possible to get a __list_add_valid() failure. The list you're adding to has to be initialized, but the list item that doesn't. In __list_add_valid() the "new" is "&entry_obj->list" which is an offset into the entry_obj object.
regards,
dan carpenter