diff mbox series

Input: elantench - Fix the firmware misreport coordinates for trackpoint occasionally.

Message ID 20210729010940.5752-1-phoenix@emc.com.tw
State New
Headers show
Series Input: elantench - Fix the firmware misreport coordinates for trackpoint occasionally. | expand

Commit Message

phoenix July 29, 2021, 1:09 a.m. UTC
Signed-off-by: Phoenix Huang <phoenix@emc.com.tw>
---
 drivers/input/mouse/elantech.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

phoenix Aug. 30, 2021, 12:19 p.m. UTC | #1
Hi Dmitry,

Would you review this patch, thanks

Best regards,
Phoenix Huang

-----Original Message-----
From: Phoenix Huang [mailto:phoenix@emc.com.tw] 

Sent: Thursday, July 29, 2021 9:10 AM
To: linux-kernel@vger.kernel.org; linux-input@vger.kernel.org;
dmitry.torokhov@gmail.com
Cc: jingle.wu@emc.com.tw; josh.chen@emc.com.tw; dave.wang@emc.com.tw;
Phoenix Huang <phoenix@emc.com.tw>
Subject: [PATCH] Input: elantench - Fix the firmware misreport coordinates
for trackpoint occasionally.

Signed-off-by: Phoenix Huang <phoenix@emc.com.tw>

---
 drivers/input/mouse/elantech.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 2d0bc029619f..07e1098f2d31 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -517,6 +517,17 @@ static void elantech_report_trackpoint(struct psmouse
*psmouse,
 	case 0x16008020U:
 	case 0x26800010U:
 	case 0x36808000U:
+	
+		/* This firmware misreport coordinates for trackpoint
occasionally.
+		* So we discard these packets by pattern to prevent cursor
jumps.
+		*/
+		if (packet[4] == 0x80 || packet[5] == 0x80 ||
+		    packet[1] >> 7 == packet[4] >> 7 ||
+		    packet[2] >> 7 == packet[5] >> 7) {
+		    	elantech_debug("discarding packet [%6ph]\n",
packet);
+			break;
+
+		}
 		x = packet[4] - (int)((packet[1]^0x80) << 1);
 		y = (int)((packet[2]^0x80) << 1) - packet[5];
 
--
2.25.1
Dmitry Torokhov Aug. 30, 2021, 8:23 p.m. UTC | #2
Hi Phoenix,

On Mon, Aug 30, 2021 at 08:19:48PM +0800, phoenix wrote:
> Hi Dmitry,

> 

> Would you review this patch, thanks

> 

> Best regards,

> Phoenix Huang

> 

> -----Original Message-----

> From: Phoenix Huang [mailto:phoenix@emc.com.tw] 

> Sent: Thursday, July 29, 2021 9:10 AM

> To: linux-kernel@vger.kernel.org; linux-input@vger.kernel.org;

> dmitry.torokhov@gmail.com

> Cc: jingle.wu@emc.com.tw; josh.chen@emc.com.tw; dave.wang@emc.com.tw;

> Phoenix Huang <phoenix@emc.com.tw>

> Subject: [PATCH] Input: elantench - Fix the firmware misreport coordinates

> for trackpoint occasionally.

> 

> Signed-off-by: Phoenix Huang <phoenix@emc.com.tw>

> ---

>  drivers/input/mouse/elantech.c | 11 +++++++++++

>  1 file changed, 11 insertions(+)

> 

> diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c

> index 2d0bc029619f..07e1098f2d31 100644

> --- a/drivers/input/mouse/elantech.c

> +++ b/drivers/input/mouse/elantech.c

> @@ -517,6 +517,17 @@ static void elantech_report_trackpoint(struct psmouse

> *psmouse,

>  	case 0x16008020U:

>  	case 0x26800010U:

>  	case 0x36808000U:

> +	

> +		/* This firmware misreport coordinates for trackpoint

> occasionally.

> +		* So we discard these packets by pattern to prevent cursor

> jumps.

> +		*/

> +		if (packet[4] == 0x80 || packet[5] == 0x80 ||

> +		    packet[1] >> 7 == packet[4] >> 7 ||


I think this will reject X coordinates in range [0, 127]. Is this really
what is needed? What kind of patterns are you observing when firmware
misreports coordinates?

Thanks.

-- 
Dmitry
phoenix Sept. 10, 2021, 2:18 a.m. UTC | #3
Hi Dmity,

Sorry for late reply.
> +		if (packet[4] == 0x80 || packet[5] == 0x80 ||

> +		    packet[1] >> 7 == packet[4] >> 7 ||

"I think this will reject X coordinates in range [0, 127]. Is this really
what is needed? What kind of patterns are you observing when firmware
misreports coordinates?"
this will reject X in range [128, 256] and [-128, -256]. This patch prevent
cursor suddenly jump to screen edge or corner.
The patterns we observing as below:
1. x (packet[4]) or y (packet[5]) is 0x80, ex: [xx xx xx xx 80 80]
2. ~x sign bit is same as MSB(most significant bit) of x, ex: [30 00 00 06
00 00] 
3. ~y sign bit is same as MSB of y, ex: [30 00 00 06 fa 00]

Best regards,
Phoenix Huang
-----Original Message-----
From: Dmitry Torokhov [mailto:dmitry.torokhov@gmail.com] 

Sent: Tuesday, August 31, 2021 4:24 AM
To: phoenix <phoenix@emc.com.tw>
Cc: linux-kernel@vger.kernel.org; linux-input@vger.kernel.org;
jingle.wu@emc.com.tw; josh.chen@emc.com.tw; dave.wang@emc.com.tw
Subject: Re: [PATCH] Input: elantench - Fix the firmware misreport
coordinates for trackpoint occasionally.

Hi Phoenix,

On Mon, Aug 30, 2021 at 08:19:48PM +0800, phoenix wrote:
> Hi Dmitry,

> 

> Would you review this patch, thanks

> 

> Best regards,

> Phoenix Huang

> 

> -----Original Message-----

> From: Phoenix Huang [mailto:phoenix@emc.com.tw]

> Sent: Thursday, July 29, 2021 9:10 AM

> To: linux-kernel@vger.kernel.org; linux-input@vger.kernel.org; 

> dmitry.torokhov@gmail.com

> Cc: jingle.wu@emc.com.tw; josh.chen@emc.com.tw; dave.wang@emc.com.tw; 

> Phoenix Huang <phoenix@emc.com.tw>

> Subject: [PATCH] Input: elantench - Fix the firmware misreport 

> coordinates for trackpoint occasionally.

> 

> Signed-off-by: Phoenix Huang <phoenix@emc.com.tw>

> ---

>  drivers/input/mouse/elantech.c | 11 +++++++++++

>  1 file changed, 11 insertions(+)

> 

> diff --git a/drivers/input/mouse/elantech.c 

> b/drivers/input/mouse/elantech.c index 2d0bc029619f..07e1098f2d31 

> 100644

> --- a/drivers/input/mouse/elantech.c

> +++ b/drivers/input/mouse/elantech.c

> @@ -517,6 +517,17 @@ static void elantech_report_trackpoint(struct 

> psmouse *psmouse,

>  	case 0x16008020U:

>  	case 0x26800010U:

>  	case 0x36808000U:

> +	

> +		/* This firmware misreport coordinates for trackpoint

> occasionally.

> +		* So we discard these packets by pattern to prevent cursor

> jumps.

> +		*/

> +		if (packet[4] == 0x80 || packet[5] == 0x80 ||

> +		    packet[1] >> 7 == packet[4] >> 7 ||


I think this will reject X coordinates in range [0, 127]. Is this really
what is needed? What kind of patterns are you observing when firmware
misreports coordinates?

Thanks.

--
Dmitry
diff mbox series

Patch

diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 2d0bc029619f..07e1098f2d31 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -517,6 +517,17 @@  static void elantech_report_trackpoint(struct psmouse *psmouse,
 	case 0x16008020U:
 	case 0x26800010U:
 	case 0x36808000U:
+	
+		/* This firmware misreport coordinates for trackpoint occasionally.
+		* So we discard these packets by pattern to prevent cursor jumps.
+		*/
+		if (packet[4] == 0x80 || packet[5] == 0x80 ||
+		    packet[1] >> 7 == packet[4] >> 7 ||
+		    packet[2] >> 7 == packet[5] >> 7) {
+		    	elantech_debug("discarding packet [%6ph]\n", packet);
+			break;
+
+		}
 		x = packet[4] - (int)((packet[1]^0x80) << 1);
 		y = (int)((packet[2]^0x80) << 1) - packet[5];