All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Nicolas Schichan <nschichan@freebox.fr>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	linux-gpio@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: gpiolib sysfs access when CONFIG_GPIO_CDEV is not set
Date: Thu, 5 Nov 2020 16:39:45 +0800	[thread overview]
Message-ID: <20201105083945.GA23079@sol> (raw)
In-Reply-To: <CAHNNwZAucoc00gJrUsPRMpFc9U2r+os6NJfc1axsGh0m6ES=xQ@mail.gmail.com>

On Wed, Nov 04, 2020 at 06:26:54PM +0100, Nicolas Schichan wrote:
> Hello,
> 
> Following an update to the 5.10-rc1 kernel, I found out that trying to
> export a GPIO using /sys/class/gpio/export fails with the kernel
> reporting a message in the kernel logs:
> 
> # echo 41 >/sys/class/gpio/export
> [   46.761394] kobject_add_internal failed for gpio (error: -2 parent:
> gpiochip2)
> sh: write error: No such file or directory
> #
> 
> I have tracked it to the fact that I have CONFIG_GPIO_CDEV is disabled in
> my kernel config: Enabling CONFIG_GPIO_CDEV made export work again.
> 

Hi Nicolas,

Thanks for the report and investigation.

Just checking - the CONFIG_GPIO_CDEV defaults to enabled, so you had
explicitly disabled it?

> Enabling CONFIG_GPIO_CDEV and commenting all the code in
> gpiolib_cdev_register() except the final "return 0;" made the issue
> appear again, leading me to think that the issue is related to
> something that is done cdev_device_add() must be done to fix the
> issue.
> 
> Looking at the code of cdev_device_add() I was able to determine that
> the device_add() call made there is required to get the gpiolib sysfs
> export to work again.
> 

So the sysfs init, and the remainder of gpiochip_setup_dev(), relies on the
cdev init to perform the device_add() - I missed that :(.

> In the end I have done this (which I won't even pretend is the proper
> way to fix this), and sysfs attributes are finally working without
> CONFIG_GPIO_CDEV:
> 

I'd prefer this dependency was made more explicit, so I'd be inclined to
relocate the ifdef CONFIG_GPIO_CDEV block from gpiolib-cdev.h into
gpiolib.c by adding helper functions that call either the
gpiolib_cdev_register/unregister or the device_add/del dependent on
CONFIG_GPIO_CDEV.

I'll try to get a patch out shortly.

Thanks,
Kent.

> diff --git a/drivers/gpio/gpiolib-cdev.h b/drivers/gpio/gpiolib-cdev.h
> index cb41dd757338..dd72bd0e4af4 100644
> --- a/drivers/gpio/gpiolib-cdev.h
> +++ b/drivers/gpio/gpiolib-cdev.h
> @@ -16,7 +16,7 @@ void gpiolib_cdev_unregister(struct gpio_device *gdev);
> 
>  static inline int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
>  {
> -    return 0;
> +    return device_add(&gdev->dev);
>  }
> 
>  static inline void gpiolib_cdev_unregister(struct gpio_device *gdev)
> 
> If this is the preferred solution I can send a proper patch.
> 
> Best Regards,
> 
> -- 
> Nicolas Schichan

  reply	other threads:[~2020-11-05  8:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-04 17:26 gpiolib sysfs access when CONFIG_GPIO_CDEV is not set Nicolas Schichan
2020-11-05  8:39 ` Kent Gibson [this message]
2020-11-05 12:07   ` Nicolas Schichan
2020-11-05 12:35     ` Kent Gibson
2020-11-10 13:43 ` 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=20201105083945.GA23079@sol \
    --to=warthog618@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=nschichan@freebox.fr \
    /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.