[alsa-devel] [PATCH -next] ASoC: Intel: Skylake: Fix to use list_for_each_safe() when delete items

weiyongjun (A) weiyongjun1 at huawei.com
Tue Apr 25 09:57:57 CEST 2017



> -----Original Message-----
> From: Vinod Koul [mailto:vinod.koul at intel.com]
> Sent: Tuesday, April 25, 2017 12:01 PM
> To: Wei Yongjun <weiyj.lk at gmail.com>
> Cc: Liam Girdwood <lgirdwood at gmail.com>; Mark Brown
> <broonie at kernel.org>; Jaroslav Kysela <perex at perex.cz>; Takashi Iwai
> <tiwai at suse.com>; Pardha Saradhi K
> <pardha.saradhi.kesapragada at intel.com>; G Kranthi
> <gudishax.kranthikumar at intel.com>; Hardik T Shah
> <hardik.t.shah at intel.com>; Jeeja KP <jeeja.kp at intel.com>; weiyongjun (A)
> <weiyongjun1 at huawei.com>; alsa-devel at alsa-project.org; linux-
> kernel at vger.kernel.org
> Subject: Re: [PATCH -next] ASoC: Intel: Skylake: Fix to use
> list_for_each_safe() when delete items
> 
> On Tue, Apr 25, 2017 at 03:28:17AM +0000, Wei Yongjun wrote:
> > From: Wei Yongjun <weiyongjun1 at huawei.com>
> >
> > Since we will remove items off the list using list_del() we need
> > to use a safe version of the list_for_each() macro aptly named
> > list_for_each_safe().
> 
> ah yes, god catch
> 
> > This is detected by Coccinelle semantic patch.
> 
> It is a good practice to include the script you used, do you mind adding
> that in the log?
> 

Sure. 

@@
iterator name list_for_each;
expression E;
expression pos, head;
identifier l;
@@
*  list_for_each(pos, head)
{
...
*  \(list_del\|list_del_init\|list_move\|list_move_tail\)(pos, ...);
... when != \(goto l; \| break; \| return E; \| return;\)
}

@@
expression E;
expression pos, head, ep;
identifier list;
identifier l;
@@
*  list_for_each(pos, head)
{
...
* ep = list_entry(pos, ..., list);
...
*  \(list_del\|list_del_init\|list_move\|list_move_tail\)(&ep->list, ...);
... when != \(goto l; \| break; \| return E; \| return;\)
}

@@
iterator name list_for_each_prev;
expression E;
expression pos, head;
identifier l;
@@
*  list_for_each_prev(pos, head)
{
...
*  \(list_del\|list_del_init\)(pos);
... when != \(goto l; \| break; \| return E; \| return;\)
}

@@
iterator name list_for_each_entry;
expression E;
expression pos, head;
identifier l, member;
@@

*  list_for_each_entry(pos, head, member)
{
...
*  \(list_del\|list_del_init\)(&pos->member);
... when != \(goto l; \| break; \| return E; \| return;\)
}

@@
iterator name list_for_each_entry_from;
expression E;
expression pos, head;
identifier l, member;
@@

*  list_for_each_entry_from(pos, head, member)
{
...
*  \(list_del\|list_del_init\)(&pos->member);
... when != \(goto l; \| break; \| return E; \| return;\)
}

@@
iterator name list_for_each_entry_reverse;
expression E;
expression pos, head;
identifier l, member;
@@

*  list_for_each_entry_reverse(pos, head, member)
{
...
*  \(list_del\|list_del_init\)(&pos->member);
... when != \(goto l; \| break; \| return E; \| return;\)
}


More information about the Alsa-devel mailing list