Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb usbdi(9): Restore usb_descriptor_t to its correc...



details:   https://anonhg.NetBSD.org/src/rev/3be10ff3618a
branches:  trunk
changeset: 365280:3be10ff3618a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Apr 17 13:15:37 2022 +0000

description:
usbdi(9): Restore usb_descriptor_t to its correct definition.

Descriptors in the USB spec all start with bLength and
bDescriptorType.  bDescriptorSubtype is only for certain
class-specific descriptors.  Many descriptors, such as
usb_device_descriptor_t, _do not_ have bDescriptorSubtype, so using a
structure that has bDescriptorSubtype for such descrpitors is wrong.

There is some history here:

- Back in 1998, when augustss@ introduced the USB stack, the type
  usb_descriptor_t was erroneously defined with a bDescriptorSubtype
  member.

- In 2007, drochner@ removed this member to accurately reflect the
  USB spec.

- In 2018, khorben@ appeared to have accidentally reintroduced it
  while importing the umb(4) driver from OpenBSD, which still has the
  erroneous bDescriptorSubtype member in usb_descriptor_t.

The umb(4) driver has since been adjusted to correctly use
usb_cdc_descriptor_t instead of usb_descriptor_t (and I have now
restored umidi_cs_descriptor_t which I had removed last month before
I realized this history of usb_descriptor_t), so this member is no
longer necessary.

diffstat:

 sys/dev/usb/usb.h |  12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diffs (30 lines):

diff -r 3c562f3e45a1 -r 3be10ff3618a sys/dev/usb/usb.h
--- a/sys/dev/usb/usb.h Sun Apr 17 13:15:27 2022 +0000
+++ b/sys/dev/usb/usb.h Sun Apr 17 13:15:37 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usb.h,v 1.119 2021/10/11 00:25:05 jmcneill Exp $       */
+/*     $NetBSD: usb.h,v 1.120 2022/04/17 13:15:37 riastradh Exp $      */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -202,12 +202,18 @@
 
 #define USB_3_MAX_CTRL_PACKET  512
 
+/*
+ * This is the common header to all USB descriptors defined in the USB
+ * specification.
+ *
+ * DO NOT CHANGE THIS TYPE!
+ */
 typedef struct {
        uByte           bLength;
        uByte           bDescriptorType;
-       uByte           bDescriptorSubtype;
 } UPACKED usb_descriptor_t;
-#define USB_DESCRIPTOR_SIZE 3
+#define USB_DESCRIPTOR_SIZE 2
+__CTASSERT(sizeof(usb_descriptor_t) == USB_DESCRIPTOR_SIZE);
 
 typedef struct {
        uByte           bLength;



Home | Main Index | Thread Index | Old Index