Module Name:    src
Committed By:   riastradh
Date:           Sun Apr 17 13:15:15 UTC 2022

Modified Files:
        src/sys/dev/usb: umidi.c

Log Message:
umidi(4): Restore umidi_cs_descriptor_t type.

Had been previously deleted under the misapprehension that
usb_descriptor_t is appropriate here, but it's not -- it should not
have the bDescriptorSubtype member.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/usb/umidi.c

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/umidi.c
diff -u src/sys/dev/usb/umidi.c:1.86 src/sys/dev/usb/umidi.c:1.87
--- src/sys/dev/usb/umidi.c:1.86	Sat Mar 19 20:44:07 2022
+++ src/sys/dev/usb/umidi.c	Sun Apr 17 13:15:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: umidi.c,v 1.86 2022/03/19 20:44:07 riastradh Exp $	*/
+/*	$NetBSD: umidi.c,v 1.87 2022/04/17 13:15:15 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2012, 2014 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.86 2022/03/19 20:44:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.87 2022/04/17 13:15:15 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -70,6 +70,13 @@ __KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.
 #define UMIDI_EMBEDDED	0x01
 #define UMIDI_EXTERNAL	0x02
 
+/* generic, for iteration */
+typedef struct {
+	uByte		bLength;
+	uByte		bDescriptorType;
+	uByte		bDescriptorSubtype;
+} UPACKED umidi_cs_descriptor_t;
+
 typedef struct {
 	uByte		bLength;
 	uByte		bDescriptorType;
@@ -866,6 +873,7 @@ alloc_all_endpoints_yamaha(struct umidi_
 	char *end;
 	usb_config_descriptor_t *cdesc;
 	usb_descriptor_t *desc;
+	umidi_cs_descriptor_t *csdesc;
 	usb_interface_descriptor_t *idesc;
 	umidi_cs_interface_descriptor_t *udesc;
 	usb_endpoint_descriptor_t *epd;
@@ -902,12 +910,13 @@ alloc_all_endpoints_yamaha(struct umidi_
 		return USBD_INVAL;
 
 	/* count jacks */
-	if (!(desc->bDescriptorType == UDESC_CS_INTERFACE &&
-	      desc->bDescriptorSubtype == UMIDI_MS_HEADER))
+	if (desc->bDescriptorType != UDESC_CS_INTERFACE ||
+	    desc->bLength < sizeof(*csdesc))
 		return USBD_INVAL;
-	if (desc->bLength < sizeof(*udesc))
+	csdesc = (umidi_cs_descriptor_t *)desc;
+	if (csdesc->bDescriptorSubtype != UMIDI_MS_HEADER)
 		return USBD_INVAL;
-	udesc = TO_CSIFD(desc);
+	udesc = TO_CSIFD(csdesc);
 	if (UGETW(udesc->wTotalLength) > end - (char *)udesc)
 		return USBD_INVAL;
 	if (UGETW(udesc->wTotalLength) < udesc->bLength)
@@ -919,13 +928,15 @@ alloc_all_endpoints_yamaha(struct umidi_
 		if (desc->bLength < sizeof(*desc) ||
 		    desc->bLength > end - (char *)desc)
 			break;
-		if (desc->bDescriptorType == UDESC_CS_INTERFACE &&
-		    desc->bLength >= UMIDI_JACK_DESCRIPTOR_SIZE) {
-			if (desc->bDescriptorSubtype == UMIDI_OUT_JACK)
-				sc->sc_out_num_jacks++;
-			else if (desc->bDescriptorSubtype == UMIDI_IN_JACK)
-				sc->sc_in_num_jacks++;
-		}
+		if (desc->bDescriptorType != UDESC_CS_INTERFACE ||
+		    desc->bLength < sizeof(*csdesc) ||
+		    desc->bLength < UMIDI_JACK_DESCRIPTOR_SIZE)
+			continue;
+		csdesc = (umidi_cs_descriptor_t *)desc;
+		if (csdesc->bDescriptorSubtype == UMIDI_OUT_JACK)
+			sc->sc_out_num_jacks++;
+		else if (csdesc->bDescriptorSubtype == UMIDI_IN_JACK)
+			sc->sc_in_num_jacks++;
 	}
 
 	/* validate some parameters */

Reply via email to