Module Name: src
Committed By: riastradh
Date: Mon Mar 28 12:44:37 UTC 2022
Modified Files:
src/sys/dev/usb: uhidev.c uhidev.h
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/dev/usb/uhidev.c
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/usb/uhidev.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/usb/uhidev.c
diff -u src/sys/dev/usb/uhidev.c:1.91 src/sys/dev/usb/uhidev.c:1.92
--- src/sys/dev/usb/uhidev.c:1.91 Mon Mar 28 12:44:28 2022
+++ src/sys/dev/usb/uhidev.c Mon Mar 28 12:44:37 2022
@@ -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 *s
/*
* 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 *s
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);
Index: src/sys/dev/usb/uhidev.h
diff -u src/sys/dev/usb/uhidev.h:1.26 src/sys/dev/usb/uhidev.h:1.27
--- src/sys/dev/usb/uhidev.h:1.26 Mon Mar 28 12:44:17 2022
+++ src/sys/dev/usb/uhidev.h Mon Mar 28 12:44:37 2022
@@ -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 uh
usbd_callback, void *);
#define UHIDEV_OSIZE 64
+#define UHIDEV_MAXREPID 255
#endif /* _DEV_USB_UHIDEV_H_ */