2020-11-23 22:43:34

by Pawan Gupta

[permalink] [raw]
Subject: [PATCH] pinctrl: core: Fix unused variable build warnings

A recent commit f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs
file") added build warnings when CONFIG_GPIOLIB=n. Offcourse the kernel
fails to build when warnings are treated as errors. Below is the error
message:

$ make CFLAGS_KERNEL+=-Werror

drivers/pinctrl/core.c: In function ‘pinctrl_pins_show’:
drivers/pinctrl/core.c:1607:20: error: unused variable ‘chip’ [-Werror=unused-variable]
1607 | struct gpio_chip *chip;
| ^~~~
drivers/pinctrl/core.c:1606:15: error: unused variable ‘gpio_num’ [-Werror=unused-variable]
1606 | unsigned int gpio_num;
| ^~~~~~~~
drivers/pinctrl/core.c:1605:29: error: unused variable ‘range’ [-Werror=unused-variable]
1605 | struct pinctrl_gpio_range *range;
| ^~~~~
cc1: all warnings being treated as errors

These variables are only used inside #ifdef CONFIG_GPIOLIB, fix the
build warnings by wrapping the definition inside the config.

Fixes: f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs file")
Signed-off-by: Pawan Gupta <[email protected]>
---
drivers/pinctrl/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 3663d87f51a0..1bb371a5cf8d 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1602,10 +1602,11 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
struct pinctrl_dev *pctldev = s->private;
const struct pinctrl_ops *ops = pctldev->desc->pctlops;
unsigned i, pin;
+#ifdef CONFIG_GPIOLIB
struct pinctrl_gpio_range *range;
unsigned int gpio_num;
struct gpio_chip *chip;
-
+#endif
seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);

mutex_lock(&pctldev->mutex);
--
2.21.3


2020-11-24 05:15:33

by Drew Fustini

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: core: Fix unused variable build warnings

On Mon, Nov 23, 2020 at 02:33:33PM -0800, Pawan Gupta wrote:
> A recent commit f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs
> file") added build warnings when CONFIG_GPIOLIB=n. Offcourse the kernel
> fails to build when warnings are treated as errors. Below is the error
> message:
>
> $ make CFLAGS_KERNEL+=-Werror
>
> drivers/pinctrl/core.c: In function ‘pinctrl_pins_show’:
> drivers/pinctrl/core.c:1607:20: error: unused variable ‘chip’ [-Werror=unused-variable]
> 1607 | struct gpio_chip *chip;
> | ^~~~
> drivers/pinctrl/core.c:1606:15: error: unused variable ‘gpio_num’ [-Werror=unused-variable]
> 1606 | unsigned int gpio_num;
> | ^~~~~~~~
> drivers/pinctrl/core.c:1605:29: error: unused variable ‘range’ [-Werror=unused-variable]
> 1605 | struct pinctrl_gpio_range *range;
> | ^~~~~
> cc1: all warnings being treated as errors
>
> These variables are only used inside #ifdef CONFIG_GPIOLIB, fix the
> build warnings by wrapping the definition inside the config.
>
> Fixes: f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs file")
> Signed-off-by: Pawan Gupta <[email protected]>
> ---
> drivers/pinctrl/core.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> index 3663d87f51a0..1bb371a5cf8d 100644
> --- a/drivers/pinctrl/core.c
> +++ b/drivers/pinctrl/core.c
> @@ -1602,10 +1602,11 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
> struct pinctrl_dev *pctldev = s->private;
> const struct pinctrl_ops *ops = pctldev->desc->pctlops;
> unsigned i, pin;
> +#ifdef CONFIG_GPIOLIB
> struct pinctrl_gpio_range *range;
> unsigned int gpio_num;
> struct gpio_chip *chip;
> -
> +#endif
> seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
>
> mutex_lock(&pctldev->mutex);
> --
> 2.21.3
>

Thanks for pointing this out. I don't have any systems where I build
without CONFIG_GPIOLIB so I missed this.

I'm having trouble figuring out a .config that will reproduce this. I
tried tinyconfig but it compiled clean.

Could you share your .config?

Thank you,
Drew

2020-11-24 08:01:51

by Pawan Gupta

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: core: Fix unused variable build warnings

On Mon, Nov 23, 2020 at 09:06:18PM -0800, Drew Fustini wrote:
> On Mon, Nov 23, 2020 at 02:33:33PM -0800, Pawan Gupta wrote:
> > A recent commit f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs
> > file") added build warnings when CONFIG_GPIOLIB=n. Offcourse the kernel
> > fails to build when warnings are treated as errors. Below is the error
> > message:
> >
> > $ make CFLAGS_KERNEL+=-Werror
> >
> > drivers/pinctrl/core.c: In function ‘pinctrl_pins_show’:
> > drivers/pinctrl/core.c:1607:20: error: unused variable ‘chip’ [-Werror=unused-variable]
> > 1607 | struct gpio_chip *chip;
> > | ^~~~
> > drivers/pinctrl/core.c:1606:15: error: unused variable ‘gpio_num’ [-Werror=unused-variable]
> > 1606 | unsigned int gpio_num;
> > | ^~~~~~~~
> > drivers/pinctrl/core.c:1605:29: error: unused variable ‘range’ [-Werror=unused-variable]
> > 1605 | struct pinctrl_gpio_range *range;
> > | ^~~~~
> > cc1: all warnings being treated as errors
> >
> > These variables are only used inside #ifdef CONFIG_GPIOLIB, fix the
> > build warnings by wrapping the definition inside the config.
> >
> > Fixes: f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs file")
> > Signed-off-by: Pawan Gupta <[email protected]>
> > ---
> > drivers/pinctrl/core.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> > index 3663d87f51a0..1bb371a5cf8d 100644
> > --- a/drivers/pinctrl/core.c
> > +++ b/drivers/pinctrl/core.c
> > @@ -1602,10 +1602,11 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
> > struct pinctrl_dev *pctldev = s->private;
> > const struct pinctrl_ops *ops = pctldev->desc->pctlops;
> > unsigned i, pin;
> > +#ifdef CONFIG_GPIOLIB
> > struct pinctrl_gpio_range *range;
> > unsigned int gpio_num;
> > struct gpio_chip *chip;
> > -
> > +#endif
> > seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
> >
> > mutex_lock(&pctldev->mutex);
> > --
> > 2.21.3
> >
>
> Thanks for pointing this out. I don't have any systems where I build
> without CONFIG_GPIOLIB so I missed this.
>
> I'm having trouble figuring out a .config that will reproduce this. I
> tried tinyconfig but it compiled clean.

Just setting CONFIG_GPIOLIB=n via menuconfig is not an option? Have you
tried x86?

> Could you share your .config?

Attaching the .config that reproduces the build warning.

Thanks,
Pawan


Attachments:
(No filename) (2.56 kB)
.config (176.17 kB)
Download all attachments

2020-11-26 09:42:46

by Drew Fustini

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: core: Fix unused variable build warnings

On Mon, Nov 23, 2020 at 11:51:29PM -0800, Pawan Gupta wrote:
> On Mon, Nov 23, 2020 at 09:06:18PM -0800, Drew Fustini wrote:
> > On Mon, Nov 23, 2020 at 02:33:33PM -0800, Pawan Gupta wrote:
> > > A recent commit f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs
> > > file") added build warnings when CONFIG_GPIOLIB=n. Offcourse the kernel
> > > fails to build when warnings are treated as errors. Below is the error
> > > message:
> > >
> > > $ make CFLAGS_KERNEL+=-Werror
> > >
> > > drivers/pinctrl/core.c: In function ‘pinctrl_pins_show’:
> > > drivers/pinctrl/core.c:1607:20: error: unused variable ‘chip’ [-Werror=unused-variable]
> > > 1607 | struct gpio_chip *chip;
> > > | ^~~~
> > > drivers/pinctrl/core.c:1606:15: error: unused variable ‘gpio_num’ [-Werror=unused-variable]
> > > 1606 | unsigned int gpio_num;
> > > | ^~~~~~~~
> > > drivers/pinctrl/core.c:1605:29: error: unused variable ‘range’ [-Werror=unused-variable]
> > > 1605 | struct pinctrl_gpio_range *range;
> > > | ^~~~~
> > > cc1: all warnings being treated as errors
> > >
> > > These variables are only used inside #ifdef CONFIG_GPIOLIB, fix the
> > > build warnings by wrapping the definition inside the config.
> > >
> > > Fixes: f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs file")
> > > Signed-off-by: Pawan Gupta <[email protected]>
> > > ---
> > > drivers/pinctrl/core.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
> > > index 3663d87f51a0..1bb371a5cf8d 100644
> > > --- a/drivers/pinctrl/core.c
> > > +++ b/drivers/pinctrl/core.c
> > > @@ -1602,10 +1602,11 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
> > > struct pinctrl_dev *pctldev = s->private;
> > > const struct pinctrl_ops *ops = pctldev->desc->pctlops;
> > > unsigned i, pin;
> > > +#ifdef CONFIG_GPIOLIB
> > > struct pinctrl_gpio_range *range;
> > > unsigned int gpio_num;
> > > struct gpio_chip *chip;
> > > -
> > > +#endif
> > > seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
> > >
> > > mutex_lock(&pctldev->mutex);
> > > --
> > > 2.21.3
> > >
> >
> > Thanks for pointing this out. I don't have any systems where I build
> > without CONFIG_GPIOLIB so I missed this.
> >
> > I'm having trouble figuring out a .config that will reproduce this. I
> > tried tinyconfig but it compiled clean.
>
> Just setting CONFIG_GPIOLIB=n via menuconfig is not an option? Have you
> tried x86?

There were other options related to pinctrl both for my ARM board and my
laptop that were forcing GPIOLIB to stay on.

>
> > Could you share your .config?
>
> Attaching the .config that reproduces the build warning.

Thanks. I was able to reproduce the error with your config.

I applied your patch and it did resolve the error for me.

Reviewed-by: Drew Fustini <[email protected]>

2020-12-01 23:10:55

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: core: Fix unused variable build warnings

On Mon, Nov 23, 2020 at 11:41 PM Pawan Gupta <[email protected]> wrote:

> A recent commit f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs
> file") added build warnings when CONFIG_GPIOLIB=n. Offcourse the kernel
> fails to build when warnings are treated as errors. Below is the error
> message:
>
> $ make CFLAGS_KERNEL+=-Werror
>
> drivers/pinctrl/core.c: In function ‘pinctrl_pins_show’:
> drivers/pinctrl/core.c:1607:20: error: unused variable ‘chip’ [-Werror=unused-variable]
> 1607 | struct gpio_chip *chip;
> | ^~~~
> drivers/pinctrl/core.c:1606:15: error: unused variable ‘gpio_num’ [-Werror=unused-variable]
> 1606 | unsigned int gpio_num;
> | ^~~~~~~~
> drivers/pinctrl/core.c:1605:29: error: unused variable ‘range’ [-Werror=unused-variable]
> 1605 | struct pinctrl_gpio_range *range;
> | ^~~~~
> cc1: all warnings being treated as errors
>
> These variables are only used inside #ifdef CONFIG_GPIOLIB, fix the
> build warnings by wrapping the definition inside the config.
>
> Fixes: f1b206cf7c57 ("pinctrl: core: print gpio in pins debugfs file")
> Signed-off-by: Pawan Gupta <[email protected]>

This was fixed in
commit b507cb92477ad85902783a183c5ce01d16296687
"pinctrl: core: Add missing #ifdef CONFIG_GPIOLIB"
On october 28.

Thanks anyways!

Yours,
Linus Walleij