Skip to content

Commit

Permalink
net/rfkill/core.c: Avoid leaving freed data in a list
Browse files Browse the repository at this point in the history
The list_for_each_entry loop can fail, in which case the list element is
not removed from the list rfkill_fds.  Since this list is not accessed by
the loop, the addition of &data->list into the list is just moved after the
loop.

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

// <smpl>
@@
expression E,E1,E2;
identifier l;
@@

*list_add(&E->l,E1);
... when != E1
    when != list_del(&E->l)
    when != list_del_init(&E->l)
    when != E = E2
*kfree(E);// </smpl>

Signed-off-by: Julia Lawall <[email protected]>
Signed-off-by: John W. Linville <[email protected]>
  • Loading branch information
Julia Lawall authored and linvjw committed May 16, 2011
1 parent 40b275b commit bd2281b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/rfkill/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,6 @@ static int rfkill_fop_open(struct inode *inode, struct file *file)
* start getting events from elsewhere but hold mtx to get
* startup events added first
*/
list_add(&data->list, &rfkill_fds);

list_for_each_entry(rfkill, &rfkill_list, node) {
ev = kzalloc(sizeof(*ev), GFP_KERNEL);
Expand All @@ -1033,6 +1032,7 @@ static int rfkill_fop_open(struct inode *inode, struct file *file)
rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD);
list_add_tail(&ev->list, &data->events);
}
list_add(&data->list, &rfkill_fds);
mutex_unlock(&data->mtx);
mutex_unlock(&rfkill_global_mutex);

Expand Down

0 comments on commit bd2281b

Please sign in to comment.