Skip to contentSkip to conversation

question about lists

DISCUSSION Julia Lawall 3 participants 5 messages May 3, 2020 – May 5, 2020 Kernel janitors

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
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_add will initialize both fields of the list_head structure without looking at their values, so why is the INIT_LIST_HEAD needed?

Yeah. You're right. It's not needed.

regards,
dan carpenter

#2 lore raw
In reply to Julia Lawall
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_add will initialize both fields of the list_head structure without looking at their values, so why is the INIT_LIST_HEAD needed?

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

#3 lore raw
In reply to Julia Lawall

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_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

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

#4 lore raw
In reply to Julia Lawall
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