[PATCH 6/7] Input: cros_ec_keyb - do not allocate keyboard state separately
From: Dmitry Torokhov
Date: Sat Feb 21 2026 - 19:38:06 EST
Now that we know the upper bound for the number of columnts, and know
that it is pretty small, there is no point in allocating it separately.
We are wasting more memory tracking the allocations.
Embed valid_keys and old_kb_state directly into cros_ec_keyb structure.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/input/keyboard/cros_ec_keyb.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
index 1b4ee30e1998..02176aee0530 100644
--- a/drivers/input/keyboard/cros_ec_keyb.c
+++ b/drivers/input/keyboard/cros_ec_keyb.c
@@ -59,8 +59,8 @@ struct cros_ec_keyb {
unsigned int cols;
int row_shift;
bool ghost_filter;
- u8 *valid_keys;
- u8 *old_kb_state;
+ u8 valid_keys[CROS_EC_KEYBOARD_COLS_MAX];
+ u8 old_kb_state[CROS_EC_KEYBOARD_COLS_MAX];
struct device *dev;
struct cros_ec_device *ec;
@@ -750,14 +750,6 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev)
return -EINVAL;
}
- ckdev->valid_keys = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL);
- if (!ckdev->valid_keys)
- return -ENOMEM;
-
- ckdev->old_kb_state = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL);
- if (!ckdev->old_kb_state)
- return -ENOMEM;
-
/*
* We call the keyboard matrix 'input0'. Allocate phys before input
* dev, to ensure correct tear-down ordering.
--
2.53.0.345.g96ddfc5eaa-goog