* Re: question about lists
2020-05-03 21:10 question about lists Julia Lawall
@ 2020-05-04 19:23 ` Dan Carpenter
2020-05-04 19:28 ` Julia Lawall
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2020-05-04 19:23 UTC (permalink / raw)
To: kernel-janitors
On Sun, May 03, 2020 at 11:10:01PM +0200, Julia Lawall wrote:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: question about lists
2020-05-03 21:10 question about lists Julia Lawall
2020-05-04 19:23 ` Dan Carpenter
@ 2020-05-04 19:28 ` Julia Lawall
2020-05-04 19:41 ` Christophe JAILLET
2020-05-05 8:35 ` Dan Carpenter
3 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2020-05-04 19:28 UTC (permalink / raw)
To: kernel-janitors
On Mon, 4 May 2020, Dan Carpenter wrote:
> On Sun, May 03, 2020 at 11:10:01PM +0200, Julia Lawall wrote:
> > 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.
OK, there seem to be a good number of them, so I wondered if I missed
something.
thanks,
julia
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about lists
2020-05-03 21:10 question about lists Julia Lawall
2020-05-04 19:23 ` Dan Carpenter
2020-05-04 19:28 ` Julia Lawall
@ 2020-05-04 19:41 ` Christophe JAILLET
2020-05-05 8:35 ` Dan Carpenter
3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2020-05-04 19:41 UTC (permalink / raw)
To: kernel-janitors
Le 03/05/2020 à 23:10, Julia Lawall a écrit :
> 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
>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about lists
2020-05-03 21:10 question about lists Julia Lawall
` (2 preceding siblings ...)
2020-05-04 19:41 ` Christophe JAILLET
@ 2020-05-05 8:35 ` Dan Carpenter
3 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2020-05-05 8:35 UTC (permalink / raw)
To: kernel-janitors
On Mon, May 04, 2020 at 09:41:21PM +0200, Christophe JAILLET wrote:
> - 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
^ permalink raw reply [flat|nested] 5+ messages in thread