Skip to contentSkip to conversation

bus: ts-nbus: use gpiod_multi_set_value_cansleep

PATCH In review David Lechner 2 participants 6 messages Jun 13, 2025 GPIO

lore
Share & tools
lore
#0 lore raw

v5 cover bus: ts-nbus: use gpiod_multi_set_value_cansleep

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 v5:
- Fix undeclared variable in ts_nbus_reset_bus()
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Dropped all non-ts-nbus patches.
- Fixed a reported issue with uninitialized variables.
- Link to v3: https://lore.kernel.org/r/[email protected]

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/[email protected]

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/[email protected]

---
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, 10 insertions(+), 9 deletions(-)

---
base-commit: 19a60293b9925080d97f22f122aca3fc46dadaf9
change-id: 20250131-gpio-set-array-helper-bd4a328370d3

Best regards,

Signature · 1 line
David Lechner <[email protected]>
#1 lore raw

PATCH v5 1/3 bus: ts-nbus: validate ts,data-gpios array size

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.

---
 drivers/bus/ts-nbus.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/bus/ts-nbus.c +4 -0
index 2328c48b9b1260e805c631f2aa7379d620084537..d3ee102a13893c83c50e41f7298821f4d7ae3487 100644
@@ -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),
Signature · 1 line
2.43.0
#2 lore raw

PATCH v5 2/3 bus: ts-nbus: use gpiod_multi_set_value_cansleep

In reply to 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.

---
 drivers/bus/ts-nbus.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/bus/ts-nbus.c +2 -4
index d3ee102a13893c83c50e41f7298821f4d7ae3487..b4c9308caf0647a3261071d9527fffce77784af2 100644
@@ -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);
 }
 
 /*
Signature · 1 line
2.43.0
#3 lore raw

PATCH v5 3/3 bus: ts-nbus: use bitmap_set_value8()

In reply to 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. In ts_nbus_reset_bus(), this zero- initialization is enough and we don't need to replace the array access with bitmap_clear().

---
v5 changes:
- Fix undeclared variable in ts_nbus_reset_bus() 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, 4 insertions(+), 5 deletions(-)
drivers/bus/ts-nbus.c +4 -5
index b4c9308caf0647a3261071d9527fffce77784af2..371fa83ad0db424ea48cd7c23e3070f56162d7ad 100644
@@ -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,7 @@ 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);
-
-	values[0] = 0;
+	DECLARE_BITMAP(values, 8) = { };
 
 	gpiod_multi_set_value_cansleep(ts_nbus->data, values);
 	gpiod_set_value_cansleep(ts_nbus->csn, 0);
@@ -149,9 +148,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);
 }
Signature · 1 line
2.43.0
#4 lore raw
In reply to David Lechner
Quoted 9 lines · David Lechner

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?

Sure, no problem, just a few things:

- These are all cleanups that can wait until 6.17, right?
- I see the driver has no in-tree users, and apparently never were. There is a imx28-ts4600.dts file that should reference it but doesn't. Do we have any indication that the driver works? Added Sebastien to Cc as well for clarification.
- it would help me if you can send the patches to [email protected] for me to pick up, as that ensures I don't forget them.

Arnd

#5 lore raw
Quoted 7 lines · Arnd Bergmann
Quoted 6 lines · David Lechner

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,

Quoted 7 lines
Quoted 3 lines

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?

Sure, no problem, just a few things:

- These are all cleanups that can wait until 6.17, right?

yes

Quoted 4 lines

- I see the driver has no in-tree users, and apparently never were. There is a imx28-ts4600.dts file that should reference it but doesn't. Do we have any indication that the driver works? Added Sebastien to Cc as well for clarification.

I dropped Sebastien in v5 because the emails bounced in v4, so I don't expect we will get a response. I'm not familiar with this driver or related hardware myself.

Quoted 4 lines

- it would help me if you can send the patches to [email protected] for me to pick up, as that ensures I don't forget them.

Arnd