Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] Input: gpio_decoder - fix bit order reversal introduced by bitmap conversion
@ 2026-08-17 11:50 Esben Haabendal
  2026-08-17 13:37 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Esben Haabendal @ 2026-08-17 11:50 UTC (permalink / raw)
  To: Dmitry Torokhov, Andy Shevchenko
  Cc: linux-input, linux-kernel, stable, Esben Haabendal,
	Esben Haabendal

The switch from a manual loop to gpiod_get_array_value_cansleep() +
bitmap_read() inadvertently reversed the bit order of the decoded value.
The original loop treated GPIO[0] as MSB by shifting left on each
iteration, but bitmap_read() returns GPIO[0] at bit 0 (LSB).

The previous bit order was correct according to device-tree bindings, and
the change broke existing users.

Fixes: 4eec8772e4f5 ("Input: gpio_decoder - replace custom loop by gpiod_get_array_value_cansleep()")
Cc: stable@vger.kernel.org
Signed-off-by: Esben Haabendal <esbenhaabendal@gmail.com>
---
The refactoring from a custom loop to gpiod_get_array_value_cansleep() +
bitmap_read() caused the bit order to be changed from reading MSB first to
LSB first.

The device-tree bindings explicitly states that that it should be MSB
first, and the change obviously is a regression for existing users.

Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 drivers/input/misc/gpio_decoder.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/gpio_decoder.c b/drivers/input/misc/gpio_decoder.c
index 0e4a49845afa..055bfcbd5235 100644
--- a/drivers/input/misc/gpio_decoder.c
+++ b/drivers/input/misc/gpio_decoder.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/bitmap.h>
+#include <linux/bitrev.h>
 #include <linux/dev_printk.h>
 #include <linux/device/devres.h>
 #include <linux/err.h>
@@ -39,7 +40,7 @@ static int gpio_decoder_get_gpios_state(struct gpio_decoder *decoder)
 		return err;
 	}
 
-	return bitmap_read(values, 0, size);
+	return bitrev32(bitmap_read(values, 0, size)) >> (32 - size);
 }
 
 static void gpio_decoder_poll_gpios(struct input_dev *input)

---
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
change-id: 20260817-gpio-decoder-bitrev-2457d68fd62b

Best regards,
--  
Esben Haabendal <esben@geanix.com>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-17 13:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 11:50 [PATCH] Input: gpio_decoder - fix bit order reversal introduced by bitmap conversion Esben Haabendal
2026-08-17 13:37 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox