linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Manivannan Sadhasivam <mani@kernel.org>,
	Johan Hovold <johan@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] gpio: sysfs: Try numbered exports if symbolic names fail
Date: Thu, 10 Dec 2020 09:34:04 +0100	[thread overview]
Message-ID: <X9HdfKxuUD3CZGNP@localhost> (raw)
In-Reply-To: <20201209161821.92931-1-linus.walleij@linaro.org>

On Wed, Dec 09, 2020 at 05:18:21PM +0100, Linus Walleij wrote:
> If a GPIO line cannot be exported using a symbolic name from
> the .names array in the gpiochip, fall back to using the
> "gpioN" naming system instead of just failing.
> 
> Cc: Manivannan Sadhasivam <mani@kernel.org>
> Cc: Johan Hovold <johan@kernel.org>
> Suggested-by: Johan Hovold <johan@kernel.org>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/gpio/gpiolib-sysfs.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
> index 728f6c687182..a5a0e9238217 100644
> --- a/drivers/gpio/gpiolib-sysfs.c
> +++ b/drivers/gpio/gpiolib-sysfs.c
> @@ -627,10 +627,24 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
>  	if (chip->names && chip->names[offset])
>  		ioname = chip->names[offset];
>  
> -	dev = device_create_with_groups(&gpio_class, &gdev->dev,
> -					MKDEV(0, 0), data, gpio_groups,
> -					ioname ? ioname : "gpio%u",
> -					desc_to_gpio(desc));
> +	/*
> +	 * If we have a symbolic name for the GPIO we try to use that
> +	 * for the exported sysfs device/file, as legacy scripts depend
> +	 * on it. If we don't have a symbolic name or if there is a
> +	 * namespace collision, we stick with the "gpioN" name.
> +	 */
> +	dev = NULL;
> +	if (ioname)
> +		dev = device_create_with_groups(&gpio_class, &gdev->dev,
> +						MKDEV(0, 0), data, gpio_groups,
> +						ioname,
> +						desc_to_gpio(desc));
> +	if (IS_ERR_OR_NULL(dev))
> +		dev = device_create_with_groups(&gpio_class, &gdev->dev,
> +						MKDEV(0, 0), data, gpio_groups,
> +						"gpio%u",
> +						desc_to_gpio(desc));

I suggested having the driver set a flag which determines whether to use
the line names in sysfs or not.

The above will trigger a bunch of nasty warnings and backtraces in the
sysfs code (for every gpio line!), which is not something we want for
normal operation. Having the sysfs interface for the same USB device
depend on probe order is not very nice either.

Since the USB GPIO controller do not register any names today (as
gpiolib currently require a flat name space), there's no need to worry
about legacy scripts depending on those either (or rather, the argument
goes the other way since adding names now could break a functioning
script).

Just add a flag to suppress the renaming and we can safely start adding
names to hotpluggable controllers (if the rest of gpiolib can handle
non-unique names).

Johan

  reply	other threads:[~2020-12-10  8:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-09 16:18 [PATCH] gpio: sysfs: Try numbered exports if symbolic names fail Linus Walleij
2020-12-10  8:34 ` Johan Hovold [this message]
2020-12-11 23:41   ` Linus Walleij
2020-12-14  9:07     ` Johan Hovold

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=X9HdfKxuUD3CZGNP@localhost \
    --to=johan@kernel.org \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mani@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 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).