Skip to contentSkip to conversation

Input: psmouse - when comparing PNP IDs ignore case

PATCH In review Dmitry Torokhov 3 participants 4 messages Feb 28, 2015 – Mar 2, 2015

Subsystems (2)
lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

PATCH 1/1 Input: psmouse - when comparing PNP IDs ignore case

PNP IDs are supposed to be case-insensitive and so we should compare them as such.

---
 drivers/input/mouse/psmouse-base.c | 39 +++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)
drivers/input/mouse/psmouse-base.c +32 -7
index 4ccd01d..a175496 100644
@@ -463,19 +463,44 @@ 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[])
+{
+	int i;
+
+	for (i = 0; ids[i]; i++)
+		if (!strcasecmp(id, ids[i]))
+			return true;
+
+	return false;
+}
+
 /*
  * psmouse_matches_pnp_id - check if psmouse matches one of the passed in ids.
  */
 bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[])
 {
-	int i;
-
-	if (!strncmp(psmouse->ps2dev.serio->firmware_id, "PNP:", 4))
-		for (i = 0; ids[i]; i++)
-			if (strstr(psmouse->ps2dev.serio->firmware_id, ids[i]))
-				return true;
+	struct serio *serio = psmouse->ps2dev.serio;
+	char *p, *fw_id_copy, *save_ptr;
+	bool found = false;
+
+	if (!strncmp(serio->firmware_id, "PNP:", 4))
+		return false;
+
+	fw_id_copy = kstrndup(&serio->firmware_id[4],
+			      sizeof(serio->firmware_id) - 4,
+			      GFP_KERNEL);
+	if (!fw_id_copy)
+		return false;
+
+	save_ptr = fw_id_copy;
+	while ((p = strsep(&fw_id_copy, " ")) != NULL) {
+		if (psmouse_check_pnp_id(p, ids))
+			found = true;
+			break;
+	}
 
-	return false;
+	kfree(save_ptr);
+	return found;
 }
 
 /*
Signature · 5 lines
2.2.0.rc0.207.ga3a616c


-- 
Dmitry
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 4 lines · Dmitry Torokhov

PNP IDs are supposed to be case-insensitive and so we should compare them as such.

Looks good:

Regards,

Hans

Quoted 61 lines
---
  drivers/input/mouse/psmouse-base.c | 39 +++++++++++++++++++++++++++++++-------
  1 file changed, 32 insertions(+), 7 deletions(-)
drivers/input/mouse/psmouse-base.c +32 -7
index 4ccd01d..a175496 100644
@@ -463,19 +463,44 @@ 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[])
+{
+	int i;
+
+	for (i = 0; ids[i]; i++)
+		if (!strcasecmp(id, ids[i]))
+			return true;
+
+	return false;
+}
+
  /*
   * psmouse_matches_pnp_id - check if psmouse matches one of the passed in ids.
   */
  bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[])
  {
-	int i;
-
-	if (!strncmp(psmouse->ps2dev.serio->firmware_id, "PNP:", 4))
-		for (i = 0; ids[i]; i++)
-			if (strstr(psmouse->ps2dev.serio->firmware_id, ids[i]))
-				return true;
+	struct serio *serio = psmouse->ps2dev.serio;
+	char *p, *fw_id_copy, *save_ptr;
+	bool found = false;
+
+	if (!strncmp(serio->firmware_id, "PNP:", 4))
+		return false;
+
+	fw_id_copy = kstrndup(&serio->firmware_id[4],
+			      sizeof(serio->firmware_id) - 4,
+			      GFP_KERNEL);
+	if (!fw_id_copy)
+		return false;
+
+	save_ptr = fw_id_copy;
+	while ((p = strsep(&fw_id_copy, " ")) != NULL) {
+		if (psmouse_check_pnp_id(p, ids))
+			found = true;
+			break;
+	}
 
-	return false;
+	kfree(save_ptr);
+	return found;
  }
 
  /*
#2 lore raw
In reply to Dmitry Torokhov
Quoted 2 lines · Dmitry Torokhov

PNP IDs are supposed to be case-insensitive and so we should compare them as such.

Have specific systems popped up which need this fix, or is it just in the interests of being correct? If there are specific system(s) that are affected, it would be valuable to list them or at least say so.

Jeff

author maintainer
#3 lore raw

Hi Jeff,

Quoted 7 lines · Jeff Epler
Quoted 2 lines · Dmitry Torokhov

PNP IDs are supposed to be case-insensitive and so we should compare them as such.

Have specific systems popped up which need this fix, or is it just in the interests of being correct? If there are specific system(s) that are affected, it would be valuable to list them or at least say so.

It is needed by another patch identifying SYN300D as a forcepad whereas in BIOS it is actually SYN300d. While we could change the kernel to match against SYN300d I am not sure if somebody else won't use SYN300D in some other BIOS.

Thanks.

Signature · 1 line
Dmitry