All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	Alexandre Courbot <acourbot@nvidia.com>,
	Johan Hovold <johan@kernel.org>,
	Michael Welling <mwelling@ieee.org>,
	Markus Pargmann <mpa@pengutronix.de>,
	Lee Campbell <leecam@google.com>,
	Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>,
	Grant Likely <grant.likely@linaro.org>,
	Arnd Bergmann <arnd@arndb.de>, Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh+dt@kernel.org>,
	Amit Kucheria <amit.kucheria@linaro.org>,
	David Mandala <david.mandala@linaro.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Re: [PATCH v3] gpio: of: make it possible to name GPIO lines
Date: Tue, 26 Apr 2016 13:03:45 +0200	[thread overview]
Message-ID: <CACRpkdYZuRGvFf1kjy3E4=1hSfVaqFTk6qENyaJjEdTgZ8uVGQ@mail.gmail.com> (raw)
In-Reply-To: <20160421170615.GA25466@dtor-ws>

On Thu, Apr 21, 2016 at 7:06 PM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Thu, Apr 21, 2016 at 01:08:21PM +0200, Linus Walleij wrote:
>>  /**
>> + * of_gpiochip_set_names() - set up the names of the lines
>> + * @chip: GPIO chip whose lines should be named, if possible
>> + */
>> +static void of_gpiochip_set_names(struct gpio_chip *gc)
>> +{
>> +     struct gpio_device *gdev = gc->gpiodev;
>> +     struct device_node *np = gc->of_node;
>> +     int i;
>> +     int nstrings;
>> +
>> +     /* Do we even have the "gpio-line-names" property */
>> +     if (!of_property_read_bool(np, "gpio-line-names"))
>> +             return;
>> +
>> +     nstrings = of_property_count_strings(np, "gpio-line-names");
>> +     /*
>> +      * Make sure to not index beyond either the end of the
>> +      * "gpio-names" array nor the number of descriptors of
>> +      * the GPIO device.
>> +      */
>
> I know you mentioned that it already been discussed much, but I am not
> sure why we need to count the string (and validate that strings are
> present by treating the property as boolean?),

I validate the property to be present to bail out quickly on controllers
that have no names set (i.e. all currently deployed device trees).
I can skip that part if you think it's too much optimization.

However:

> I am not
> sure why we need to count the string
> when we could do
> something like this (relying on the fact that
> of_property_read_string_index() returns 0 or negative error, no positive
> return codes):
>
>         for (i = 0; i < gdev->ngpio; i++) {
>                 const char *name;
>                 int error;
>
>                 error = of_property_read_string_index(np,
>                                                       "gpio-line-names",
>                                                       i,
>                                                       &name);
>                 if (error) {
>                         if (error != -ENODATA)
>                                 dev_err(&gdev->dev,
>                                         "unable to name line %d: %d\n",
>                                         i, error);
>                         /*
>                          * Either no more strings (-ENODATA), or
>                          * other error, in any case we are done naming.
>                          */
>                         break;
>                 }
>
>                 gdev->descs[i].name = name;
>         }

Yeah I can do that, thanks I didn't look close enough at the semantics.

The big question whether the DT people are OK with naming producer
names like this remains however.

Yours,
Linus Walleij

  reply	other threads:[~2016-04-26 11:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21 11:08 [PATCH v3] gpio: of: make it possible to name GPIO lines Linus Walleij
2016-04-21 17:06 ` Dmitry Torokhov
2016-04-26 11:03   ` Linus Walleij [this message]
2016-04-26 16:53     ` Dmitry Torokhov
2016-04-28  8:12 ` Markus Pargmann
2016-05-01  8:56   ` Linus Walleij

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='CACRpkdYZuRGvFf1kjy3E4=1hSfVaqFTk6qENyaJjEdTgZ8uVGQ@mail.gmail.com' \
    --to=linus.walleij@linaro.org \
    --cc=acourbot@nvidia.com \
    --cc=amit.kucheria@linaro.org \
    --cc=arnd@arndb.de \
    --cc=bamvor.zhangjian@linaro.org \
    --cc=broonie@kernel.org \
    --cc=david.mandala@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=leecam@google.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=mpa@pengutronix.de \
    --cc=mwelling@ieee.org \
    --cc=robh+dt@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 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.