linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* question about drivers/mtd/ubi/cdev.c
@ 2010-08-03 20:12 Julia Lawall
  2010-08-04  3:06 ` Artem Bityutskiy
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2010-08-03 20:12 UTC (permalink / raw)
  To: dedekind1, dwmw2, linux-mtd

I was wondering about the following code in the function rename_volumes in 
the file drivers/mtd/ubi/cdev.c:

list_for_each_entry(re, &rename_list, list) {
	...
        if (no_remove_needed)
                continue;
	...
        re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
	if (!re) { ... }
        re->remove = 1;
        re->desc = desc;
        list_add(&re->list, &rename_list);
	...
}

Is there a danger of repeating computation since re is redefined and moved 
back to the beginning of the list?

julia

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: question about drivers/mtd/ubi/cdev.c
  2010-08-03 20:12 question about drivers/mtd/ubi/cdev.c Julia Lawall
@ 2010-08-04  3:06 ` Artem Bityutskiy
  2010-08-04  5:48   ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Artem Bityutskiy @ 2010-08-04  3:06 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-mtd, dwmw2

On Tue, 2010-08-03 at 22:12 +0200, Julia Lawall wrote:
> I was wondering about the following code in the function rename_volumes in 
> the file drivers/mtd/ubi/cdev.c:
> 
> list_for_each_entry(re, &rename_list, list) {
> 	...
>         if (no_remove_needed)
>                 continue;
> 	...
>         re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
> 	if (!re) { ... }
>         re->remove = 1;
>         re->desc = desc;
>         list_add(&re->list, &rename_list);
> 	...
> }
> 
> Is there a danger of repeating computation since re is redefined and moved 
> back to the beginning of the list?

Hmm, the code is bogus, I do not know how it works, but it does, because
I tested it :-)

We should not use 're' as a temporary variable inside the loop. I guess
we can use 're1' instead. I'll change this later, when have time, unless
you submit a fix earlier :-)

Thanks for pointing this!

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: question about drivers/mtd/ubi/cdev.c
  2010-08-04  3:06 ` Artem Bityutskiy
@ 2010-08-04  5:48   ` Julia Lawall
  2010-08-04  6:37     ` Artem Bityutskiy
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2010-08-04  5:48 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: linux-mtd, dwmw2

On Wed, 4 Aug 2010, Artem Bityutskiy wrote:

> On Tue, 2010-08-03 at 22:12 +0200, Julia Lawall wrote:
> > I was wondering about the following code in the function rename_volumes in 
> > the file drivers/mtd/ubi/cdev.c:
> > 
> > list_for_each_entry(re, &rename_list, list) {
> > 	...
> >         if (no_remove_needed)
> >                 continue;
> > 	...
> >         re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
> > 	if (!re) { ... }
> >         re->remove = 1;
> >         re->desc = desc;
> >         list_add(&re->list, &rename_list);
> > 	...
> > }
> > 
> > Is there a danger of repeating computation since re is redefined and moved 
> > back to the beginning of the list?
> 
> Hmm, the code is bogus, I do not know how it works, but it does, because
> I tested it :-)
>
> We should not use 're' as a temporary variable inside the loop. I guess
> we can use 're1' instead. I'll change this later, when have time, unless
> you submit a fix earlier :-)

Would the proper approach be to use list_for_each_entry_safe?

julia

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: question about drivers/mtd/ubi/cdev.c
  2010-08-04  5:48   ` Julia Lawall
@ 2010-08-04  6:37     ` Artem Bityutskiy
  0 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2010-08-04  6:37 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-mtd, dwmw2

On Wed, 2010-08-04 at 07:48 +0200, Julia Lawall wrote:
> > Hmm, the code is bogus, I do not know how it works, but it does, because
> > I tested it :-)
> >
> > We should not use 're' as a temporary variable inside the loop. I guess
> > we can use 're1' instead. I'll change this later, when have time, unless
> > you submit a fix earlier :-)
> 
> Would the proper approach be to use list_for_each_entry_safe?

Yes, plus not using the iterator as a temporary variable is also a good
idea.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-04  6:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-03 20:12 question about drivers/mtd/ubi/cdev.c Julia Lawall
2010-08-04  3:06 ` Artem Bityutskiy
2010-08-04  5:48   ` Julia Lawall
2010-08-04  6:37     ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).