From: Rob Herring <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
Cc: John Stultz <johnstul-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>,
Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
Grant Likely
<grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>,
Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>,
Thomas Petazzoni
<thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
Josh Cartwright
<josh.cartwright-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH V4 1/3] of: introduce for_each_matching_node_and_match()
Date: Tue, 20 Nov 2012 17:52:04 -0600 [thread overview]
Message-ID: <50AC17A4.2040507@gmail.com> (raw)
In-Reply-To: <1353453142-4973-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
On 11/20/2012 05:12 PM, Stephen Warren wrote:
> From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>
> The following pattern of code is tempting:
>
> for_each_matching_node(np, table) {
> match = of_match_node(table, np);
>
> However, this results in iterating over table twice; the second time
> inside of_match_node(). The implementation of for_each_matching_node()
> already found the match, so this is redundant. Invent new function
> of_find_matching_node_and_match() and macro
> for_each_matching_node_and_match() to remove the double iteration,
> thus transforming the above code to:
>
> for_each_matching_node_and_match(np, table, &match)
>
> Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---
> v4: New patch.
>
> This series is based on the ARM sys_timer rework that I posted yesterday,
> although patch 1/3 should be completely independant of that, and could
> perhaps even be applied for 3.8 right now.
Agreed. I will apply for 3.8 assuming no further comments in the next
few days.
Rob
> I hope that these patches can be taken through arm-soc tree for 3.9;
> I will repost them based on 3.8-rc1 at the appropriate time.
> ---
> drivers/of/base.c | 18 +++++++++++++-----
> include/linux/of.h | 15 +++++++++++++--
> 2 files changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index f2f63c8..094271e 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -594,27 +594,35 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
> EXPORT_SYMBOL(of_match_node);
>
> /**
> - * of_find_matching_node - Find a node based on an of_device_id match
> - * table.
> + * of_find_matching_node_and_match - Find a node based on an of_device_id
> + * match table.
> * @from: The node to start searching from or NULL, the node
> * you pass will not be searched, only the next one
> * will; typically, you pass what the previous call
> * returned. of_node_put() will be called on it
> * @matches: array of of device match structures to search in
> + * @match Updated to point at the matches entry which matched
> *
> * Returns a node pointer with refcount incremented, use
> * of_node_put() on it when done.
> */
> -struct device_node *of_find_matching_node(struct device_node *from,
> - const struct of_device_id *matches)
> +struct device_node *of_find_matching_node_and_match(struct device_node *from,
> + const struct of_device_id *matches,
> + const struct of_device_id **match)
> {
> struct device_node *np;
>
> + if (match)
> + *match = NULL;
> +
> read_lock(&devtree_lock);
> np = from ? from->allnext : allnodes;
> for (; np; np = np->allnext) {
> - if (of_match_node(matches, np) && of_node_get(np))
> + if (of_match_node(matches, np) && of_node_get(np)) {
> + if (match)
> + *match = matches;
> break;
> + }
> }
> of_node_put(from);
> read_unlock(&devtree_lock);
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 681a6c8..1000496 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -180,11 +180,22 @@ extern struct device_node *of_find_compatible_node(struct device_node *from,
> #define for_each_compatible_node(dn, type, compatible) \
> for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
> dn = of_find_compatible_node(dn, type, compatible))
> -extern struct device_node *of_find_matching_node(struct device_node *from,
> - const struct of_device_id *matches);
> +extern struct device_node *of_find_matching_node_and_match(
> + struct device_node *from,
> + const struct of_device_id *matches,
> + const struct of_device_id **match);
> +static inline struct device_node *of_find_matching_node(
> + struct device_node *from,
> + const struct of_device_id *matches)
> +{
> + return of_find_matching_node_and_match(from, matches, NULL);
> +}
> #define for_each_matching_node(dn, matches) \
> for (dn = of_find_matching_node(NULL, matches); dn; \
> dn = of_find_matching_node(dn, matches))
> +#define for_each_matching_node_and_match(dn, matches, match) \
> + for (dn = of_find_matching_node_and_match(NULL, matches, match); \
> + dn; dn = of_find_matching_node_and_match(dn, matches, match))
> extern struct device_node *of_find_node_by_path(const char *path);
> extern struct device_node *of_find_node_by_phandle(phandle handle);
> extern struct device_node *of_get_parent(const struct device_node *node);
>
WARNING: multiple messages have this Message-ID (diff)
From: robherring2@gmail.com (Rob Herring)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V4 1/3] of: introduce for_each_matching_node_and_match()
Date: Tue, 20 Nov 2012 17:52:04 -0600 [thread overview]
Message-ID: <50AC17A4.2040507@gmail.com> (raw)
In-Reply-To: <1353453142-4973-1-git-send-email-swarren@wwwdotorg.org>
On 11/20/2012 05:12 PM, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> The following pattern of code is tempting:
>
> for_each_matching_node(np, table) {
> match = of_match_node(table, np);
>
> However, this results in iterating over table twice; the second time
> inside of_match_node(). The implementation of for_each_matching_node()
> already found the match, so this is redundant. Invent new function
> of_find_matching_node_and_match() and macro
> for_each_matching_node_and_match() to remove the double iteration,
> thus transforming the above code to:
>
> for_each_matching_node_and_match(np, table, &match)
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
> v4: New patch.
>
> This series is based on the ARM sys_timer rework that I posted yesterday,
> although patch 1/3 should be completely independant of that, and could
> perhaps even be applied for 3.8 right now.
Agreed. I will apply for 3.8 assuming no further comments in the next
few days.
Rob
> I hope that these patches can be taken through arm-soc tree for 3.9;
> I will repost them based on 3.8-rc1 at the appropriate time.
> ---
> drivers/of/base.c | 18 +++++++++++++-----
> include/linux/of.h | 15 +++++++++++++--
> 2 files changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index f2f63c8..094271e 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -594,27 +594,35 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
> EXPORT_SYMBOL(of_match_node);
>
> /**
> - * of_find_matching_node - Find a node based on an of_device_id match
> - * table.
> + * of_find_matching_node_and_match - Find a node based on an of_device_id
> + * match table.
> * @from: The node to start searching from or NULL, the node
> * you pass will not be searched, only the next one
> * will; typically, you pass what the previous call
> * returned. of_node_put() will be called on it
> * @matches: array of of device match structures to search in
> + * @match Updated to point at the matches entry which matched
> *
> * Returns a node pointer with refcount incremented, use
> * of_node_put() on it when done.
> */
> -struct device_node *of_find_matching_node(struct device_node *from,
> - const struct of_device_id *matches)
> +struct device_node *of_find_matching_node_and_match(struct device_node *from,
> + const struct of_device_id *matches,
> + const struct of_device_id **match)
> {
> struct device_node *np;
>
> + if (match)
> + *match = NULL;
> +
> read_lock(&devtree_lock);
> np = from ? from->allnext : allnodes;
> for (; np; np = np->allnext) {
> - if (of_match_node(matches, np) && of_node_get(np))
> + if (of_match_node(matches, np) && of_node_get(np)) {
> + if (match)
> + *match = matches;
> break;
> + }
> }
> of_node_put(from);
> read_unlock(&devtree_lock);
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 681a6c8..1000496 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -180,11 +180,22 @@ extern struct device_node *of_find_compatible_node(struct device_node *from,
> #define for_each_compatible_node(dn, type, compatible) \
> for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
> dn = of_find_compatible_node(dn, type, compatible))
> -extern struct device_node *of_find_matching_node(struct device_node *from,
> - const struct of_device_id *matches);
> +extern struct device_node *of_find_matching_node_and_match(
> + struct device_node *from,
> + const struct of_device_id *matches,
> + const struct of_device_id **match);
> +static inline struct device_node *of_find_matching_node(
> + struct device_node *from,
> + const struct of_device_id *matches)
> +{
> + return of_find_matching_node_and_match(from, matches, NULL);
> +}
> #define for_each_matching_node(dn, matches) \
> for (dn = of_find_matching_node(NULL, matches); dn; \
> dn = of_find_matching_node(dn, matches))
> +#define for_each_matching_node_and_match(dn, matches, match) \
> + for (dn = of_find_matching_node_and_match(NULL, matches, match); \
> + dn; dn = of_find_matching_node_and_match(dn, matches, match))
> extern struct device_node *of_find_node_by_path(const char *path);
> extern struct device_node *of_find_node_by_phandle(phandle handle);
> extern struct device_node *of_get_parent(const struct device_node *node);
>
WARNING: multiple messages have this Message-ID (diff)
From: Rob Herring <robherring2@gmail.com>
To: Stephen Warren <swarren@wwwdotorg.org>
Cc: John Stultz <johnstul@us.ibm.com>,
Thomas Gleixner <tglx@linutronix.de>,
Grant Likely <grant.likely@secretlab.ca>,
Rob Herring <rob.herring@calxeda.com>,
Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
Josh Cartwright <josh.cartwright@gmail.com>,
Stephen Warren <swarren@nvidia.com>,
Arnd Bergmann <arnd@arndb.de>,
linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org,
Olof Johansson <olof@lixom.net>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH V4 1/3] of: introduce for_each_matching_node_and_match()
Date: Tue, 20 Nov 2012 17:52:04 -0600 [thread overview]
Message-ID: <50AC17A4.2040507@gmail.com> (raw)
In-Reply-To: <1353453142-4973-1-git-send-email-swarren@wwwdotorg.org>
On 11/20/2012 05:12 PM, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> The following pattern of code is tempting:
>
> for_each_matching_node(np, table) {
> match = of_match_node(table, np);
>
> However, this results in iterating over table twice; the second time
> inside of_match_node(). The implementation of for_each_matching_node()
> already found the match, so this is redundant. Invent new function
> of_find_matching_node_and_match() and macro
> for_each_matching_node_and_match() to remove the double iteration,
> thus transforming the above code to:
>
> for_each_matching_node_and_match(np, table, &match)
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
> v4: New patch.
>
> This series is based on the ARM sys_timer rework that I posted yesterday,
> although patch 1/3 should be completely independant of that, and could
> perhaps even be applied for 3.8 right now.
Agreed. I will apply for 3.8 assuming no further comments in the next
few days.
Rob
> I hope that these patches can be taken through arm-soc tree for 3.9;
> I will repost them based on 3.8-rc1 at the appropriate time.
> ---
> drivers/of/base.c | 18 +++++++++++++-----
> include/linux/of.h | 15 +++++++++++++--
> 2 files changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index f2f63c8..094271e 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -594,27 +594,35 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
> EXPORT_SYMBOL(of_match_node);
>
> /**
> - * of_find_matching_node - Find a node based on an of_device_id match
> - * table.
> + * of_find_matching_node_and_match - Find a node based on an of_device_id
> + * match table.
> * @from: The node to start searching from or NULL, the node
> * you pass will not be searched, only the next one
> * will; typically, you pass what the previous call
> * returned. of_node_put() will be called on it
> * @matches: array of of device match structures to search in
> + * @match Updated to point at the matches entry which matched
> *
> * Returns a node pointer with refcount incremented, use
> * of_node_put() on it when done.
> */
> -struct device_node *of_find_matching_node(struct device_node *from,
> - const struct of_device_id *matches)
> +struct device_node *of_find_matching_node_and_match(struct device_node *from,
> + const struct of_device_id *matches,
> + const struct of_device_id **match)
> {
> struct device_node *np;
>
> + if (match)
> + *match = NULL;
> +
> read_lock(&devtree_lock);
> np = from ? from->allnext : allnodes;
> for (; np; np = np->allnext) {
> - if (of_match_node(matches, np) && of_node_get(np))
> + if (of_match_node(matches, np) && of_node_get(np)) {
> + if (match)
> + *match = matches;
> break;
> + }
> }
> of_node_put(from);
> read_unlock(&devtree_lock);
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 681a6c8..1000496 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -180,11 +180,22 @@ extern struct device_node *of_find_compatible_node(struct device_node *from,
> #define for_each_compatible_node(dn, type, compatible) \
> for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
> dn = of_find_compatible_node(dn, type, compatible))
> -extern struct device_node *of_find_matching_node(struct device_node *from,
> - const struct of_device_id *matches);
> +extern struct device_node *of_find_matching_node_and_match(
> + struct device_node *from,
> + const struct of_device_id *matches,
> + const struct of_device_id **match);
> +static inline struct device_node *of_find_matching_node(
> + struct device_node *from,
> + const struct of_device_id *matches)
> +{
> + return of_find_matching_node_and_match(from, matches, NULL);
> +}
> #define for_each_matching_node(dn, matches) \
> for (dn = of_find_matching_node(NULL, matches); dn; \
> dn = of_find_matching_node(dn, matches))
> +#define for_each_matching_node_and_match(dn, matches, match) \
> + for (dn = of_find_matching_node_and_match(NULL, matches, match); \
> + dn; dn = of_find_matching_node_and_match(dn, matches, match))
> extern struct device_node *of_find_node_by_path(const char *path);
> extern struct device_node *of_find_node_by_phandle(phandle handle);
> extern struct device_node *of_get_parent(const struct device_node *node);
>
next prev parent reply other threads:[~2012-11-20 23:52 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-20 23:12 [PATCH V4 1/3] of: introduce for_each_matching_node_and_match() Stephen Warren
2012-11-20 23:12 ` Stephen Warren
2012-11-20 23:12 ` Stephen Warren
[not found] ` <1353453142-4973-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-11-20 23:12 ` [PATCH V4 2/3] clocksource: add common of_clksrc_init() function Stephen Warren
2012-11-20 23:12 ` Stephen Warren
2012-11-20 23:12 ` Stephen Warren
[not found] ` <1353453142-4973-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-01-02 18:16 ` Stephen Warren
2013-01-02 18:16 ` Stephen Warren
2013-01-02 18:16 ` Stephen Warren
2012-11-20 23:12 ` [PATCH V4 3/3] ARM: tegra: move timer.c to drivers/clocksource/ Stephen Warren
2012-11-20 23:12 ` Stephen Warren
2012-11-20 23:12 ` Stephen Warren
[not found] ` <1353453142-4973-3-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-01-02 18:21 ` Stephen Warren
2013-01-02 18:21 ` Stephen Warren
2013-01-02 18:21 ` Stephen Warren
2012-11-20 23:52 ` Rob Herring [this message]
2012-11-20 23:52 ` [PATCH V4 1/3] of: introduce for_each_matching_node_and_match() Rob Herring
2012-11-20 23:52 ` Rob Herring
2012-11-21 9:53 ` Arnd Bergmann
2012-11-21 9:53 ` Arnd Bergmann
2012-11-21 9:53 ` Arnd Bergmann
[not found] ` <201211210953.20552.arnd-r2nGTMty4D4@public.gmane.org>
2012-11-21 10:06 ` Grant Likely
2012-11-21 10:06 ` Grant Likely
2012-11-21 10:06 ` Grant Likely
2012-11-21 10:09 ` Thomas Petazzoni
2012-11-21 10:09 ` Thomas Petazzoni
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=50AC17A4.2040507@gmail.com \
--to=robherring2-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=arnd-r2nGTMty4D4@public.gmane.org \
--cc=grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org \
--cc=johnstul-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
--cc=josh.cartwright-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org \
--cc=rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org \
--cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
--cc=swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
--cc=thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.