diff options
| author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2026-07-26 22:08:00 -0700 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2026-08-03 17:06:26 -0700 |
| commit | c1df7e4e4951ee786c2e5eec002ac3a56848ea1f (patch) | |
| tree | c28d737a29e027e115440023c7bc694454befb90 /drivers/input | |
| parent | ad8d3b91e48e1d9b7f94a5cc46cd6e4fd58dc6f5 (diff) | |
Input: psmouse - modernize PNP ID parsing
Rewrite psmouse_matches_pnp_id() to parse and match the space-separated
PNP ID string directly in place without dynamic memory allocation.
Assisted-by: Antigravity:gemini-3.5-flash
Link: https://patch.msgid.link/20260727050803.1269941-3-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
| -rw-r--r-- | drivers/input/mouse/psmouse-base.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c index 668a6a4fbe82..d87fefded859 100644 --- a/drivers/input/mouse/psmouse-base.c +++ b/drivers/input/mouse/psmouse-base.c @@ -492,13 +492,16 @@ static int psmouse_poll(struct psmouse *psmouse) PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)); } -static bool psmouse_check_pnp_id(const char *id, const char * const ids[]) +static bool psmouse_check_pnp_id(const char *p, const char * const ids[]) { - int i; + const char * const *id; + size_t len; - for (i = 0; ids[i]; i++) - if (!strcasecmp(id, ids[i])) + for (id = ids; *id; id++) { + len = strlen(*id); + if (!strncasecmp(p, *id, len) && (p[len] == ' ' || p[len] == '\0')) return true; + } return false; } @@ -509,28 +512,26 @@ static bool psmouse_check_pnp_id(const char *id, const char * const ids[]) bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[]) { struct serio *serio = psmouse->ps2dev.serio; - char *p, *fw_id_copy, *save_ptr; - bool found = false; + const char *p = serio->firmware_id; - if (strncmp(serio->firmware_id, "PNP: ", 5)) + if (!strstarts(p, "PNP: ")) return false; - fw_id_copy = kstrndup(&serio->firmware_id[5], - sizeof(serio->firmware_id) - 5, - GFP_KERNEL); - if (!fw_id_copy) - return false; + p += 5; + while (*p) { + p = skip_spaces(p); + if (!*p) + break; - save_ptr = fw_id_copy; - while ((p = strsep(&fw_id_copy, " ")) != NULL) { - if (psmouse_check_pnp_id(p, ids)) { - found = true; + if (psmouse_check_pnp_id(p, ids)) + return true; + + p = strchr(p, ' '); + if (!p) break; - } } - kfree(save_ptr); - return found; + return false; } /* |
