linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: fix sysfs when cdev is not selected
@ 2020-11-05 10:40 Kent Gibson
  2020-11-05 12:01 ` Nicolas Schichan
  2020-11-05 14:37 ` Bartosz Golaszewski
  0 siblings, 2 replies; 3+ messages in thread
From: Kent Gibson @ 2020-11-05 10:40 UTC (permalink / raw)
  To: linux-kernel, linux-gpio, bgolaszewski, linus.walleij
  Cc: Kent Gibson, Nicolas Schichan

In gpiochip_setup_dev() the call to gpiolib_cdev_register() indirectly
calls device_add().  This is still required for the sysfs even when
CONFIG_GPIO_CDEV is not selected in the build.

Replace the stubbed functions in gpiolib-cdev.h with macros in gpiolib.c
that perform the required device_add() and device_del() when
CONFIG_GPIO_CDEV is not selected.

Fixes: d143493c01b7 (gpiolib: make cdev a build option)
Reported-by: Nicolas Schichan <nschichan@freebox.fr>
Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
 drivers/gpio/gpiolib-cdev.h | 15 ---------------
 drivers/gpio/gpiolib.c      | 18 +++++++++++++++---
 2 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/drivers/gpio/gpiolib-cdev.h b/drivers/gpio/gpiolib-cdev.h
index cb41dd757338..b42644cbffb8 100644
--- a/drivers/gpio/gpiolib-cdev.h
+++ b/drivers/gpio/gpiolib-cdev.h
@@ -7,22 +7,7 @@
 
 struct gpio_device;
 
-#ifdef CONFIG_GPIO_CDEV
-
 int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt);
 void gpiolib_cdev_unregister(struct gpio_device *gdev);
 
-#else
-
-static inline int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
-{
-	return 0;
-}
-
-static inline void gpiolib_cdev_unregister(struct gpio_device *gdev)
-{
-}
-
-#endif /* CONFIG_GPIO_CDEV */
-
 #endif /* GPIOLIB_CDEV_H */
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8e29a60c3697..c980ddcda833 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -480,11 +480,23 @@ static void gpiodevice_release(struct device *dev)
 	kfree(gdev);
 }
 
+#ifdef CONFIG_GPIO_CDEV
+#define gcdev_register(gdev, devt)	gpiolib_cdev_register((gdev), (devt))
+#define gcdev_unregister(gdev)		gpiolib_cdev_unregister((gdev))
+#else
+/*
+ * gpiolib_cdev_register() indirectly calls device_add(), which is still
+ * required even when cdev is not selected.
+ */
+#define gcdev_register(gdev, devt)	device_add(&(gdev)->dev)
+#define gcdev_unregister(gdev)		device_del(&(gdev)->dev)
+#endif
+
 static int gpiochip_setup_dev(struct gpio_device *gdev)
 {
 	int ret;
 
-	ret = gpiolib_cdev_register(gdev, gpio_devt);
+	ret = gcdev_register(gdev, gpio_devt);
 	if (ret)
 		return ret;
 
@@ -500,7 +512,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
 	return 0;
 
 err_remove_device:
-	gpiolib_cdev_unregister(gdev);
+	gcdev_unregister(gdev);
 	return ret;
 }
 
@@ -825,7 +837,7 @@ void gpiochip_remove(struct gpio_chip *gc)
 	 * be removed, else it will be dangling until the last user is
 	 * gone.
 	 */
-	gpiolib_cdev_unregister(gdev);
+	gcdev_unregister(gdev);
 	put_device(&gdev->dev);
 }
 EXPORT_SYMBOL_GPL(gpiochip_remove);
-- 
2.29.2


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

* Re: [PATCH] gpiolib: fix sysfs when cdev is not selected
  2020-11-05 10:40 [PATCH] gpiolib: fix sysfs when cdev is not selected Kent Gibson
@ 2020-11-05 12:01 ` Nicolas Schichan
  2020-11-05 14:37 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Schichan @ 2020-11-05 12:01 UTC (permalink / raw)
  To: Kent Gibson; +Cc: linux-kernel, linux-gpio, bgolaszewski, linus.walleij

Hello Kent,

On Thu, Nov 5, 2020 at 11:41 AM Kent Gibson <warthog618@gmail.com> wrote:
>
> In gpiochip_setup_dev() the call to gpiolib_cdev_register() indirectly
> calls device_add().  This is still required for the sysfs even when
> CONFIG_GPIO_CDEV is not selected in the build.
>
> Replace the stubbed functions in gpiolib-cdev.h with macros in gpiolib.c
> that perform the required device_add() and device_del() when
> CONFIG_GPIO_CDEV is not selected.
>
> Fixes: d143493c01b7 (gpiolib: make cdev a build option)
> Reported-by: Nicolas Schichan <nschichan@freebox.fr>
> Signed-off-by: Kent Gibson <warthog618@gmail.com>
> ---
>  drivers/gpio/gpiolib-cdev.h | 15 ---------------
>  drivers/gpio/gpiolib.c      | 18 +++++++++++++++---
>  2 files changed, 15 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-cdev.h b/drivers/gpio/gpiolib-cdev.h
> index cb41dd757338..b42644cbffb8 100644
> --- a/drivers/gpio/gpiolib-cdev.h
> +++ b/drivers/gpio/gpiolib-cdev.h
> @@ -7,22 +7,7 @@
>
>  struct gpio_device;
>
> -#ifdef CONFIG_GPIO_CDEV
> -
>  int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt);
>  void gpiolib_cdev_unregister(struct gpio_device *gdev);
>
> -#else
> -
> -static inline int gpiolib_cdev_register(struct gpio_device *gdev, dev_t devt)
> -{
> -       return 0;
> -}
> -
> -static inline void gpiolib_cdev_unregister(struct gpio_device *gdev)
> -{
> -}
> -
> -#endif /* CONFIG_GPIO_CDEV */
> -
>  #endif /* GPIOLIB_CDEV_H */
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 8e29a60c3697..c980ddcda833 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -480,11 +480,23 @@ static void gpiodevice_release(struct device *dev)
>         kfree(gdev);
>  }
>
> +#ifdef CONFIG_GPIO_CDEV
> +#define gcdev_register(gdev, devt)     gpiolib_cdev_register((gdev), (devt))
> +#define gcdev_unregister(gdev)         gpiolib_cdev_unregister((gdev))
> +#else
> +/*
> + * gpiolib_cdev_register() indirectly calls device_add(), which is still
> + * required even when cdev is not selected.
> + */
> +#define gcdev_register(gdev, devt)     device_add(&(gdev)->dev)
> +#define gcdev_unregister(gdev)         device_del(&(gdev)->dev)
> +#endif
> +
>  static int gpiochip_setup_dev(struct gpio_device *gdev)
>  {
>         int ret;
>
> -       ret = gpiolib_cdev_register(gdev, gpio_devt);
> +       ret = gcdev_register(gdev, gpio_devt);
>         if (ret)
>                 return ret;
>
> @@ -500,7 +512,7 @@ static int gpiochip_setup_dev(struct gpio_device *gdev)
>         return 0;
>
>  err_remove_device:
> -       gpiolib_cdev_unregister(gdev);
> +       gcdev_unregister(gdev);
>         return ret;
>  }
>
> @@ -825,7 +837,7 @@ void gpiochip_remove(struct gpio_chip *gc)
>          * be removed, else it will be dangling until the last user is
>          * gone.
>          */
> -       gpiolib_cdev_unregister(gdev);
> +       gcdev_unregister(gdev);
>         put_device(&gdev->dev);
>  }
>  EXPORT_SYMBOL_GPL(gpiochip_remove);
> --
> 2.29.2
>

I have tested your patch and it works for both CONFIG_GPIO_CDEV set and unset.

Tested-by: Nicolas Schichan <nschichan@freebox.fr>

Regards,

-- 
Nicolas Schichan
Freebox SAS

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

* Re: [PATCH] gpiolib: fix sysfs when cdev is not selected
  2020-11-05 10:40 [PATCH] gpiolib: fix sysfs when cdev is not selected Kent Gibson
  2020-11-05 12:01 ` Nicolas Schichan
@ 2020-11-05 14:37 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2020-11-05 14:37 UTC (permalink / raw)
  To: Kent Gibson; +Cc: LKML, linux-gpio, Linus Walleij, Nicolas Schichan

On Thu, Nov 5, 2020 at 11:41 AM Kent Gibson <warthog618@gmail.com> wrote:
>
> In gpiochip_setup_dev() the call to gpiolib_cdev_register() indirectly
> calls device_add().  This is still required for the sysfs even when
> CONFIG_GPIO_CDEV is not selected in the build.
>
> Replace the stubbed functions in gpiolib-cdev.h with macros in gpiolib.c
> that perform the required device_add() and device_del() when
> CONFIG_GPIO_CDEV is not selected.
>
> Fixes: d143493c01b7 (gpiolib: make cdev a build option)
> Reported-by: Nicolas Schichan <nschichan@freebox.fr>
> Signed-off-by: Kent Gibson <warthog618@gmail.com>

Applied for fixes with Nicolas' tag.

Bartosz

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

end of thread, other threads:[~2020-11-05 14:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-05 10:40 [PATCH] gpiolib: fix sysfs when cdev is not selected Kent Gibson
2020-11-05 12:01 ` Nicolas Schichan
2020-11-05 14:37 ` Bartosz Golaszewski

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