All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Ulf Hansson" <ulf.hansson@linaro.org>,
	"Peter Rosin" <peda@axentia.se>, "Andrew Lunn" <andrew@lunn.ch>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org, linux-mmc@vger.kernel.org,
	netdev@vger.kernel.org, linux-phy@lists.infradead.org,
	linux-sound@vger.kernel.org,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>
Subject: Re: [PATCH v3 05/15] bus: ts-nbus: use bitmap_get_value8()
Date: Fri, 21 Feb 2025 09:24:31 +0000	[thread overview]
Message-ID: <20250221092431.GE1615191@kernel.org> (raw)
In-Reply-To: <0084eef7-3831-4e62-acf1-6c2dc0e15dd1@baylibre.com>

On Thu, Feb 20, 2025 at 11:32:10AM -0600, David Lechner wrote:
> On 2/20/25 4:17 AM, Simon Horman wrote:
> > On Mon, Feb 10, 2025 at 04:33:31PM -0600, David Lechner wrote:
> >> Use bitmap_get_value8() instead of accessing the bitmap directly.
> >>
> >> Accessing the bitmap directly is not considered good practice. We now
> >> have a helper function that can be used instead, so let's use it.
> >>
> >> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> > u> Signed-off-by: David Lechner <dlechner@baylibre.com>
> >> ---
> >>  drivers/bus/ts-nbus.c | 5 +++--
> >>  1 file changed, 3 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/bus/ts-nbus.c b/drivers/bus/ts-nbus.c
> >> index b4c9308caf0647a3261071d9527fffce77784af2..beac67f3b820377f8bb1fc4f4ee77e15ee240834 100644
> >> --- a/drivers/bus/ts-nbus.c
> >> +++ b/drivers/bus/ts-nbus.c
> >> @@ -10,6 +10,7 @@
> >>   * TS-4600 SoM.
> >>   */
> >>  
> >> +#include <linux/bitmap.h>
> >>  #include <linux/bitops.h>
> >>  #include <linux/gpio/consumer.h>
> >>  #include <linux/kernel.h>
> >> @@ -107,7 +108,7 @@ static void ts_nbus_reset_bus(struct ts_nbus *ts_nbus)
> >>  {
> >>  	DECLARE_BITMAP(values, 8);
> >>  
> >> -	values[0] = 0;
> >> +	bitmap_set_value8(values, byte, 0);
> > 
> > Hi David,
> > 
> > byte doesn't appear to exist in the scope of this function.
> > 
> > I tried this:
> > 
> > 	bitmap_set_value8(values, 0, 8);
> > 
> > But when compiling with GCC 14.2.0 I see warnings that values
> > is used uninitialised - bitmap_set_value8() appears to rely on
> > it being so.
> 
> Ah yes, I see the problem (I don't think this driver compiles with
> allmodconfig so the compiler didn't catch it for me).

Thanks, that would explain things.

FWIIW, I think you can exercise this with allmodconfig by simply running:

  make drivers/bus/ts-nbus.o

> 
> > 
> >   CC      drivers/bus/ts-nbus.o
> > In file included from drivers/bus/ts-nbus.c:13:
> > In function ‘bitmap_write’,
> >     inlined from ‘ts_nbus_reset_bus’ at drivers/bus/ts-nbus.c:111:2:
> > ./include/linux/bitmap.h:818:12: error: ‘values’ is used uninitialized [-Werror=uninitialized]
> >   818 |         map[index] &= (fit ? (~(mask << offset)) : ~BITMAP_FIRST_WORD_MASK(start));
> >       |         ~~~^~~~~~~
> > In file included from ./include/linux/kasan-checks.h:5,
> >                  from ./include/asm-generic/rwonce.h:26,
> >                  from ./arch/x86/include/generated/asm/rwonce.h:1,
> >                  from ./include/linux/compiler.h:344,
> >                  from ./include/linux/build_bug.h:5,
> >                  from ./include/linux/bits.h:22,
> >                  from ./include/linux/bitops.h:6,
> >                  from ./include/linux/bitmap.h:8:
> > drivers/bus/ts-nbus.c: In function ‘ts_nbus_reset_bus’:
> > drivers/bus/ts-nbus.c:109:24: note: ‘values’ declared here
> >   109 |         DECLARE_BITMAP(values, 8);
> >       |                        ^~~~~~
> > ./include/linux/types.h:11:23: note: in definition of macro ‘DECLARE_BITMAP’
> >    11 |         unsigned long name[BITS_TO_LONGS(bits)]
> >       |                       ^~~~
> > 
> > 
> >>  
> >>  	gpiod_multi_set_value_cansleep(ts_nbus->data, values);
> >>  	gpiod_set_value_cansleep(ts_nbus->csn, 0);
> >> @@ -151,7 +152,7 @@ static void ts_nbus_write_byte(struct ts_nbus *ts_nbus, u8 byte)
> >>  {
> >>  	DECLARE_BITMAP(values, 8);
> 
> We can fix by zero-initialing the bitmap.
> 
> 	DECLARE_BITMAP(values, 8) = { };

Thanks, I confirmed that adding that to ts_nbus_reset_bus()
makes the compiler happy. And it seems sensible to me.

I guess that theoretically it should also be added to ts_nbus_write_byte(),
although GCC has nothing to say about that either way.

> Would you like me to send a new version of the patch?

It's not really my call. But I would expect that is a good next step.

> >> -	values[0] = byte;
> >> +	bitmap_set_value8(values, byte, 8);
> >>  
> >>  	gpiod_multi_set_value_cansleep(ts_nbus->data, values);
> >>  }

WARNING: multiple messages have this Message-ID (diff)
From: Simon Horman <horms@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Ulf Hansson" <ulf.hansson@linaro.org>,
	"Peter Rosin" <peda@axentia.se>, "Andrew Lunn" <andrew@lunn.ch>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org, linux-mmc@vger.kernel.org,
	netdev@vger.kernel.org, linux-phy@lists.infradead.org,
	linux-sound@vger.kernel.org,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>
Subject: Re: [PATCH v3 05/15] bus: ts-nbus: use bitmap_get_value8()
Date: Fri, 21 Feb 2025 09:24:31 +0000	[thread overview]
Message-ID: <20250221092431.GE1615191@kernel.org> (raw)
In-Reply-To: <0084eef7-3831-4e62-acf1-6c2dc0e15dd1@baylibre.com>

On Thu, Feb 20, 2025 at 11:32:10AM -0600, David Lechner wrote:
> On 2/20/25 4:17 AM, Simon Horman wrote:
> > On Mon, Feb 10, 2025 at 04:33:31PM -0600, David Lechner wrote:
> >> Use bitmap_get_value8() instead of accessing the bitmap directly.
> >>
> >> Accessing the bitmap directly is not considered good practice. We now
> >> have a helper function that can be used instead, so let's use it.
> >>
> >> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> > u> Signed-off-by: David Lechner <dlechner@baylibre.com>
> >> ---
> >>  drivers/bus/ts-nbus.c | 5 +++--
> >>  1 file changed, 3 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/bus/ts-nbus.c b/drivers/bus/ts-nbus.c
> >> index b4c9308caf0647a3261071d9527fffce77784af2..beac67f3b820377f8bb1fc4f4ee77e15ee240834 100644
> >> --- a/drivers/bus/ts-nbus.c
> >> +++ b/drivers/bus/ts-nbus.c
> >> @@ -10,6 +10,7 @@
> >>   * TS-4600 SoM.
> >>   */
> >>  
> >> +#include <linux/bitmap.h>
> >>  #include <linux/bitops.h>
> >>  #include <linux/gpio/consumer.h>
> >>  #include <linux/kernel.h>
> >> @@ -107,7 +108,7 @@ static void ts_nbus_reset_bus(struct ts_nbus *ts_nbus)
> >>  {
> >>  	DECLARE_BITMAP(values, 8);
> >>  
> >> -	values[0] = 0;
> >> +	bitmap_set_value8(values, byte, 0);
> > 
> > Hi David,
> > 
> > byte doesn't appear to exist in the scope of this function.
> > 
> > I tried this:
> > 
> > 	bitmap_set_value8(values, 0, 8);
> > 
> > But when compiling with GCC 14.2.0 I see warnings that values
> > is used uninitialised - bitmap_set_value8() appears to rely on
> > it being so.
> 
> Ah yes, I see the problem (I don't think this driver compiles with
> allmodconfig so the compiler didn't catch it for me).

Thanks, that would explain things.

FWIIW, I think you can exercise this with allmodconfig by simply running:

  make drivers/bus/ts-nbus.o

> 
> > 
> >   CC      drivers/bus/ts-nbus.o
> > In file included from drivers/bus/ts-nbus.c:13:
> > In function ‘bitmap_write’,
> >     inlined from ‘ts_nbus_reset_bus’ at drivers/bus/ts-nbus.c:111:2:
> > ./include/linux/bitmap.h:818:12: error: ‘values’ is used uninitialized [-Werror=uninitialized]
> >   818 |         map[index] &= (fit ? (~(mask << offset)) : ~BITMAP_FIRST_WORD_MASK(start));
> >       |         ~~~^~~~~~~
> > In file included from ./include/linux/kasan-checks.h:5,
> >                  from ./include/asm-generic/rwonce.h:26,
> >                  from ./arch/x86/include/generated/asm/rwonce.h:1,
> >                  from ./include/linux/compiler.h:344,
> >                  from ./include/linux/build_bug.h:5,
> >                  from ./include/linux/bits.h:22,
> >                  from ./include/linux/bitops.h:6,
> >                  from ./include/linux/bitmap.h:8:
> > drivers/bus/ts-nbus.c: In function ‘ts_nbus_reset_bus’:
> > drivers/bus/ts-nbus.c:109:24: note: ‘values’ declared here
> >   109 |         DECLARE_BITMAP(values, 8);
> >       |                        ^~~~~~
> > ./include/linux/types.h:11:23: note: in definition of macro ‘DECLARE_BITMAP’
> >    11 |         unsigned long name[BITS_TO_LONGS(bits)]
> >       |                       ^~~~
> > 
> > 
> >>  
> >>  	gpiod_multi_set_value_cansleep(ts_nbus->data, values);
> >>  	gpiod_set_value_cansleep(ts_nbus->csn, 0);
> >> @@ -151,7 +152,7 @@ static void ts_nbus_write_byte(struct ts_nbus *ts_nbus, u8 byte)
> >>  {
> >>  	DECLARE_BITMAP(values, 8);
> 
> We can fix by zero-initialing the bitmap.
> 
> 	DECLARE_BITMAP(values, 8) = { };

Thanks, I confirmed that adding that to ts_nbus_reset_bus()
makes the compiler happy. And it seems sensible to me.

I guess that theoretically it should also be added to ts_nbus_write_byte(),
although GCC has nothing to say about that either way.

> Would you like me to send a new version of the patch?

It's not really my call. But I would expect that is a good next step.

> >> -	values[0] = byte;
> >> +	bitmap_set_value8(values, byte, 8);
> >>  
> >>  	gpiod_multi_set_value_cansleep(ts_nbus->data, values);
> >>  }

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2025-02-21  9:24 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-10 22:33 [PATCH v3 00/15] gpiolib: add gpiod_multi_set_value_cansleep David Lechner
2025-02-10 22:33 ` David Lechner
2025-02-10 22:33 ` [PATCH v3 01/15] gpiolib: add gpiod_multi_set_value_cansleep() David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-11  7:35   ` Geert Uytterhoeven
2025-02-11  7:35     ` Geert Uytterhoeven
2025-02-11  9:39   ` Andy Shevchenko
2025-02-11  9:39     ` Andy Shevchenko
2025-02-14  9:22   ` Linus Walleij
2025-02-14  9:22     ` Linus Walleij
2025-02-10 22:33 ` [PATCH v3 02/15] auxdisplay: seg-led-gpio: use gpiod_multi_set_value_cansleep David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-12 10:51   ` Andy Shevchenko
2025-02-12 10:51     ` Andy Shevchenko
2025-02-10 22:33 ` [PATCH v3 03/15] bus: ts-nbus: validate ts,data-gpios array size David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-10 22:33 ` [PATCH v3 04/15] bus: ts-nbus: use gpiod_multi_set_value_cansleep David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-10 22:33 ` [PATCH v3 05/15] bus: ts-nbus: use bitmap_get_value8() David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-11  9:40   ` Andy Shevchenko
2025-02-11  9:40     ` Andy Shevchenko
2025-02-20 10:17   ` Simon Horman
2025-02-20 10:17     ` Simon Horman
2025-02-20 12:06     ` Andy Shevchenko
2025-02-20 12:06       ` Andy Shevchenko
2025-02-20 17:16       ` David Lechner
2025-02-20 17:16         ` David Lechner
2025-02-20 17:32     ` David Lechner
2025-02-20 17:32       ` David Lechner
2025-02-21  9:24       ` Simon Horman [this message]
2025-02-21  9:24         ` Simon Horman
2025-02-10 22:33 ` [PATCH v3 06/15] gpio: max3191x: use gpiod_multi_set_value_cansleep David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-11  9:42   ` Andy Shevchenko
2025-02-11  9:42     ` Andy Shevchenko
2025-02-10 22:33 ` [PATCH v3 07/15] iio: adc: ad7606: " David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-17 13:18   ` Jonathan Cameron
2025-02-17 13:18     ` Jonathan Cameron
2025-02-10 22:33 ` [PATCH v3 08/15] iio: amplifiers: hmc425a: " David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-10 22:33 ` [PATCH v3 09/15] iio: resolver: ad2s1210: " David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-10 22:33 ` [PATCH v3 10/15] iio: resolver: ad2s1210: use bitmap_write David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-11 19:46   ` Jonathan Cameron
2025-02-11 19:46     ` Jonathan Cameron
2025-02-20 20:54   ` David Lechner
2025-02-20 20:54     ` David Lechner
2025-02-22 11:38     ` Jonathan Cameron
2025-02-22 11:38       ` Jonathan Cameron
2025-02-22 11:51     ` Jonathan Cameron
2025-02-22 11:51       ` Jonathan Cameron
2025-02-10 22:33 ` [PATCH v3 11/15] mmc: pwrseq_simple: use gpiod_multi_set_value_cansleep David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-10 22:33 ` [PATCH v3 12/15] mux: gpio: " David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-10 22:33 ` [PATCH v3 13/15] net: mdio: mux-gpio: " David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-10 22:33 ` [PATCH v3 14/15] phy: mapphone-mdm6600: " David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-13 17:21   ` Vinod Koul
2025-02-13 17:21     ` Vinod Koul
2025-02-10 22:33 ` [PATCH v3 15/15] ASoC: adau1701: " David Lechner
2025-02-10 22:33   ` David Lechner
2025-02-12  9:36 ` (subset) [PATCH v3 00/15] gpiolib: add gpiod_multi_set_value_cansleep Bartosz Golaszewski
2025-02-12  9:36   ` Bartosz Golaszewski
2025-02-12  9:36 ` Bartosz Golaszewski
2025-02-12  9:36   ` Bartosz Golaszewski
2025-02-13 17:25   ` David Lechner
2025-02-13 17:25     ` David Lechner
2025-02-13 17:37     ` Andy Shevchenko
2025-02-13 17:37       ` Andy Shevchenko
2025-02-13 17:42     ` Bartosz Golaszewski
2025-02-13 17:42       ` Bartosz Golaszewski
2025-02-13 17:52       ` Mark Brown
2025-02-13 17:52         ` Mark Brown
2025-02-13 17:58         ` Bartosz Golaszewski
2025-02-13 17:58           ` Bartosz Golaszewski
2025-02-13 18:04           ` Mark Brown
2025-02-13 18:04             ` Mark Brown
2025-02-13 18:26 ` Mark Brown
2025-02-13 18:26   ` Mark Brown
2025-02-14 10:20 ` Bartosz Golaszewski
2025-02-14 10:20   ` Bartosz Golaszewski
2025-02-14 14:35   ` Andy Shevchenko
2025-02-14 14:35     ` Andy Shevchenko
2025-02-14 14:37     ` Bartosz Golaszewski
2025-02-14 14:37       ` Bartosz Golaszewski
2025-02-16 14:23       ` Jonathan Cameron
2025-02-16 14:23         ` Jonathan Cameron
2025-02-16 15:55         ` Bartosz Golaszewski
2025-02-16 15:55           ` Bartosz Golaszewski
2025-02-17 13:11           ` Jonathan Cameron
2025-02-17 13:11             ` Jonathan Cameron
2025-02-17 13:24             ` Bartosz Golaszewski
2025-02-17 13:24               ` Bartosz Golaszewski
2025-02-17 13:21 ` Jonathan Cameron
2025-02-17 13:21   ` Jonathan Cameron

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=20250221092431.GE1615191@kernel.org \
    --to=horms@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andrew@lunn.ch \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=broonie@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dlechner@baylibre.com \
    --cc=edumazet@google.com \
    --cc=geert@linux-m68k.org \
    --cc=hkallweit1@gmail.com \
    --cc=jic23@kernel.org \
    --cc=kishon@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=pabeni@redhat.com \
    --cc=peda@axentia.se \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=ulf.hansson@linaro.org \
    --cc=vkoul@kernel.org \
    /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.