From: grant.likely@secretlab.ca (Grant Likely)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/1] of: introduce helper to manage boolean
Date: Thu, 08 Mar 2012 18:44:41 -0700 [thread overview]
Message-ID: <20120309014441.8236B3E0903@localhost> (raw)
In-Reply-To: <1328588028-24766-1-git-send-email-plagnioj@jcrosoft.com>
On Tue, 7 Feb 2012 05:13:48 +0100, Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> wrote:
> of_property_read_bool
>
> Search for a property in a device node and read a 32-bit value from
> it. Returns 0 if <0> or if the property does not exist, 1 if <1> or none.
>
> this will allow to disable a boolean
>
> is-ok; => true
> is-ok = <1>; => true
> is-ok = <0>; => false
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> Cc: devicetree-discuss at lists.ozlabs.org
> ---
> Hi,
>
> if this is ok I'll rebase my mtd and i2c patch to use it
>
> Best Regards,
> J.
> drivers/of/base.c | 30 ++++++++++++++++++++++++++++++
> include/linux/of.h | 8 ++++++++
> 2 files changed, 38 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 133908a..a0eaf08 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -686,6 +686,36 @@ int of_property_read_u64(const struct device_node *np, const char *propname,
> EXPORT_SYMBOL_GPL(of_property_read_u64);
>
> /**
> + * of_property_read_bool - Find and read a boolean from a property
> + * @np: device node from which the property value is to be read.
> + * @propname: name of the property to be searched.
> + *
> + * Search for a property in a device node and read a 32-bit value from
> + * it. Returns 0 if <0> or if the property does not exist, 1 if <1> or none.
> + *
> + * is-ok; => true
> + * is-ok = <1>; => true
> + * is-ok = <0>; => false
> + */
> +int of_property_read_bool(const struct device_node *np, const char *propname)
> +{
> + u32 reg;
> + int ret = of_property_read_u32(np, propname, ®);
> +
> + switch (ret) {
> + case -EINVAL:
> + return false;
> + case -ENODATA:
> + return true;
> + case 0:
> + return reg == 1;
Ugh. so any value other than 1 returns false? I think that will surprise
most people.
I don't like this api or binding. If it is a bool property, then why isn't
simply testing for the property existance sufficient?
g.
WARNING: multiple messages have this Message-ID (diff)
From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: Jean-Christophe PLAGNIOL-VILLARD
<plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
Subject: Re: [PATCH 1/1] of: introduce helper to manage boolean
Date: Thu, 08 Mar 2012 18:44:41 -0700 [thread overview]
Message-ID: <20120309014441.8236B3E0903@localhost> (raw)
In-Reply-To: <1328588028-24766-1-git-send-email-plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
On Tue, 7 Feb 2012 05:13:48 +0100, Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org> wrote:
> of_property_read_bool
>
> Search for a property in a device node and read a 32-bit value from
> it. Returns 0 if <0> or if the property does not exist, 1 if <1> or none.
>
> this will allow to disable a boolean
>
> is-ok; => true
> is-ok = <1>; => true
> is-ok = <0>; => false
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj-sclMFOaUSTBWk0Htik3J/w@public.gmane.org>
> Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
> ---
> Hi,
>
> if this is ok I'll rebase my mtd and i2c patch to use it
>
> Best Regards,
> J.
> drivers/of/base.c | 30 ++++++++++++++++++++++++++++++
> include/linux/of.h | 8 ++++++++
> 2 files changed, 38 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 133908a..a0eaf08 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -686,6 +686,36 @@ int of_property_read_u64(const struct device_node *np, const char *propname,
> EXPORT_SYMBOL_GPL(of_property_read_u64);
>
> /**
> + * of_property_read_bool - Find and read a boolean from a property
> + * @np: device node from which the property value is to be read.
> + * @propname: name of the property to be searched.
> + *
> + * Search for a property in a device node and read a 32-bit value from
> + * it. Returns 0 if <0> or if the property does not exist, 1 if <1> or none.
> + *
> + * is-ok; => true
> + * is-ok = <1>; => true
> + * is-ok = <0>; => false
> + */
> +int of_property_read_bool(const struct device_node *np, const char *propname)
> +{
> + u32 reg;
> + int ret = of_property_read_u32(np, propname, ®);
> +
> + switch (ret) {
> + case -EINVAL:
> + return false;
> + case -ENODATA:
> + return true;
> + case 0:
> + return reg == 1;
Ugh. so any value other than 1 returns false? I think that will surprise
most people.
I don't like this api or binding. If it is a bool property, then why isn't
simply testing for the property existance sufficient?
g.
next prev parent reply other threads:[~2012-03-09 1:44 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-07 4:13 [PATCH 1/1] of: introduce helper to manage boolean Jean-Christophe PLAGNIOL-VILLARD
2012-02-07 4:13 ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-07 15:13 ` Rob Herring
2012-02-07 15:13 ` Rob Herring
2012-02-07 16:14 ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-07 16:14 ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-09 1:44 ` Grant Likely [this message]
2012-03-09 1:44 ` Grant Likely
2012-03-09 10:04 ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-09 10:04 ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-09 16:26 ` Grant Likely
2012-03-09 16:26 ` Grant Likely
2012-03-09 16:36 ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-09 16:36 ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-12 19:39 ` Scott Wood
2012-03-12 19:39 ` Scott Wood
2012-03-13 3:17 ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-13 3:17 ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-13 4:16 ` Grant Likely
2012-03-13 4:16 ` Grant Likely
2012-03-13 7:03 ` Jean-Christophe PLAGNIOL-VILLARD
2012-03-13 7:03 ` Jean-Christophe PLAGNIOL-VILLARD
2012-07-10 12:10 ` Simon Glass
2012-07-10 12:10 ` Simon Glass
2012-07-10 21:23 ` Scott Wood
2012-07-10 21:23 ` Scott Wood
2012-07-10 22:53 ` Simon Glass
2012-07-10 22:53 ` Simon Glass
2012-07-10 23:11 ` Scott Wood
2012-07-10 23:11 ` Scott Wood
2012-07-12 5:27 ` Simon Glass
2012-07-12 5:27 ` Simon Glass
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=20120309014441.8236B3E0903@localhost \
--to=grant.likely@secretlab.ca \
--cc=linux-arm-kernel@lists.infradead.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.