* [PATCH] of: introduces helper to manage optional property
@ 2013-12-26 5:18 Xiubo Li
[not found] ` <1388035115-893-1-git-send-email-Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
[not found] ` < 20140106162609.GG24664@e106331-lin.cambridge.arm.com>
0 siblings, 2 replies; 5+ messages in thread
From: Xiubo Li @ 2013-12-26 5:18 UTC (permalink / raw)
To: grant.likely-QSEj5FYQhm4dnm+yROfE0A,
rob.herring-bsGFqQB8/DxBDgjK7y7TUQ
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA
Gets to know whether one optional property is present or not in one
device node. Returns true if the property is present, false otherwise.
There is one similar helper of_property_read_bool(), but it means that
the property is one boolen type. For many drivers, they need to know
whether one optional property is present or not firstly. Though many
other of_XX helper can do this before deal with it's real work, there
maybe other errors the driver need to deal with, and the errors maybe
the same with the property absent error. And this helper can make the
code briefer,more readable and easier to deal with.
Signed-off-by: Xiubo Li <Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
include/linux/of.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/linux/of.h b/include/linux/of.h
index 276c546..0bd8cb9 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -601,6 +601,23 @@ static inline int of_property_read_u32(const struct device_node *np,
return of_property_read_u32_array(np, propname, out_value, 1);
}
+/**
+ * of_property_optional - Find one optional property
+ * @np: device node from which the property to be searched.
+ * @propname: name of the optional property to be searched for.
+ *
+ * Get to know whether one optional property is present or not in a
+ * device node.
+ * Returns true if the property is present, false otherwise.
+ */
+static inline bool of_property_optional(const struct device_node *np,
+ const char *propname)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ return prop ? true : false;
+}
+
#define of_property_for_each_u32(np, propname, prop, p, u) \
for (prop = of_find_property(np, propname, NULL), \
p = of_prop_next_u32(prop, NULL, &u); \
--
1.8.4
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] of: introduces helper to manage optional property
[not found] ` <1388035115-893-1-git-send-email-Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2013-12-26 14:38 ` Gerhard Sittig
[not found] ` <20131226143851.GL8064-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2014-01-06 16:26 ` Mark Rutland
1 sibling, 1 reply; 5+ messages in thread
From: Gerhard Sittig @ 2013-12-26 14:38 UTC (permalink / raw)
To: Xiubo Li
Cc: grant.likely-QSEj5FYQhm4dnm+yROfE0A,
rob.herring-bsGFqQB8/DxBDgjK7y7TUQ,
devicetree-u79uwXL29TY76Z2rM5mHXA
On Thu, Dec 26, 2013 at 13:18 +0800, Xiubo Li wrote:
>
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -601,6 +601,23 @@ static inline int of_property_read_u32(const struct device_node *np,
> return of_property_read_u32_array(np, propname, out_value, 1);
> }
>
> +/**
> + * of_property_optional - Find one optional property
> + * @np: device node from which the property to be searched.
> + * @propname: name of the optional property to be searched for.
> + *
> + * Get to know whether one optional property is present or not in a
> + * device node.
> + * Returns true if the property is present, false otherwise.
> + */
> +static inline bool of_property_optional(const struct device_node *np,
> + const char *propname)
> +{
> + struct property *prop = of_find_property(np, propname, NULL);
> +
> + return prop ? true : false;
> +}
> +
Exactly how is this different from of_property_read_bool()?
AFAICS it's identical! You may be trying to solve the wrong
problem.
And I'm afraid that the routine's name you picked is even more
confusing. The call site ("if (of_property_optional() ...") will
no longer reflect that it's evaluating a boolean condition.
Being an optional property and being boolean are two completely
different things.
virtually yours
Gerhard Sittig
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office-ynQEQJNshbs@public.gmane.org
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] of: introduces helper to manage optional property
[not found] ` <1388035115-893-1-git-send-email-Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2013-12-26 14:38 ` Gerhard Sittig
@ 2014-01-06 16:26 ` Mark Rutland
1 sibling, 0 replies; 5+ messages in thread
From: Mark Rutland @ 2014-01-06 16:26 UTC (permalink / raw)
To: Xiubo Li
Cc: grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
On Thu, Dec 26, 2013 at 05:18:35AM +0000, Xiubo Li wrote:
> Gets to know whether one optional property is present or not in one
> device node. Returns true if the property is present, false otherwise.
>
> There is one similar helper of_property_read_bool(), but it means that
> the property is one boolen type. For many drivers, they need to know
> whether one optional property is present or not firstly. Though many
> other of_XX helper can do this before deal with it's real work, there
> maybe other errors the driver need to deal with, and the errors maybe
> the same with the property absent error. And this helper can make the
> code briefer,more readable and easier to deal with.
>
> Signed-off-by: Xiubo Li <Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> ---
> include/linux/of.h | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 276c546..0bd8cb9 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -601,6 +601,23 @@ static inline int of_property_read_u32(const struct device_node *np,
> return of_property_read_u32_array(np, propname, out_value, 1);
> }
>
> +/**
> + * of_property_optional - Find one optional property
If we really do need something like this, it would be better named
of_property_present (and can alias of_property_read_bool internally).
Is there a particular case this would make easier? Do you have a real
example?
Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] of: introduces helper to manage optional property
[not found] ` <20131226143851.GL8064-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
@ 2014-01-08 7:17 ` Li.Xiubo-KZfg59tc24xl57MIdRCFDg
0 siblings, 0 replies; 5+ messages in thread
From: Li.Xiubo-KZfg59tc24xl57MIdRCFDg @ 2014-01-08 7:17 UTC (permalink / raw)
To: Gerhard Sittig; +Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> > @@ -601,6 +601,23 @@ static inline int of_property_read_u32(const struct
> device_node *np,
> > return of_property_read_u32_array(np, propname, out_value, 1);
> > }
> >
> > +/**
> > + * of_property_optional - Find one optional property
> > + * @np: device node from which the property to be searched.
> > + * @propname: name of the optional property to be searched for.
> > + *
> > + * Get to know whether one optional property is present or not in a
> > + * device node.
> > + * Returns true if the property is present, false otherwise.
> > + */
> > +static inline bool of_property_optional(const struct device_node *np,
> > + const char *propname)
> > +{
> > + struct property *prop = of_find_property(np, propname, NULL);
> > +
> > + return prop ? true : false;
> > +}
> > +
>
> Exactly how is this different from of_property_read_bool()?
> AFAICS it's identical! You may be trying to solve the wrong
> problem.
>
> And I'm afraid that the routine's name you picked is even more
> confusing. The call site ("if (of_property_optional() ...") will
> no longer reflect that it's evaluating a boolean condition.
> Being an optional property and being boolean are two completely
> different things.
>
>
Yes, That's right.
Thanks,
Best Regards,
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] of: introduces helper to manage optional property
[not found] ` <20140106162609.GG24664-NuALmloUBlrZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
@ 2014-01-16 17:26 ` Grant Likely
0 siblings, 0 replies; 5+ messages in thread
From: Grant Likely @ 2014-01-16 17:26 UTC (permalink / raw)
To: Mark Rutland, Xiubo Li
Cc: rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
On Mon, 6 Jan 2014 16:26:09 +0000, Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org> wrote:
> On Thu, Dec 26, 2013 at 05:18:35AM +0000, Xiubo Li wrote:
> > Gets to know whether one optional property is present or not in one
> > device node. Returns true if the property is present, false otherwise.
> >
> > There is one similar helper of_property_read_bool(), but it means that
> > the property is one boolen type. For many drivers, they need to know
> > whether one optional property is present or not firstly. Though many
> > other of_XX helper can do this before deal with it's real work, there
> > maybe other errors the driver need to deal with, and the errors maybe
> > the same with the property absent error. And this helper can make the
> > code briefer,more readable and easier to deal with.
> >
> > Signed-off-by: Xiubo Li <Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > ---
> > include/linux/of.h | 17 +++++++++++++++++
> > 1 file changed, 17 insertions(+)
> >
> > diff --git a/include/linux/of.h b/include/linux/of.h
> > index 276c546..0bd8cb9 100644
> > --- a/include/linux/of.h
> > +++ b/include/linux/of.h
> > @@ -601,6 +601,23 @@ static inline int of_property_read_u32(const struct device_node *np,
> > return of_property_read_u32_array(np, propname, out_value, 1);
> > }
> >
> > +/**
> > + * of_property_optional - Find one optional property
>
> If we really do need something like this, it would be better named
> of_property_present (and can alias of_property_read_bool internally).
I would rather not add an alias or new function for this is possible
given that existing functions (of_find_property and
of_property_read_bool provide the same behavour)
g.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-01-16 17:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-26 5:18 [PATCH] of: introduces helper to manage optional property Xiubo Li
[not found] ` <1388035115-893-1-git-send-email-Li.Xiubo-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2013-12-26 14:38 ` Gerhard Sittig
[not found] ` <20131226143851.GL8064-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2014-01-08 7:17 ` Li.Xiubo-KZfg59tc24xl57MIdRCFDg
2014-01-06 16:26 ` Mark Rutland
[not found] ` < 20140106162609.GG24664@e106331-lin.cambridge.arm.com>
[not found] ` <20140106162609.GG24664-NuALmloUBlrZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2014-01-16 17:26 ` Grant Likely
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).