Tue Sep 5 05:55:12 2023 UTC ()
panic on an condition that shouldn't be possible.

appease GCC 12.


(mrg)
diff -r1.40 -r1.41 src/sys/dev/pckbport/pms.c
diff -r1.81 -r1.82 src/sys/dev/pckbport/synaptics.c

cvs diff -r1.40 -r1.41 src/sys/dev/pckbport/pms.c (expand / switch to unified diff)

--- src/sys/dev/pckbport/pms.c 2022/10/28 23:40:37 1.40
+++ src/sys/dev/pckbport/pms.c 2023/09/05 05:55:12 1.41
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pms.c,v 1.40 2022/10/28 23:40:37 riastradh Exp $ */ 1/* $NetBSD: pms.c,v 1.41 2023/09/05 05:55:12 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2004 Kentaro Kurahone. 4 * Copyright (c) 2004 Kentaro Kurahone.
5 * Copyright (c) 2004 Ales Krenek. 5 * Copyright (c) 2004 Ales Krenek.
6 * Copyright (c) 1994 Charles M. Hannum. 6 * Copyright (c) 1994 Charles M. Hannum.
7 * Copyright (c) 1992, 1993 Erik Forsberg. 7 * Copyright (c) 1992, 1993 Erik Forsberg.
8 * All rights reserved. 8 * All rights reserved.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: pms.c,v 1.40 2022/10/28 23:40:37 riastradh Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: pms.c,v 1.41 2023/09/05 05:55:12 mrg Exp $");
30 30
31#include "opt_pms.h" 31#include "opt_pms.h"
32 32
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/systm.h> 34#include <sys/systm.h>
35#include <sys/device.h> 35#include <sys/device.h>
36#include <sys/ioctl.h> 36#include <sys/ioctl.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/kthread.h> 38#include <sys/kthread.h>
39 39
40#include <sys/bus.h> 40#include <sys/bus.h>
41 41
42#include <dev/pckbport/pckbportvar.h> 42#include <dev/pckbport/pckbportvar.h>
@@ -551,26 +551,28 @@ pmsinput(void *vsc, int data) @@ -551,26 +551,28 @@ pmsinput(void *vsc, int data)
551 } 551 }
552 } 552 }
553 sc->last = sc->current; 553 sc->last = sc->current;
554 554
555 if (sc->inputstate == 0) { 555 if (sc->inputstate == 0) {
556 /* 556 /*
557 * Some devices (seen on trackballs anytime, and on 557 * Some devices (seen on trackballs anytime, and on
558 * some mice shortly after reset) output garbage bytes 558 * some mice shortly after reset) output garbage bytes
559 * between packets. Just ignore them. 559 * between packets. Just ignore them.
560 */ 560 */
561 if ((data & 0xc0) != 0) 561 if ((data & 0xc0) != 0)
562 return; /* not in sync yet, discard input */ 562 return; /* not in sync yet, discard input */
563 } 563 }
 564 if (sc->inputstate >= sizeof(sc->packet))
 565 panic("inputstate should never be %d", sc->inputstate);
564 566
565 sc->packet[sc->inputstate++] = data & 0xff; 567 sc->packet[sc->inputstate++] = data & 0xff;
566 switch (sc->inputstate) { 568 switch (sc->inputstate) {
567 case 0: 569 case 0:
568 /* no useful processing can be done yet */ 570 /* no useful processing can be done yet */
569 break; 571 break;
570 572
571 case 1: 573 case 1:
572 /* 574 /*
573 * Why should we test for bit 0x8 and insist on it here? 575 * Why should we test for bit 0x8 and insist on it here?
574 * The old (psm.c and psm_intelli.c) drivers didn't do 576 * The old (psm.c and psm_intelli.c) drivers didn't do
575 * it, and there are devices where it does harm (that's 577 * it, and there are devices where it does harm (that's
576 * why it is not used if using PMS_STANDARD protocol). 578 * why it is not used if using PMS_STANDARD protocol).

cvs diff -r1.81 -r1.82 src/sys/dev/pckbport/synaptics.c (expand / switch to unified diff)

--- src/sys/dev/pckbport/synaptics.c 2022/09/28 16:43:00 1.81
+++ src/sys/dev/pckbport/synaptics.c 2023/09/05 05:55:12 1.82
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: synaptics.c,v 1.81 2022/09/28 16:43:00 nia Exp $ */ 1/* $NetBSD: synaptics.c,v 1.82 2023/09/05 05:55:12 mrg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2005, Steve C. Woodford 4 * Copyright (c) 2005, Steve C. Woodford
5 * Copyright (c) 2004, Ales Krenek 5 * Copyright (c) 2004, Ales Krenek
6 * Copyright (c) 2004, Kentaro A. Kurahone 6 * Copyright (c) 2004, Kentaro A. Kurahone
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 12 *
13 * * Redistributions of source code must retain the above copyright 13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -38,27 +38,27 @@ @@ -38,27 +38,27 @@
38/* 38/*
39 * TODO: 39 * TODO:
40 * - Make the sysctl values per-instance instead of global. 40 * - Make the sysctl values per-instance instead of global.
41 * - Consider setting initial scaling factors at runtime according 41 * - Consider setting initial scaling factors at runtime according
42 * to the values returned by the 'Read Resolutions' command. 42 * to the values returned by the 'Read Resolutions' command.
43 * - Support the serial protocol (we only support PS/2 for now) 43 * - Support the serial protocol (we only support PS/2 for now)
44 * - Support auto-repeat for up/down button Z-axis emulation. 44 * - Support auto-repeat for up/down button Z-axis emulation.
45 * - Maybe add some more gestures (can we use Palm support somehow?) 45 * - Maybe add some more gestures (can we use Palm support somehow?)
46 */ 46 */
47 47
48#include "opt_pms.h" 48#include "opt_pms.h"
49 49
50#include <sys/cdefs.h> 50#include <sys/cdefs.h>
51__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.81 2022/09/28 16:43:00 nia Exp $"); 51__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.82 2023/09/05 05:55:12 mrg Exp $");
52 52
53#include <sys/param.h> 53#include <sys/param.h>
54#include <sys/systm.h> 54#include <sys/systm.h>
55#include <sys/device.h> 55#include <sys/device.h>
56#include <sys/ioctl.h> 56#include <sys/ioctl.h>
57#include <sys/sysctl.h> 57#include <sys/sysctl.h>
58#include <sys/kernel.h> 58#include <sys/kernel.h>
59#include <sys/proc.h> 59#include <sys/proc.h>
60 60
61#include <sys/bus.h> 61#include <sys/bus.h>
62 62
63#include <dev/pckbport/pckbportvar.h> 63#include <dev/pckbport/pckbportvar.h>
64 64
@@ -1749,26 +1749,28 @@ pms_synaptics_input(void *vsc, int data) @@ -1749,26 +1749,28 @@ pms_synaptics_input(void *vsc, int data)
1749 /*FALLTHROUGH*/ 1749 /*FALLTHROUGH*/
1750 1750
1751 case -6: 1751 case -6:
1752 case 3: 1752 case 3:
1753 if ((data & 8) == 8) { 1753 if ((data & 8) == 8) {
1754 aprint_debug_dev(psc->sc_dev, 1754 aprint_debug_dev(psc->sc_dev,
1755 "pms_synaptics_input: dropped in relative mode, reset\n"); 1755 "pms_synaptics_input: dropped in relative mode, reset\n");
1756 psc->inputstate = 0; 1756 psc->inputstate = 0;
1757 psc->sc_enabled = 0; 1757 psc->sc_enabled = 0;
1758 wakeup(&psc->sc_enabled); 1758 wakeup(&psc->sc_enabled);
1759 return; 1759 return;
1760 } 1760 }
1761 } 1761 }
 1762 if (psc->inputstate >= sizeof(psc->packet))
 1763 panic("inputstate should never be %d", psc->inputstate);
1762 1764
1763 psc->packet[psc->inputstate++] = data & 0xff; 1765 psc->packet[psc->inputstate++] = data & 0xff;
1764 if (psc->inputstate == 6) { 1766 if (psc->inputstate == 6) {
1765 /* 1767 /*
1766 * We have a complete packet. 1768 * We have a complete packet.
1767 * Extract the pertinent details. 1769 * Extract the pertinent details.
1768 */ 1770 */
1769 psc->inputstate = 0; 1771 psc->inputstate = 0;
1770 if ((psc->packet[0] & 0xfc) == 0x84 && 1772 if ((psc->packet[0] & 0xfc) == 0x84 &&
1771 (psc->packet[3] & 0xcc) == 0xc4) { 1773 (psc->packet[3] & 0xcc) == 0xc4) {
1772 /* W = SYNAPTICS_WIDTH_PASSTHROUGH, PS/2 passthrough */ 1774 /* W = SYNAPTICS_WIDTH_PASSTHROUGH, PS/2 passthrough */
1773 pms_synaptics_passthrough(psc); 1775 pms_synaptics_passthrough(psc);
1774 } else { 1776 } else {