[PATCH v2 03/10] gpio: aggregator: add read-only 'dev_name' configfs attribute

Koichiro Den posted 10 patches 1 year ago
There is a newer version of this series
[PATCH v2 03/10] gpio: aggregator: add read-only 'dev_name' configfs attribute
Posted by Koichiro Den 1 year ago
Add a read-only 'dev_name' attribute to configfs interface, which
exposes the platform bus device name. Users can easily identify which
gpiochip<N> has been created as follows:

$ cat /sys/kernel/config/gpio-aggregator/<aggregator-name>/dev_name
  gpio-aggregator.0
$ ls -d /sys/devices/platform/gpio-aggregator.0/gpiochip*
  gpiochip3

Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
---
 drivers/gpio/gpio-aggregator.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index c63cf3067ce7..76d3a8677308 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -732,6 +732,23 @@ static struct configfs_attribute *gpio_aggr_line_attrs[] = {
 	NULL
 };
 
+static ssize_t
+gpio_aggr_device_dev_name_show(struct config_item *item, char *page)
+{
+	struct gpio_aggregator *aggr = to_gpio_aggregator(item);
+	struct platform_device *pdev;
+
+	guard(mutex)(&aggr->lock);
+
+	pdev = aggr->pdev;
+	if (pdev)
+		return sprintf(page, "%s\n", dev_name(&pdev->dev));
+
+	return sprintf(page, "%s.%d\n", DRV_NAME, aggr->id);
+}
+
+CONFIGFS_ATTR_RO(gpio_aggr_device_, dev_name);
+
 static ssize_t
 gpio_aggr_device_live_show(struct config_item *item, char *page)
 {
@@ -781,6 +798,7 @@ gpio_aggr_device_live_store(struct config_item *item, const char *page,
 CONFIGFS_ATTR(gpio_aggr_device_, live);
 
 static struct configfs_attribute *gpio_aggr_device_attrs[] = {
+	&gpio_aggr_device_attr_dev_name,
 	&gpio_aggr_device_attr_live,
 	NULL
 };
-- 
2.45.2
Re: [PATCH v2 03/10] gpio: aggregator: add read-only 'dev_name' configfs attribute
Posted by Geert Uytterhoeven 12 months ago
Hi Den-san,

On Mon, 3 Feb 2025 at 04:12, Koichiro Den <koichiro.den@canonical.com> wrote:
> Add a read-only 'dev_name' attribute to configfs interface, which
> exposes the platform bus device name. Users can easily identify which
> gpiochip<N> has been created as follows:
>
> $ cat /sys/kernel/config/gpio-aggregator/<aggregator-name>/dev_name
>   gpio-aggregator.0
> $ ls -d /sys/devices/platform/gpio-aggregator.0/gpiochip*
>   gpiochip3
>
> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>

Thanks for your patch!

> --- a/drivers/gpio/gpio-aggregator.c
> +++ b/drivers/gpio/gpio-aggregator.c
> @@ -732,6 +732,23 @@ static struct configfs_attribute *gpio_aggr_line_attrs[] = {
>         NULL
>  };
>
> +static ssize_t
> +gpio_aggr_device_dev_name_show(struct config_item *item, char *page)
> +{
> +       struct gpio_aggregator *aggr = to_gpio_aggregator(item);
> +       struct platform_device *pdev;
> +
> +       guard(mutex)(&aggr->lock);
> +
> +       pdev = aggr->pdev;
> +       if (pdev)
> +               return sprintf(page, "%s\n", dev_name(&pdev->dev));
> +
> +       return sprintf(page, "%s.%d\n", DRV_NAME, aggr->id);

sysfs_emit(), for both branches.

> +}
> +

Please drop this blank line (everywhere).

> +CONFIGFS_ATTR_RO(gpio_aggr_device_, dev_name);
> +
>  static ssize_t
>  gpio_aggr_device_live_show(struct config_item *item, char *page)
>  {

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH v2 03/10] gpio: aggregator: add read-only 'dev_name' configfs attribute
Posted by Koichiro Den 12 months ago
On Wed, Feb 12, 2025 at 03:20:06PM GMT, Geert Uytterhoeven wrote:
> Hi Den-san,
> 
> On Mon, 3 Feb 2025 at 04:12, Koichiro Den <koichiro.den@canonical.com> wrote:
> > Add a read-only 'dev_name' attribute to configfs interface, which
> > exposes the platform bus device name. Users can easily identify which
> > gpiochip<N> has been created as follows:
> >
> > $ cat /sys/kernel/config/gpio-aggregator/<aggregator-name>/dev_name
> >   gpio-aggregator.0
> > $ ls -d /sys/devices/platform/gpio-aggregator.0/gpiochip*
> >   gpiochip3
> >
> > Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
> 
> Thanks for your patch!
> 
> > --- a/drivers/gpio/gpio-aggregator.c
> > +++ b/drivers/gpio/gpio-aggregator.c
> > @@ -732,6 +732,23 @@ static struct configfs_attribute *gpio_aggr_line_attrs[] = {
> >         NULL
> >  };
> >
> > +static ssize_t
> > +gpio_aggr_device_dev_name_show(struct config_item *item, char *page)
> > +{
> > +       struct gpio_aggregator *aggr = to_gpio_aggregator(item);
> > +       struct platform_device *pdev;
> > +
> > +       guard(mutex)(&aggr->lock);
> > +
> > +       pdev = aggr->pdev;
> > +       if (pdev)
> > +               return sprintf(page, "%s\n", dev_name(&pdev->dev));
> > +
> > +       return sprintf(page, "%s.%d\n", DRV_NAME, aggr->id);
> 
> sysfs_emit(), for both branches.

Will fix in v3.

> 
> > +}
> > +
> 
> Please drop this blank line (everywhere).

Will fix in v3.

Thanks!

Koichiro

> 
> > +CONFIGFS_ATTR_RO(gpio_aggr_device_, dev_name);
> > +
> >  static ssize_t
> >  gpio_aggr_device_live_show(struct config_item *item, char *page)
> >  {
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> -- 
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds
Re: [PATCH v2 03/10] gpio: aggregator: add read-only 'dev_name' configfs attribute
Posted by Bartosz Golaszewski 1 year ago
On Mon, Feb 3, 2025 at 4:12 AM Koichiro Den <koichiro.den@canonical.com> wrote:
>
> Add a read-only 'dev_name' attribute to configfs interface, which
> exposes the platform bus device name. Users can easily identify which
> gpiochip<N> has been created as follows:
>
> $ cat /sys/kernel/config/gpio-aggregator/<aggregator-name>/dev_name
>   gpio-aggregator.0
> $ ls -d /sys/devices/platform/gpio-aggregator.0/gpiochip*
>   gpiochip3
>
> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
> ---
>  drivers/gpio/gpio-aggregator.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
> index c63cf3067ce7..76d3a8677308 100644
> --- a/drivers/gpio/gpio-aggregator.c
> +++ b/drivers/gpio/gpio-aggregator.c
> @@ -732,6 +732,23 @@ static struct configfs_attribute *gpio_aggr_line_attrs[] = {
>         NULL
>  };
>
> +static ssize_t
> +gpio_aggr_device_dev_name_show(struct config_item *item, char *page)
> +{
> +       struct gpio_aggregator *aggr = to_gpio_aggregator(item);
> +       struct platform_device *pdev;
> +
> +       guard(mutex)(&aggr->lock);
> +
> +       pdev = aggr->pdev;
> +       if (pdev)
> +               return sprintf(page, "%s\n", dev_name(&pdev->dev));
> +
> +       return sprintf(page, "%s.%d\n", DRV_NAME, aggr->id);
> +}
> +
> +CONFIGFS_ATTR_RO(gpio_aggr_device_, dev_name);
> +
>  static ssize_t
>  gpio_aggr_device_live_show(struct config_item *item, char *page)
>  {
> @@ -781,6 +798,7 @@ gpio_aggr_device_live_store(struct config_item *item, const char *page,
>  CONFIGFS_ATTR(gpio_aggr_device_, live);
>
>  static struct configfs_attribute *gpio_aggr_device_attrs[] = {
> +       &gpio_aggr_device_attr_dev_name,
>         &gpio_aggr_device_attr_live,
>         NULL
>  };
> --
> 2.45.2
>

I don't understand why this isn't part of the previous patch?

Bart
Re: [PATCH v2 03/10] gpio: aggregator: add read-only 'dev_name' configfs attribute
Posted by Koichiro Den 1 year ago
On Tue, Feb 04, 2025 at 01:49:22PM GMT, Bartosz Golaszewski wrote:
> On Mon, Feb 3, 2025 at 4:12 AM Koichiro Den <koichiro.den@canonical.com> wrote:
> >
> > Add a read-only 'dev_name' attribute to configfs interface, which
> > exposes the platform bus device name. Users can easily identify which
> > gpiochip<N> has been created as follows:
> >
> > $ cat /sys/kernel/config/gpio-aggregator/<aggregator-name>/dev_name
> >   gpio-aggregator.0
> > $ ls -d /sys/devices/platform/gpio-aggregator.0/gpiochip*
> >   gpiochip3
> >
> > Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
> > ---
> >  drivers/gpio/gpio-aggregator.c | 18 ++++++++++++++++++
> >  1 file changed, 18 insertions(+)
> >
> > diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
> > index c63cf3067ce7..76d3a8677308 100644
> > --- a/drivers/gpio/gpio-aggregator.c
> > +++ b/drivers/gpio/gpio-aggregator.c
> > @@ -732,6 +732,23 @@ static struct configfs_attribute *gpio_aggr_line_attrs[] = {
> >         NULL
> >  };
> >
> > +static ssize_t
> > +gpio_aggr_device_dev_name_show(struct config_item *item, char *page)
> > +{
> > +       struct gpio_aggregator *aggr = to_gpio_aggregator(item);
> > +       struct platform_device *pdev;
> > +
> > +       guard(mutex)(&aggr->lock);
> > +
> > +       pdev = aggr->pdev;
> > +       if (pdev)
> > +               return sprintf(page, "%s\n", dev_name(&pdev->dev));
> > +
> > +       return sprintf(page, "%s.%d\n", DRV_NAME, aggr->id);
> > +}
> > +
> > +CONFIGFS_ATTR_RO(gpio_aggr_device_, dev_name);
> > +
> >  static ssize_t
> >  gpio_aggr_device_live_show(struct config_item *item, char *page)
> >  {
> > @@ -781,6 +798,7 @@ gpio_aggr_device_live_store(struct config_item *item, const char *page,
> >  CONFIGFS_ATTR(gpio_aggr_device_, live);
> >
> >  static struct configfs_attribute *gpio_aggr_device_attrs[] = {
> > +       &gpio_aggr_device_attr_dev_name,
> >         &gpio_aggr_device_attr_live,
> >         NULL
> >  };
> > --
> > 2.45.2
> >
> 
> I don't understand why this isn't part of the previous patch?

I just separated it to keep the previous one minimal as possible :)
Ok, I'll squash it.

Koichiro

> 
> Bart