Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb uhidev(9): Define UHIDEV_MAXREPID = 255.
details: https://anonhg.NetBSD.org/src/rev/4d6e10926d8e
branches: trunk
changeset: 364546:4d6e10926d8e
user: riastradh <riastradh%NetBSD.org@localhost>
date: Mon Mar 28 12:44:37 2022 +0000
description:
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:
sys/dev/usb/uhidev.c | 21 +++++++++------------
sys/dev/usb/uhidev.h | 3 ++-
2 files changed, 11 insertions(+), 13 deletions(-)
diffs (74 lines):
diff -r 4b1276e18317 -r 4d6e10926d8e sys/dev/usb/uhidev.c
--- a/sys/dev/usb/uhidev.c Mon Mar 28 12:44:28 2022 +0000
+++ b/sys/dev/usb/uhidev.c Mon Mar 28 12:44:37 2022 +0000
@@ -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 @@
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 @@
/*
* 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 @@
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 -r 4b1276e18317 -r 4d6e10926d8e sys/dev/usb/uhidev.h
--- a/sys/dev/usb/uhidev.h Mon Mar 28 12:44:28 2022 +0000
+++ b/sys/dev/usb/uhidev.h Mon Mar 28 12:44:37 2022 +0000
@@ -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_callback, void *);
#define UHIDEV_OSIZE 64
+#define UHIDEV_MAXREPID 255
#endif /* _DEV_USB_UHIDEV_H_ */
Home |
Main Index |
Thread Index |
Old Index