linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: psmouse - when comparing PNP IDs ignore case
@ 2015-02-28  0:18 Dmitry Torokhov
  2015-02-28 10:15 ` Hans de Goede
  2015-03-02 22:14 ` Jeff Epler
  0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2015-02-28  0:18 UTC (permalink / raw)
  To: linux-input; +Cc: Hans de Goede, Benjamin Tissoires, linux-kernel

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

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/mouse/psmouse-base.c | 39 +++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 4ccd01d..a175496 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -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.2.0.rc0.207.ga3a616c


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Input: psmouse - when comparing PNP IDs ignore case
  2015-02-28  0:18 [PATCH] Input: psmouse - when comparing PNP IDs ignore case Dmitry Torokhov
@ 2015-02-28 10:15 ` Hans de Goede
  2015-03-02 22:14 ` Jeff Epler
  1 sibling, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2015-02-28 10:15 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input; +Cc: Benjamin Tissoires, linux-kernel

Hi,

On 28-02-15 01:18, Dmitry Torokhov wrote:
> PNP IDs are supposed to be case-insensitive and so we should compare
> them as such.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Looks good:

Acked-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans

> ---
>   drivers/input/mouse/psmouse-base.c | 39 +++++++++++++++++++++++++++++++-------
>   1 file changed, 32 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
> index 4ccd01d..a175496 100644
> --- a/drivers/input/mouse/psmouse-base.c
> +++ b/drivers/input/mouse/psmouse-base.c
> @@ -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;
>   }
>
>   /*
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Input: psmouse - when comparing PNP IDs ignore case
  2015-02-28  0:18 [PATCH] Input: psmouse - when comparing PNP IDs ignore case Dmitry Torokhov
  2015-02-28 10:15 ` Hans de Goede
@ 2015-03-02 22:14 ` Jeff Epler
  2015-03-02 22:19   ` Dmitry Torokhov
  1 sibling, 1 reply; 4+ messages in thread
From: Jeff Epler @ 2015-03-02 22:14 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, Hans de Goede, Benjamin Tissoires, linux-kernel

On Fri, Feb 27, 2015 at 04:18:52PM -0800, Dmitry Torokhov wrote:
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Input: psmouse - when comparing PNP IDs ignore case
  2015-03-02 22:14 ` Jeff Epler
@ 2015-03-02 22:19   ` Dmitry Torokhov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2015-03-02 22:19 UTC (permalink / raw)
  To: Jeff Epler; +Cc: linux-input, Hans de Goede, Benjamin Tissoires, linux-kernel

Hi Jeff,

On Mon, Mar 02, 2015 at 04:14:37PM -0600, Jeff Epler wrote:
> On Fri, Feb 27, 2015 at 04:18:52PM -0800, Dmitry Torokhov wrote:
> > 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.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-03-02 22:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-28  0:18 [PATCH] Input: psmouse - when comparing PNP IDs ignore case Dmitry Torokhov
2015-02-28 10:15 ` Hans de Goede
2015-03-02 22:14 ` Jeff Epler
2015-03-02 22:19   ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).