* [PATCH v4 0/3] bus: ts-nbus: use gpiod_multi_set_value_cansleep
@ 2025-06-11 20:18 David Lechner
2025-06-11 20:18 ` [PATCH v4 1/3] bus: ts-nbus: validate ts,data-gpios array size David Lechner
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: David Lechner @ 2025-06-11 20:18 UTC (permalink / raw)
To: Sebastien Bourdelin, Arnd Bergmann, linux-arm-kernel
Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel,
David Lechner, Andy Shevchenko
This is what remains from "gpiolib: add gpiod_multi_set_value_cansleep"
that didn't get applied yet for the bus subsystem. So I have changed
the subject line accordingly.
Arnd,
There was no maintainer listed in MAINTAINERS for the ts-nbus driver
and it looks like you have picked up patches for it in the past. Could
you please pick up these as well?
---
Changes in v4:
- Dropped all non-ts-nbus patches.
- Fixed a reported issue with uninitialized variables.
- Link to v3: https://lore.kernel.org/r/20250210-gpio-set-array-helper-v3-0-d6a673674da8@baylibre.com
Changes in v3:
- Added IS_ERR_OR_NULL() check to gpiod_multi_set_value_cansleep()
- Added new patches to clean up accessing bitmap directly (ts-nbus, ad2s1210).
- Added function prefix for max3191x.
- Removed unnecessary braces in ad7606 patch.
- Picked up additional trailers.
- Link to v2: https://lore.kernel.org/r/20250206-gpio-set-array-helper-v2-0-1c5f048f79c3@baylibre.com
Changes in v2:
- Renamed new function from gpiods_multi_set_value_cansleep() to
gpiod_multi_set_value_cansleep()
- Fixed typo in name of replaced function in all commit messages.
- Picked up trailers.
- Link to v1: https://lore.kernel.org/r/20250131-gpio-set-array-helper-v1-0-991c8ccb4d6e@baylibre.com
---
David Lechner (3):
bus: ts-nbus: validate ts,data-gpios array size
bus: ts-nbus: use gpiod_multi_set_value_cansleep
bus: ts-nbus: use bitmap_set_value8()
drivers/bus/ts-nbus.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
---
base-commit: 19a60293b9925080d97f22f122aca3fc46dadaf9
change-id: 20250131-gpio-set-array-helper-bd4a328370d3
Best regards,
--
David Lechner <dlechner@baylibre.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/3] bus: ts-nbus: validate ts,data-gpios array size
2025-06-11 20:18 [PATCH v4 0/3] bus: ts-nbus: use gpiod_multi_set_value_cansleep David Lechner
@ 2025-06-11 20:18 ` David Lechner
2025-06-11 20:18 ` [PATCH v4 2/3] bus: ts-nbus: use gpiod_multi_set_value_cansleep David Lechner
2025-06-11 20:18 ` [PATCH v4 3/3] bus: ts-nbus: use bitmap_set_value8() David Lechner
2 siblings, 0 replies; 5+ messages in thread
From: David Lechner @ 2025-06-11 20:18 UTC (permalink / raw)
To: Sebastien Bourdelin, Arnd Bergmann, linux-arm-kernel
Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel,
David Lechner
Add validation of ts,data-gpios array size during probe. The driver
later hard-codes 8 as the size of the array when using it, so we should
be validating that the array is actually that big to prevent possible
out of bounds accesses.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/bus/ts-nbus.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/bus/ts-nbus.c b/drivers/bus/ts-nbus.c
index 2328c48b9b1260e805c631f2aa7379d620084537..d3ee102a13893c83c50e41f7298821f4d7ae3487 100644
--- a/drivers/bus/ts-nbus.c
+++ b/drivers/bus/ts-nbus.c
@@ -48,6 +48,10 @@ static int ts_nbus_init_pdata(struct platform_device *pdev,
return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->data),
"failed to retrieve ts,data-gpio from dts\n");
+ if (ts_nbus->data->ndescs != 8)
+ return dev_err_probe(&pdev->dev, -EINVAL,
+ "invalid number of ts,data-gpios\n");
+
ts_nbus->csn = devm_gpiod_get(&pdev->dev, "ts,csn", GPIOD_OUT_HIGH);
if (IS_ERR(ts_nbus->csn))
return dev_err_probe(&pdev->dev, PTR_ERR(ts_nbus->csn),
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 2/3] bus: ts-nbus: use gpiod_multi_set_value_cansleep
2025-06-11 20:18 [PATCH v4 0/3] bus: ts-nbus: use gpiod_multi_set_value_cansleep David Lechner
2025-06-11 20:18 ` [PATCH v4 1/3] bus: ts-nbus: validate ts,data-gpios array size David Lechner
@ 2025-06-11 20:18 ` David Lechner
2025-06-11 20:18 ` [PATCH v4 3/3] bus: ts-nbus: use bitmap_set_value8() David Lechner
2 siblings, 0 replies; 5+ messages in thread
From: David Lechner @ 2025-06-11 20:18 UTC (permalink / raw)
To: Sebastien Bourdelin, Arnd Bergmann, linux-arm-kernel
Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel,
David Lechner
Reduce verbosity by using gpiod_multi_set_value_cansleep() instead of
gpiod_set_array_value_cansleep().
ts_nbus->data->ndescs is validated to be 8 during probe, so will have
the same value as the hard-coded 8 that is removed by this change.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/bus/ts-nbus.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/bus/ts-nbus.c b/drivers/bus/ts-nbus.c
index d3ee102a13893c83c50e41f7298821f4d7ae3487..b4c9308caf0647a3261071d9527fffce77784af2 100644
--- a/drivers/bus/ts-nbus.c
+++ b/drivers/bus/ts-nbus.c
@@ -109,8 +109,7 @@ static void ts_nbus_reset_bus(struct ts_nbus *ts_nbus)
values[0] = 0;
- gpiod_set_array_value_cansleep(8, ts_nbus->data->desc,
- ts_nbus->data->info, values);
+ gpiod_multi_set_value_cansleep(ts_nbus->data, values);
gpiod_set_value_cansleep(ts_nbus->csn, 0);
gpiod_set_value_cansleep(ts_nbus->strobe, 0);
gpiod_set_value_cansleep(ts_nbus->ale, 0);
@@ -150,12 +149,11 @@ static int ts_nbus_read_byte(struct ts_nbus *ts_nbus, u8 *val)
*/
static void ts_nbus_write_byte(struct ts_nbus *ts_nbus, u8 byte)
{
- struct gpio_descs *gpios = ts_nbus->data;
DECLARE_BITMAP(values, 8);
values[0] = byte;
- gpiod_set_array_value_cansleep(8, gpios->desc, gpios->info, values);
+ gpiod_multi_set_value_cansleep(ts_nbus->data, values);
}
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 3/3] bus: ts-nbus: use bitmap_set_value8()
2025-06-11 20:18 [PATCH v4 0/3] bus: ts-nbus: use gpiod_multi_set_value_cansleep David Lechner
2025-06-11 20:18 ` [PATCH v4 1/3] bus: ts-nbus: validate ts,data-gpios array size David Lechner
2025-06-11 20:18 ` [PATCH v4 2/3] bus: ts-nbus: use gpiod_multi_set_value_cansleep David Lechner
@ 2025-06-11 20:18 ` David Lechner
2025-06-11 20:26 ` David Lechner
2 siblings, 1 reply; 5+ messages in thread
From: David Lechner @ 2025-06-11 20:18 UTC (permalink / raw)
To: Sebastien Bourdelin, Arnd Bergmann, linux-arm-kernel
Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel,
Andy Shevchenko, David Lechner
Use bitmap_set_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.
The bitmap has to be zero-initialized now to avoid a compiler warning
since bitmap_set_value8() does read/modify/write rather than just the
write that this is replacing.
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
v4 changes:
- Fix typo s/get/set/ in commit message
- Zero-initialize the bitmap to avoid compiler warning
---
drivers/bus/ts-nbus.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/bus/ts-nbus.c b/drivers/bus/ts-nbus.c
index b4c9308caf0647a3261071d9527fffce77784af2..17540034e64a4e591ea61b0b4eef86a2081b02f5 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>
@@ -105,9 +106,9 @@ static void ts_nbus_set_direction(struct ts_nbus *ts_nbus, int direction)
*/
static void ts_nbus_reset_bus(struct ts_nbus *ts_nbus)
{
- DECLARE_BITMAP(values, 8);
+ DECLARE_BITMAP(values, 8) = { };
- values[0] = 0;
+ bitmap_set_value8(values, byte, 0);
gpiod_multi_set_value_cansleep(ts_nbus->data, values);
gpiod_set_value_cansleep(ts_nbus->csn, 0);
@@ -149,9 +150,9 @@ static int ts_nbus_read_byte(struct ts_nbus *ts_nbus, u8 *val)
*/
static void ts_nbus_write_byte(struct ts_nbus *ts_nbus, u8 byte)
{
- DECLARE_BITMAP(values, 8);
+ DECLARE_BITMAP(values, 8) = { };
- values[0] = byte;
+ bitmap_set_value8(values, byte, 8);
gpiod_multi_set_value_cansleep(ts_nbus->data, values);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4 3/3] bus: ts-nbus: use bitmap_set_value8()
2025-06-11 20:18 ` [PATCH v4 3/3] bus: ts-nbus: use bitmap_set_value8() David Lechner
@ 2025-06-11 20:26 ` David Lechner
0 siblings, 0 replies; 5+ messages in thread
From: David Lechner @ 2025-06-11 20:26 UTC (permalink / raw)
To: Sebastien Bourdelin, Arnd Bergmann, linux-arm-kernel
Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel,
Andy Shevchenko
On 6/11/25 3:18 PM, David Lechner wrote:
> Use bitmap_set_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.
>
> The bitmap has to be zero-initialized now to avoid a compiler warning
> since bitmap_set_value8() does read/modify/write rather than just the
> write that this is replacing.
>
> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> v4 changes:
> - Fix typo s/get/set/ in commit message
> - Zero-initialize the bitmap to avoid compiler warning
> ---
> drivers/bus/ts-nbus.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/bus/ts-nbus.c b/drivers/bus/ts-nbus.c
> index b4c9308caf0647a3261071d9527fffce77784af2..17540034e64a4e591ea61b0b4eef86a2081b02f5 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>
> @@ -105,9 +106,9 @@ static void ts_nbus_set_direction(struct ts_nbus *ts_nbus, int direction)
> */
> static void ts_nbus_reset_bus(struct ts_nbus *ts_nbus)
> {
> - DECLARE_BITMAP(values, 8);
> + DECLARE_BITMAP(values, 8) = { };
>
> - values[0] = 0;
> + bitmap_set_value8(values, byte, 0);
I got distracted by an appointment and forgot to compile test before
sending. :-(
byte is undefined here. Will send v5 soon.
>
> gpiod_multi_set_value_cansleep(ts_nbus->data, values);
> gpiod_set_value_cansleep(ts_nbus->csn, 0);
> @@ -149,9 +150,9 @@ static int ts_nbus_read_byte(struct ts_nbus *ts_nbus, u8 *val)
> */
> static void ts_nbus_write_byte(struct ts_nbus *ts_nbus, u8 byte)
> {
> - DECLARE_BITMAP(values, 8);
> + DECLARE_BITMAP(values, 8) = { };
>
> - values[0] = byte;
> + bitmap_set_value8(values, byte, 8);
>
> gpiod_multi_set_value_cansleep(ts_nbus->data, values);
> }
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-06-11 22:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11 20:18 [PATCH v4 0/3] bus: ts-nbus: use gpiod_multi_set_value_cansleep David Lechner
2025-06-11 20:18 ` [PATCH v4 1/3] bus: ts-nbus: validate ts,data-gpios array size David Lechner
2025-06-11 20:18 ` [PATCH v4 2/3] bus: ts-nbus: use gpiod_multi_set_value_cansleep David Lechner
2025-06-11 20:18 ` [PATCH v4 3/3] bus: ts-nbus: use bitmap_set_value8() David Lechner
2025-06-11 20:26 ` David Lechner
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).