summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2022-03-28 12:44:37 +0000
committerriastradh <riastradh@NetBSD.org>2022-03-28 12:44:37 +0000
commit7cb4ce17b5739c6b915fa5c08df2ead8517c07b6 (patch)
treeadb8fa4a1b414ec030352760049c617f601893e3 /sys/dev
parent54bcf62bfb659bad32d70b893822d6fc644fd4a2 (diff)
uhidev(9): Define UHIDEV_MAXREPID = 255.
Report ids are limited by the HID spec to a single byte. - Clamp max report id in report descriptor to this. - Prune dead refcnt-overflow error branches. Assert instead.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/usb/uhidev.c21
-rw-r--r--sys/dev/usb/uhidev.h3
2 files changed, 11 insertions, 13 deletions
diff --git a/sys/dev/usb/uhidev.c b/sys/dev/usb/uhidev.c
index 38fb3776f23..b4c7e5da8a0 100644
--- a/sys/dev/usb/uhidev.c
+++ b/sys/dev/usb/uhidev.c
@@ -1,4 +1,4 @@
-/* $NetBSD: uhidev.c,v 1.91 2022/03/28 12:44:28 riastradh Exp $ */
+/* $NetBSD: uhidev.c,v 1.92 2022/03/28 12:44:37 riastradh Exp $ */
/*
* Copyright (c) 2001, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.91 2022/03/28 12:44:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.92 2022/03/28 12:44:37 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -458,7 +458,7 @@ uhidev_maxrepid(void *buf, int len)
if ((int)h.report_ID > maxid)
maxid = h.report_ID;
hid_end_parse(d);
- return maxid;
+ return MIN(maxid, UHIDEV_MAXREPID);
}
static int
@@ -671,11 +671,11 @@ uhidev_open_pipes(struct uhidev_softc *sc)
/*
* If the pipes are already open, just increment the reference
- * count, or fail if it would overflow.
+ * count. The reference count is limited by the number of
+ * report ids, so this can't overflow.
*/
if (sc->sc_refcnt) {
- if (sc->sc_refcnt == INT_MAX)
- return EBUSY;
+ KASSERT(sc->sc_refcnt < UHIDEV_MAXREPID);
sc->sc_refcnt++;
return 0;
}
@@ -700,12 +700,9 @@ uhidev_open_pipes(struct uhidev_softc *sc)
if (error)
goto out;
if (sc->sc_refcnt) {
- if (sc->sc_refcnt == INT_MAX) {
- error = EBUSY;
- } else {
- sc->sc_refcnt++;
- error = 0;
- }
+ KASSERT(sc->sc_refcnt < UHIDEV_MAXREPID);
+ sc->sc_refcnt++;
+ error = 0;
goto out0;
}
mutex_exit(&sc->sc_lock);
diff --git a/sys/dev/usb/uhidev.h b/sys/dev/usb/uhidev.h
index fcf97c0fd39..8ea62eefbb2 100644
--- a/sys/dev/usb/uhidev.h
+++ b/sys/dev/usb/uhidev.h
@@ -1,4 +1,4 @@
-/* $NetBSD: uhidev.h,v 1.26 2022/03/28 12:44:17 riastradh Exp $ */
+/* $NetBSD: uhidev.h,v 1.27 2022/03/28 12:44:37 riastradh Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -54,5 +54,6 @@ usbd_status uhidev_write_async(struct uhidev *, void *, int, int, int,
usbd_callback, void *);
#define UHIDEV_OSIZE 64
+#define UHIDEV_MAXREPID 255
#endif /* _DEV_USB_UHIDEV_H_ */