From c7b9c400fa549cd649606894aa3902a226957ce8 Mon Sep 17 00:00:00 2001 From: sdk Date: Sat, 23 Jul 2022 05:55:16 +0000 Subject: [PATCH] Discard relative movement packets outside of [-127, 127] range to prevent cursor jumps when using the trackpoint on some lenovo laptops. Known affected models: - Lenovo Thinkpad X13 Gen1 - Lenovo Thinkpad T14(s) - Lenovo Thinkpad E15 Gen3 - Lenovo A475 With help from stsp@ OK stsp@ miod@ deraadt@ bru@ --- sys/dev/pckbc/pms.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys/dev/pckbc/pms.c b/sys/dev/pckbc/pms.c index 0fc2910860e..42121347c3a 100644 --- a/sys/dev/pckbc/pms.c +++ b/sys/dev/pckbc/pms.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pms.c,v 1.96 2022/04/06 18:59:30 naddy Exp $ */ +/* $OpenBSD: pms.c,v 1.97 2022/07/23 05:55:16 sdk Exp $ */ /* $NetBSD: psm.c,v 1.11 2000/06/05 22:20:57 sommerfeld Exp $ */ /*- @@ -2610,6 +2610,16 @@ pms_proc_elantech_v4(struct pms_softc *sc) case ELANTECH_PKT_TRACKPOINT: if (sc->sc_dev_enable & PMS_DEV_SECONDARY) { + /* + * This firmware misreport coordinates for trackpoint + * occasionally. Discard packets outside of [-127, 127] range + * to prevent cursor jumps. + */ + if (sc->packet[4] == 0x80 || sc->packet[5] == 0x80 || + sc->packet[1] >> 7 == sc->packet[4] >> 7 || + sc->packet[2] >> 7 == sc->packet[5] >> 7) + return; + x = sc->packet[4] - 0x100 + (sc->packet[1] << 1); y = sc->packet[5] - 0x100 + (sc->packet[2] << 1); buttons = butmap[sc->packet[0] & 7]; -- 2.20.1