linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* gpiolib sysfs access when CONFIG_GPIO_CDEV is not set
@ 2020-11-04 17:26 Nicolas Schichan
  2020-11-05  8:39 ` Kent Gibson
  2020-11-10 13:43 ` Linus Walleij
  0 siblings, 2 replies; 5+ messages in thread
From: Nicolas Schichan @ 2020-11-04 17:26 UTC (permalink / raw)
  To: Linus Walleij, linux-gpio, Bartosz Golaszewski

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.

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.

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:

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: gpiolib sysfs access when CONFIG_GPIO_CDEV is not set
  2020-11-04 17:26 gpiolib sysfs access when CONFIG_GPIO_CDEV is not set Nicolas Schichan
@ 2020-11-05  8:39 ` Kent Gibson
  2020-11-05 12:07   ` Nicolas Schichan
  2020-11-10 13:43 ` Linus Walleij
  1 sibling, 1 reply; 5+ messages in thread
From: Kent Gibson @ 2020-11-05  8:39 UTC (permalink / raw)
  To: Nicolas Schichan; +Cc: Linus Walleij, linux-gpio, Bartosz Golaszewski

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gpiolib sysfs access when CONFIG_GPIO_CDEV is not set
  2020-11-05  8:39 ` Kent Gibson
@ 2020-11-05 12:07   ` Nicolas Schichan
  2020-11-05 12:35     ` Kent Gibson
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Schichan @ 2020-11-05 12:07 UTC (permalink / raw)
  To: Kent Gibson; +Cc: Linus Walleij, linux-gpio, Bartosz Golaszewski

On Thu, Nov 5, 2020 at 9:39 AM Kent Gibson <warthog618@gmail.com> wrote:
[...]
> Hi Nicolas,
>
> Thanks for the report and investigation.
>
> Just checking - the CONFIG_GPIO_CDEV defaults to enabled, so you had
> explicitly disabled it?

Hello Kent,

Yes, we have no users of the character device gpio interface on our
platform, so I have disabled it explicitly when updating the defconfig
to the 5.10-rc1 kernel.

Regards,

-- 
Nicolas Schichan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gpiolib sysfs access when CONFIG_GPIO_CDEV is not set
  2020-11-05 12:07   ` Nicolas Schichan
@ 2020-11-05 12:35     ` Kent Gibson
  0 siblings, 0 replies; 5+ messages in thread
From: Kent Gibson @ 2020-11-05 12:35 UTC (permalink / raw)
  To: Nicolas Schichan; +Cc: Linus Walleij, linux-gpio, Bartosz Golaszewski

On Thu, Nov 05, 2020 at 01:07:43PM +0100, Nicolas Schichan wrote:
> On Thu, Nov 5, 2020 at 9:39 AM Kent Gibson <warthog618@gmail.com> wrote:
> [...]
> > Hi Nicolas,
> >
> > Thanks for the report and investigation.
> >
> > Just checking - the CONFIG_GPIO_CDEV defaults to enabled, so you had
> > explicitly disabled it?
> 
> Hello Kent,
> 
> Yes, we have no users of the character device gpio interface on our
> platform, so I have disabled it explicitly when updating the defconfig
> to the 5.10-rc1 kernel.
> 

Thanks for confirming that - I was concerned that it had somehow been
disabled unintentionally - which would be a bug in itself.

Cheers,
Kent.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gpiolib sysfs access when CONFIG_GPIO_CDEV is not set
  2020-11-04 17:26 gpiolib sysfs access when CONFIG_GPIO_CDEV is not set Nicolas Schichan
  2020-11-05  8:39 ` Kent Gibson
@ 2020-11-10 13:43 ` Linus Walleij
  1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2020-11-10 13:43 UTC (permalink / raw)
  To: Nicolas Schichan; +Cc: open list:GPIO SUBSYSTEM, Bartosz Golaszewski

On Wed, Nov 4, 2020 at 6:27 PM Nicolas Schichan <nschichan@freebox.fr> wrote:

> 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.

We have deliberately made it hard to remove the character device
because we want to encourage people to use it.

> Yes, we have no users of the character device gpio interface on our
> platform, so I have disabled it explicitly when updating the defconfig
> to the 5.10-rc1 kernel.

Please consider getting users of the character device, since if they
are using the sysfs they are using an explicitly obsoleted interface.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-10 13:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-04 17:26 gpiolib sysfs access when CONFIG_GPIO_CDEV is not set Nicolas Schichan
2020-11-05  8:39 ` Kent Gibson
2020-11-05 12:07   ` Nicolas Schichan
2020-11-05 12:35     ` Kent Gibson
2020-11-10 13:43 ` Linus Walleij

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).