[PATCH] Input: gpio_decoder - fix bit order reversal introduced by bitmap conversion

Esben Haabendal <[email protected]>
Newsgroups org.kernel.vger.linux-input,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
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: [email protected]
Signed-off-by: Esben Haabendal <[email protected]>
---
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 <[email protected]>
---
 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 <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.