list.h: implement list_for_each_entry_safe
PATCH 1/1 list.h: implement list_for_each_entry_safe
Hi Linus,
Please consider pulling from:
bk://kernel.bkbits.net/acme/list-2.5
I started converting IPX to struct list_head and also to uselist_for_eache_entry to simplify the code in the network families I maintain, and in IPX I need the _safe variation for list_for_eache_entry.
- Arnaldo
You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual.
===================================================================
[email protected], 2003-05-04 04:39:21-03:00, [email protected]
o list.h: implement list_for_each_entry_safe
list.h | 13 +++++++++++++ 1 files changed, 13 insertions(+)
include/linux/list.h +13 -0
@@ -297,6 +297,19 @@ prefetch(pos->member.next))/** +* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry +* @pos: the type * to use as a loop counter. +* @n: another type * to use as temporary storage +* @head: the head for your list. +* @member: the name of the list_struct within the struct. +*/ +#define list_for_each_entry_safe (pos, n, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.next, typeof(*n), member)) + +/** * list_for_each_rcu - iterate over an rcu-protected list * @pos: the &struct list_head to use as a loop counter. * @head: the head for your list.
===================================================================
This BitKeeper patch contains the following changesets:
1.1219
## Wrapped with gzip_uu ##
M'XL( +_$M#X \U5T6K;,!1]MK[BCL)HLMB1+#N)75*R=F,;':QT]*T05%N. MS6PIR$K:@#]^D@QMUS8M*WN8XP=S=8[.N4<7Y0 N6ZY2CV4-1P?P5;8Z]3(I M>*:K+0LRV037RBQ<2&D6QJ5L^/CD;%Q7K?;#($9FZ9SIK(0M5VWJD8#>5?1N MS5/OXO.7R^\?+Q":S^&T9&+%?W(-\SG24FU9G;<+ILM:BD K)MJ&:R?:W4&[ M$./0_&(RI3B>=&2"HVF7D9P0%A&>XS":32*D9,U$OE \+YE^NH.AX@B3&).D M"RFE!'T"$I"0)(#I&,=C' &.4IJD(?$Q33$&F\CB<1+P@8"/T0G\6_>G* ,) M-M2@3*%JUC5ON-"NLBRD6G*6E4M34;MERPJ.SB"D492@\_M,D?^7#T*8873\
M2BN5R.I-SLV)B\WMN+?XL*N$FD0)H7$7QEF>7<<XGX5QP2EY/L&]&_9'-*41 MG77A))E2-S+/H5^?GK>;1FW)FZ8RD:J%;/,ZD&KU@N6(8CR-9YAT4823R$U5 M^&BFS#M[9:;H_S)4+O<?X*L;]YHA.7_V"-XP;-_") %"$0SW.@ ?*LT5TQRD MN4\<#F0!JVK+A;M/P,'8BE7"+"G>2!.8A3BHV\D*+-;27$:ZY#UI:)*%36N( M+3"HI5Q#)C?"2 4.+5+/8T(:O'I*T+Q92\74#EIS/FS%':7D+.\5[!>89F G M-[WE?M.&-]?V9K48P1IN7=IOUWRKU2;3<%/ILA*NW%<L=8P.<EY4@N_-Z="T M-P(Q<MHCZ)4&GN==(<\ZL>LP[^F.=7AHD0/_6/!;/7(]RN)P:&"#._K(LCWQ M)\\@_.,>$+S /;)<L,_[!PQX-X=>^ @\K[?G0+T]X_^1FMBC)>Z5!N@*C8?# :^_^=K.39KW;3S*=LQHIBDJ#?TWDGY=,&
Quoted 2 lines · Arnaldo Carvalho de Melo
[email protected], 2003-05-04 04:39:21-03:00, [email protected]
olist.h: implementlist_for_each_entry_safe
Exists already, there is even a _rcu version.
Signature · 1 line
David S. Miller <[email protected]>
Em Sun, May 04, 2003 at 05:50:32AM -0700, David S. Miller escreveu:
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 2 lines
[email protected], 2003-05-04 04:39:21-03:00, [email protected]
olist.h: implementlist_for_each_entry_safeExists already, there is even a
_rcuversion.
Huh? Where is that? :-)
There is list_for_each_entry and list_for_each_entry_rcu, but not list_for_each_entry_safe nor, for that matter, list_for_each_entry_safe_rcu.
list_for_each_entry was introduced not so long ago by Rusty, AFAIK, so that we can simplify traversing lists that before, with just list_for_each & _safe and _rcu variations required that we use a struct list_head as the loop iteration variable and have as well another variable of the type contained in the list, like this:
struct llc_sap *llc_sap_find(u8 sap_value)
{
struct llc_sap* sap = NULL;
struct list_head *entry;
list_for_each(entry, &llc_main_station.sap_list.list) {
sap = list_entry(entry, struct llc_sap, node);
if (sap->laddr.lsap == sap_value)
goto out;
}
sap = NULL;
out:
return sap;
}Using the _entry variation this can (and will) be converted to
struct llc_sap *llc_sap_find(u8 sap_value)
{
struct llc_sap* sap;
list_for_each_entry(sap, &llc_main_station.sap_list.list, node)
if (sap->laddr.lsap == sap_value)
goto out;
sap = NULL;
out:
return sap;
}But then we need (at least I need for IPX, maybe others) the _entry_safe (and most likely, at least initially for completeness, the _entry_safe_rcu) variations. This is what I'm submitting :)
- Arnaldo
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Sun, 4 May 2003 18:24:38 -0300
Em Sun, May 04, 2003 at 05:50:32AM -0700, David S. Miller escreveu:
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 2 lines
[email protected], 2003-05-04 04:39:21-03:00, [email protected]
olist.h: implementlist_for_each_entry_safeExists already, there is even a
_rcuversion.
Huh? Where is that? :-)
I misread your email, sorry. Your patch is ok.