Linux Input/HID development
 help / color / mirror / Atom feed
From: Esben Haabendal <esben@geanix.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	 Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	 stable@vger.kernel.org,
	Esben Haabendal <esbenhaabendal@gmail.com>,
	 Esben Haabendal <esben@geanix.com>
Subject: [PATCH] Input: gpio_decoder - fix bit order reversal introduced by bitmap conversion
Date: Mon, 17 Aug 2026 13:50:27 +0200	[thread overview]
Message-ID: <20260817-gpio-decoder-bitrev-v1-1-6ffb77e323b8@geanix.com> (raw)

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>


             reply	other threads:[~2026-08-17 11:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17 11:50 Esben Haabendal [this message]
2026-08-17 13:37 ` [PATCH] Input: gpio_decoder - fix bit order reversal introduced by bitmap conversion Andy Shevchenko

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=20260817-gpio-decoder-bitrev-v1-1-6ffb77e323b8@geanix.com \
    --to=esben@geanix.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=esbenhaabendal@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox