From: Ben Hutchings <bhutchings@solarflare.com>
To: Jiri Pirko <jpirko@redhat.com>
Cc: linux-kernel@vger.kernel.org, davem@davemloft.net,
netdev@vger.kernel.org
Subject: Re: [PATCH] list.h: add list_for_each_struct_entry macro
Date: Mon, 18 Jan 2010 17:17:13 +0000 [thread overview]
Message-ID: <1263835033.3667.23.camel@achroite.uk.solarflarecom.com> (raw)
In-Reply-To: <20100118162338.GD4229@psychotron.lab.eng.brq.redhat.com>
On Mon, 2010-01-18 at 17:23 +0100, Jiri Pirko wrote:
> When preparing to upcoming migration of mc_list (list of multicast MACs)
> to list_head, the need of traversing the list over one structure member
> appeared. I thought I'll do it locally but I decided that an intruduction
> the macro in list.h would be much clearer. Please kindly for a review.
>
> Jirka
>
> Signed-off-by: Jiri Pirko <jpirko@redhat.com>
>
> diff --git a/include/linux/list.h b/include/linux/list.h
> index 969f6e9..8350a94 100644
> --- a/include/linux/list.h
> +++ b/include/linux/list.h
> @@ -420,6 +420,22 @@ static inline void list_splice_tail_init(struct list_head *list,
> pos = list_entry(pos->member.prev, typeof(*pos), member))
>
> /**
> + * list_for_each_struct_entry - iterate over list of given type using
> + * the struct member.
> + * @pos: the type * to use as a loop cursor.
> + * @head: the head for your list.
> + * @type: the type of the struct.
> + * @posmember: the name ot the loop cursor within the struct.
> + * @member: the name of the list_struct within the struct.
> + */
> +#define list_for_each_struct_entry(pos, head, type, posmember, member) \
> + for (pos = list_entry((head)->next, type, member)->posmember; \
Surely &list_entry(...)->posmember ?
> + prefetch(container_of(pos, type, posmember)->member.next), \
> + &container_of(pos, type, posmember)->member != (head); \
It seems a bit dodgy to do this pointer arithmetic on a list node which
might be the list head.
> + pos = list_entry(container_of(pos, type, posmember)->member.next, \
> + type, member)->posmember)
My version:
#define list_for_each_struct_entry(pos, head, type, posmember, member) \
for (pos = list_empty(head) ? NULL : \
&list_first_entry(head, type, member)->posmember; \
prefetch(container_of(pos, type, posmember)->member.next), pos; \
pos = list_is_last(&container_of(pos, type, posmember)->member, \
head) ? NULL : \
&list_entry(container_of(pos, type, posmember)->member.next, \
type, member)->posmember)
Ben.
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
next prev parent reply other threads:[~2010-01-18 17:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-18 16:23 Jiri Pirko
2010-01-18 17:17 ` Ben Hutchings [this message]
2010-01-18 21:07 ` Jiri Pirko
2010-01-18 21:14 ` Ben Hutchings
2010-01-18 21:30 ` Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1263835033.3667.23.camel@achroite.uk.solarflarecom.com \
--to=bhutchings@solarflare.com \
--cc=davem@davemloft.net \
--cc=jpirko@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®