From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Fabio Baltieri <fabiobaltieri@chromium.org>,
Benson Leung <bleung@chromium.org>
Cc: Guenter Roeck <groeck@chromium.org>,
Simon Glass <sjg@chromium.org>,
Tzung-Bi Shih <tzungbi@kernel.org>,
linux-input@vger.kernel.org, chrome-platform@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH 5/7] Input: cros_ec_keyb - simplify cros_ec_keyb_work()
Date: Sat, 21 Feb 2026 16:37:13 -0800 [thread overview]
Message-ID: <20260222003717.471977-5-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20260222003717.471977-1-dmitry.torokhov@gmail.com>
Introduce temporaries for event_data pointer and event_size to simplify
the code a bit.
In cros_ec_keyb_compute_valid_keys() explicitly compare with
KEY_RESERVED to make the intent of the comparison more clear.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/keyboard/cros_ec_keyb.c | 28 +++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
index fabbdbc22785..1b4ee30e1998 100644
--- a/drivers/input/keyboard/cros_ec_keyb.c
+++ b/drivers/input/keyboard/cros_ec_keyb.c
@@ -330,8 +330,10 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
{
struct cros_ec_keyb *ckdev = container_of(nb, struct cros_ec_keyb,
notifier);
- u32 val;
+ struct ec_response_get_next_event_v3 *event_data;
+ unsigned int event_size;
unsigned int ev_type;
+ u32 val;
/*
* If not wake enabled, discard key state changes during
@@ -341,32 +343,32 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
if (queued_during_suspend && !device_may_wakeup(ckdev->dev))
return NOTIFY_OK;
- switch (ckdev->ec->event_data.event_type) {
+ event_data = &ckdev->ec->event_data;
+ event_size = ckdev->ec->event_size;
+
+ switch (event_data->event_type) {
case EC_MKBP_EVENT_KEY_MATRIX:
pm_wakeup_event(ckdev->dev, 0);
if (!ckdev->idev) {
- dev_warn_once(ckdev->dev,
- "Unexpected key matrix event\n");
+ dev_warn_once(ckdev->dev, "Unexpected key matrix event\n");
return NOTIFY_OK;
}
- if (ckdev->ec->event_size != ckdev->cols) {
+ if (event_size != ckdev->cols) {
dev_err(ckdev->dev,
"Discarded key matrix event, unexpected length: %d != %d\n",
ckdev->ec->event_size, ckdev->cols);
return NOTIFY_OK;
}
- cros_ec_keyb_process(ckdev,
- ckdev->ec->event_data.data.key_matrix,
- ckdev->ec->event_size);
+ cros_ec_keyb_process(ckdev, event_data->data.key_matrix, event_size);
break;
case EC_MKBP_EVENT_SYSRQ:
pm_wakeup_event(ckdev->dev, 0);
- val = get_unaligned_le32(&ckdev->ec->event_data.data.sysrq);
+ val = get_unaligned_le32(&event_data->data.sysrq);
dev_dbg(ckdev->dev, "sysrq code from EC: %#x\n", val);
handle_sysrq(val);
break;
@@ -376,12 +378,10 @@ static int cros_ec_keyb_work(struct notifier_block *nb,
pm_wakeup_event(ckdev->dev, 0);
if (ckdev->ec->event_data.event_type == EC_MKBP_EVENT_BUTTON) {
- val = get_unaligned_le32(
- &ckdev->ec->event_data.data.buttons);
+ val = get_unaligned_le32(&event_data->data.buttons);
ev_type = EV_KEY;
} else {
- val = get_unaligned_le32(
- &ckdev->ec->event_data.data.switches);
+ val = get_unaligned_le32(&event_data->data.switches);
ev_type = EV_SW;
}
cros_ec_keyb_report_bs(ckdev, ev_type, val);
@@ -410,7 +410,7 @@ static void cros_ec_keyb_compute_valid_keys(struct cros_ec_keyb *ckdev)
for (col = 0; col < ckdev->cols; col++) {
for (row = 0; row < ckdev->rows; row++) {
code = keymap[MATRIX_SCAN_CODE(row, col, row_shift)];
- if (code && (code != KEY_BATTERY))
+ if (code != KEY_RESERVED && code != KEY_BATTERY)
ckdev->valid_keys[col] |= BIT(row);
}
dev_dbg(ckdev->dev, "valid_keys[%02d] = 0x%02x\n",
--
2.53.0.345.g96ddfc5eaa-goog
next prev parent reply other threads:[~2026-02-22 0:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-22 0:37 [PATCH 1/7] Input: export input_default_setkeycode Dmitry Torokhov
2026-02-22 0:37 ` [PATCH 2/7] Input: cros_ec_keyb - add function key support Dmitry Torokhov
2026-02-22 10:46 ` Tzung-Bi Shih
2026-02-23 3:47 ` Dmitry Torokhov
2026-02-23 12:24 ` Fabio Baltieri
2026-02-22 0:37 ` [PATCH 3/7] Input: cros_ec_keyb - use u8 instead of uint8_t Dmitry Torokhov
2026-02-22 10:47 ` Tzung-Bi Shih
2026-02-22 0:37 ` [PATCH 4/7] Input: cros_ec_keyb - use BIT() macro instead of open-coding shifts Dmitry Torokhov
2026-02-22 10:47 ` Tzung-Bi Shih
2026-02-22 0:37 ` Dmitry Torokhov [this message]
2026-02-22 10:47 ` [PATCH 5/7] Input: cros_ec_keyb - simplify cros_ec_keyb_work() Tzung-Bi Shih
2026-02-23 3:49 ` Dmitry Torokhov
2026-02-23 4:41 ` Tzung-Bi Shih
2026-02-22 0:37 ` [PATCH 6/7] Input: cros_ec_keyb - do not allocate keyboard state separately Dmitry Torokhov
2026-02-22 10:48 ` Tzung-Bi Shih
2026-02-22 0:37 ` [PATCH 7/7] Input: cros_ec_keyb - factor out column processing Dmitry Torokhov
2026-02-22 10:48 ` Tzung-Bi Shih
2026-02-23 3:51 ` Dmitry Torokhov
2026-02-23 4:40 ` Tzung-Bi Shih
2026-02-22 10:46 ` [PATCH 1/7] Input: export input_default_setkeycode Tzung-Bi Shih
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=20260222003717.471977-5-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=fabiobaltieri@chromium.org \
--cc=groeck@chromium.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sjg@chromium.org \
--cc=tzungbi@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