* [RESEND PATCH v3 1/5] dt: introduce of_get_child_by_name to get child node by name.
@ 2012-09-17 11:58 Srinivas KANDAGATLA
2012-09-17 12:58 ` Rob Herring
2012-09-17 12:59 ` Rob Herring
0 siblings, 2 replies; 3+ messages in thread
From: Srinivas KANDAGATLA @ 2012-09-17 11:58 UTC (permalink / raw)
To: robherring2, bergner, devicetree-discuss
Cc: kgene.kim, srinivas.kandagatla, broonie, afleming, ben-linux,
linuxppc-dev
From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
This patch introduces of_get_child_by_name function to get a child node
by its name in a given parent node.
Without this patch each driver code has to iterate the parent and do
a string compare, However having of_get_child_by_name libary function would
avoid code duplication, errors and is more convenient.
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
---
drivers/of/base.c | 25 +++++++++++++++++++++++++
include/linux/of.h | 2 ++
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d4a1c9a..7391f8a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -391,6 +391,31 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
EXPORT_SYMBOL(of_get_next_available_child);
/**
+ * of_get_child_by_name - Find the child node by name for a given parent
+ * @node: parent node
+ * @name: child name to look for.
+ *
+ * This function looks for child node for given matching name
+ *
+ * Returns a node pointer if found, with refcount incremented, use
+ * of_node_put() on it when done.
+ * Returns NULL if node is not found.
+ */
+
+struct device_node *of_get_child_by_name(const struct device_node *node,
+ const char *name)
+{
+ struct device_node *child;
+
+ for_each_child_of_node(node, child)
+ if (child->name && (of_node_cmp(child->name, name) == 0)
+ && of_node_get(child))
+ break;
+ return child;
+}
+EXPORT_SYMBOL(of_get_child_by_name);
+
+/**
* of_find_node_by_path - Find a node matching a full OF path
* @path: The full path to match
*
diff --git a/include/linux/of.h b/include/linux/of.h
index 1b11632..7b8e3cd 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -192,6 +192,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
struct device_node *prev);
extern struct device_node *of_get_next_available_child(
const struct device_node *node, struct device_node *prev);
+extern struct device_node *of_get_child_by_name(const struct device_node *node,
+ const char *name);
#define for_each_child_of_node(parent, child) \
for (child = of_get_next_child(parent, NULL); child != NULL; \
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RESEND PATCH v3 1/5] dt: introduce of_get_child_by_name to get child node by name.
2012-09-17 11:58 [RESEND PATCH v3 1/5] dt: introduce of_get_child_by_name to get child node by name Srinivas KANDAGATLA
@ 2012-09-17 12:58 ` Rob Herring
2012-09-17 12:59 ` Rob Herring
1 sibling, 0 replies; 3+ messages in thread
From: Rob Herring @ 2012-09-17 12:58 UTC (permalink / raw)
To: Srinivas KANDAGATLA
Cc: kgene.kim, devicetree-discuss, broonie, afleming, ben-linux,
bergner, linuxppc-dev
On 09/17/2012 06:58 AM, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Please drop the period on the subject.
>
> This patch introduces of_get_child_by_name function to get a child node
> by its name in a given parent node.
>
> Without this patch each driver code has to iterate the parent and do
> a string compare, However having of_get_child_by_name libary function would
> avoid code duplication, errors and is more convenient.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
> ---
> drivers/of/base.c | 25 +++++++++++++++++++++++++
> include/linux/of.h | 2 ++
> 2 files changed, 27 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index d4a1c9a..7391f8a 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -391,6 +391,31 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
> EXPORT_SYMBOL(of_get_next_available_child);
>
> /**
> + * of_get_child_by_name - Find the child node by name for a given parent
> + * @node: parent node
> + * @name: child name to look for.
> + *
> + * This function looks for child node for given matching name
> + *
> + * Returns a node pointer if found, with refcount incremented, use
> + * of_node_put() on it when done.
> + * Returns NULL if node is not found.
> + */
> +
Remove blank line.
> +struct device_node *of_get_child_by_name(const struct device_node *node,
> + const char *name)
> +{
> + struct device_node *child;
> +
> + for_each_child_of_node(node, child)
> + if (child->name && (of_node_cmp(child->name, name) == 0)
> + && of_node_get(child))
of_get_next_child has already called of_node_get, so you don't need to
call it here.
> + break;
> + return child;
> +}
> +EXPORT_SYMBOL(of_get_child_by_name);
> +
> +/**
> * of_find_node_by_path - Find a node matching a full OF path
> * @path: The full path to match
> *
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 1b11632..7b8e3cd 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -192,6 +192,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
> struct device_node *prev);
> extern struct device_node *of_get_next_available_child(
> const struct device_node *node, struct device_node *prev);
> +extern struct device_node *of_get_child_by_name(const struct device_node *node,
> + const char *name);
>
> #define for_each_child_of_node(parent, child) \
> for (child = of_get_next_child(parent, NULL); child != NULL; \
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RESEND PATCH v3 1/5] dt: introduce of_get_child_by_name to get child node by name.
2012-09-17 11:58 [RESEND PATCH v3 1/5] dt: introduce of_get_child_by_name to get child node by name Srinivas KANDAGATLA
2012-09-17 12:58 ` Rob Herring
@ 2012-09-17 12:59 ` Rob Herring
1 sibling, 0 replies; 3+ messages in thread
From: Rob Herring @ 2012-09-17 12:59 UTC (permalink / raw)
To: Srinivas KANDAGATLA
Cc: kgene.kim, devicetree-discuss, broonie, afleming, ben-linux,
bergner, linuxppc-dev
On 09/17/2012 06:58 AM, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Please drop the period on the subject.
>
> This patch introduces of_get_child_by_name function to get a child node
> by its name in a given parent node.
>
> Without this patch each driver code has to iterate the parent and do
> a string compare, However having of_get_child_by_name libary function would
> avoid code duplication, errors and is more convenient.
>
> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
> ---
> drivers/of/base.c | 25 +++++++++++++++++++++++++
> include/linux/of.h | 2 ++
> 2 files changed, 27 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index d4a1c9a..7391f8a 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -391,6 +391,31 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
> EXPORT_SYMBOL(of_get_next_available_child);
>
> /**
> + * of_get_child_by_name - Find the child node by name for a given parent
> + * @node: parent node
> + * @name: child name to look for.
> + *
> + * This function looks for child node for given matching name
> + *
> + * Returns a node pointer if found, with refcount incremented, use
> + * of_node_put() on it when done.
> + * Returns NULL if node is not found.
> + */
> +
Remove blank line.
> +struct device_node *of_get_child_by_name(const struct device_node *node,
> + const char *name)
> +{
> + struct device_node *child;
> +
> + for_each_child_of_node(node, child)
> + if (child->name && (of_node_cmp(child->name, name) == 0)
> + && of_node_get(child))
of_get_next_child has already called of_node_get, so you don't need to
call it here.
> + break;
> + return child;
> +}
> +EXPORT_SYMBOL(of_get_child_by_name);
> +
> +/**
> * of_find_node_by_path - Find a node matching a full OF path
> * @path: The full path to match
> *
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 1b11632..7b8e3cd 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -192,6 +192,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
> struct device_node *prev);
> extern struct device_node *of_get_next_available_child(
> const struct device_node *node, struct device_node *prev);
> +extern struct device_node *of_get_child_by_name(const struct device_node *node,
> + const char *name);
>
> #define for_each_child_of_node(parent, child) \
> for (child = of_get_next_child(parent, NULL); child != NULL; \
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-17 12:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-17 11:58 [RESEND PATCH v3 1/5] dt: introduce of_get_child_by_name to get child node by name Srinivas KANDAGATLA
2012-09-17 12:58 ` Rob Herring
2012-09-17 12:59 ` Rob Herring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).