2003-05-04 07:45:03

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: [PATCH] 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 use
list_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(+)


diff -Nru a/include/linux/list.h b/include/linux/list.h
--- a/include/linux/list.h Sun May 4 04:43:59 2003
+++ b/include/linux/list.h Sun May 4 04:43:59 2003
@@ -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=,&


2003-05-04 14:45:46

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] list.h: implement list_for_each_entry_safe

On Sun, 2003-05-04 at 00:57, Arnaldo Carvalho de Melo wrote:
> [email protected], 2003-05-04 04:39:21-03:00, [email protected]
> o list.h: implement list_for_each_entry_safe

Exists already, there is even a _rcu version.

--
David S. Miller <[email protected]>

2003-05-04 21:13:01

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] list.h: implement list_for_each_entry_safe

Em Sun, May 04, 2003 at 05:50:32AM -0700, David S. Miller escreveu:
> On Sun, 2003-05-04 at 00:57, Arnaldo Carvalho de Melo wrote:
> > [email protected], 2003-05-04 04:39:21-03:00, [email protected]
> > o list.h: implement list_for_each_entry_safe
>
> Exists already, there is even a _rcu version.

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

2003-05-04 21:14:40

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] list.h: implement list_for_each_entry_safe

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:
> On Sun, 2003-05-04 at 00:57, Arnaldo Carvalho de Melo wrote:
> > [email protected], 2003-05-04 04:39:21-03:00, [email protected]
> > o list.h: implement list_for_each_entry_safe
>
> Exists already, there is even a _rcu version.

Huh? Where is that? :-)

I misread your email, sorry. Your patch is ok.