Skip to content

Commit

Permalink
UBI: eliminate update of list_for_each_entry loop cursor
Browse files Browse the repository at this point in the history
list_for_each_entry uses its first argument to move from one element to the
next, so modifying it can break the iteration.  The variable re1 is already
used within the loop as a temporary variable, and is not live here.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
iterator name list_for_each_entry;
expression x,E;
position p1,p2;
@@

list_for_each_entry@p1(x,...) { <... x =@p2 E ...> }

@@
expression x,E;
position r.p1,r.p2;
statement S;
@@

*x =@p2 E
...
list_for_each_entry@p1(x,...) S
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
  • Loading branch information
Julia Lawall authored and Artem Bityutskiy committed Aug 30, 2010
1 parent 2bfc96a commit 01ebc12
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions drivers/mtd/ubi/cdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,18 +798,18 @@ static int rename_volumes(struct ubi_device *ubi,
goto out_free;
}

re = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
if (!re) {
re1 = kzalloc(sizeof(struct ubi_rename_entry), GFP_KERNEL);
if (!re1) {
err = -ENOMEM;
ubi_close_volume(desc);
goto out_free;
}

re->remove = 1;
re->desc = desc;
list_add(&re->list, &rename_list);
re1->remove = 1;
re1->desc = desc;
list_add(&re1->list, &rename_list);
dbg_msg("will remove volume %d, name \"%s\"",
re->desc->vol->vol_id, re->desc->vol->name);
re1->desc->vol->vol_id, re1->desc->vol->name);
}

mutex_lock(&ubi->device_mutex);
Expand Down

0 comments on commit 01ebc12

Please sign in to comment.