mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jonas Rebmann <jre@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 BAREBOX <barebox@lists.infradead.org>
Cc: Jonas Rebmann <jre@pengutronix.de>
Subject: [PATCH v2 1/2] input: add input_is_key_pressed() to read single key
Date: Thu, 07 May 2026 15:48:23 +0200	[thread overview]
Message-ID: <20260507-input_is_key_pressed-v2-1-3c43453a199d@pengutronix.de> (raw)
In-Reply-To: <20260507-input_is_key_pressed-v2-0-3c43453a199d@pengutronix.de>

input_key_get_status() while being powerful and able to read all key
states at once, is difficult to use correctly, as the single incorrect
usage in upstream code shows.

Reading multiple key states at once, for any meaningful number of keys
combined (typically up to three) provides no advantage over checking the
keys sequentially.

Provide a simple input_is_key_pressed() function that checks a single
keycode.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 drivers/input/input.c | 14 ++++++++++++++
 include/input/input.h |  1 +
 2 files changed, 15 insertions(+)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index e5509bf90d..5ee63d94d6 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -84,6 +84,20 @@ void input_key_get_status(unsigned long *keys, int bits)
 		bitmap_or(keys, keys, idev->keys, bits);
 }
 
+bool input_is_key_pressed(int key)
+{
+	struct input_device *idev;
+
+	if (key > KEY_MAX)
+		return false;
+
+	list_for_each_entry(idev, &input_devices, list)
+		if (test_bit(key, idev->keys))
+			return true;
+
+	return false;
+}
+
 struct input_console {
 	struct console_device console;
 	struct input_notifier notifier;
diff --git a/include/input/input.h b/include/input/input.h
index 9445d20e56..3e03eb9a65 100644
--- a/include/input/input.h
+++ b/include/input/input.h
@@ -24,6 +24,7 @@ int input_device_register(struct input_device *);
 void input_device_unregister(struct input_device *);
 
 void input_key_get_status(unsigned long *keys, int bits);
+bool input_is_key_pressed(int key);
 
 struct input_notifier {
 	void (*notify)(struct input_notifier *in, struct input_event *event);

-- 
2.53.0.610.g30c4861dc6




  reply	other threads:[~2026-05-07 13:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 13:48 [PATCH v2 0/2] input: Supersede input_key_get_status() with input_is_key_pressed() Jonas Rebmann
2026-05-07 13:48 ` Jonas Rebmann [this message]
2026-05-07 13:48 ` [PATCH v2 2/2] ARM: boards: protonic-imx6: use input_is_key_pressed() Jonas Rebmann

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=20260507-input_is_key_pressed-v2-1-3c43453a199d@pengutronix.de \
    --to=jre@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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