diff mbox

[3/4] ALSA: usb-audio: Use Class Specific EP for UAC3 devices.

Message ID 20180420170327.31569-4-jorge.sanjuan@codethink.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Jorge Sanjuan April 20, 2018, 5:03 p.m. UTC
bmAtributes offset doesn't exist in the UAC3 CS_EP descriptor.
Hence, checking for pitch control as if it was UAC2 doesn't make
any sense. Use the defined UAC3 offsets instead.

Signed-off-by: Jorge Sanjuan <jorge.sanjuan@codethink.co.uk>
---
 sound/usb/stream.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

Comments

kernel test robot April 22, 2018, 8:30 p.m. UTC | #1
Hi Jorge,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on sound/for-next]
[also build test WARNING on v4.17-rc1 next-20180420]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jorge-Sanjuan/ALSA-usb-UAC3-new-features/20180423-015726
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> sound/usb/stream.c:597:26: sparse: restricted __le32 degrades to integer

vim +597 sound/usb/stream.c

   544	
   545	static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
   546						 struct usb_host_interface *alts,
   547						 int protocol, int iface_no)
   548	{
   549		/* parsed with a v1 header here. that's ok as we only look at the
   550		 * header first which is the same for both versions */
   551		struct uac_iso_endpoint_descriptor *csep;
   552		struct usb_interface_descriptor *altsd = get_iface_desc(alts);
   553		int attributes = 0;
   554	
   555		csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT);
   556	
   557		/* Creamware Noah has this descriptor after the 2nd endpoint */
   558		if (!csep && altsd->bNumEndpoints >= 2)
   559			csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT);
   560	
   561		/*
   562		 * If we can't locate the USB_DT_CS_ENDPOINT descriptor in the extra
   563		 * bytes after the first endpoint, go search the entire interface.
   564		 * Some devices have it directly *before* the standard endpoint.
   565		 */
   566		if (!csep)
   567			csep = snd_usb_find_desc(alts->extra, alts->extralen, NULL, USB_DT_CS_ENDPOINT);
   568	
   569		if (!csep || csep->bLength < 7 ||
   570		    csep->bDescriptorSubtype != UAC_EP_GENERAL) {
   571			usb_audio_warn(chip,
   572				       "%u:%d : no or invalid class specific endpoint descriptor\n",
   573				       iface_no, altsd->bAlternateSetting);
   574			return 0;
   575		}
   576	
   577		switch (protocol) {
   578		case UAC_VERSION_1:
   579			attributes = csep->bmAttributes;
   580			break;
   581		case UAC_VERSION_2: {
   582			struct uac2_iso_endpoint_descriptor *csep2 =
   583				(struct uac2_iso_endpoint_descriptor *) csep;
   584	
   585			attributes = csep->bmAttributes & UAC_EP_CS_ATTR_FILL_MAX;
   586	
   587			/* emulate the endpoint attributes of a v1 device */
   588			if (csep2->bmControls & UAC2_CONTROL_PITCH)
   589				attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
   590			break;
   591		}
   592		case UAC_VERSION_3: {
   593			struct uac3_iso_endpoint_descriptor *csep3 =
   594				(struct uac3_iso_endpoint_descriptor *) csep;
   595	
   596			/* emulate the endpoint attributes of a v1 device */
 > 597			if (csep3->bmControls & UAC2_CONTROL_PITCH)
   598				attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
   599			break;
   600		}
   601		}
   602	
   603		return attributes;
   604	}
   605	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/sound/usb/stream.c b/sound/usb/stream.c
index 956be9f7c72a..344e0ecf6d59 100644
--- a/sound/usb/stream.c
+++ b/sound/usb/stream.c
@@ -574,9 +574,11 @@  static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
 		return 0;
 	}
 
-	if (protocol == UAC_VERSION_1) {
+	switch (protocol) {
+	case UAC_VERSION_1:
 		attributes = csep->bmAttributes;
-	} else {
+		break;
+	case UAC_VERSION_2: {
 		struct uac2_iso_endpoint_descriptor *csep2 =
 			(struct uac2_iso_endpoint_descriptor *) csep;
 
@@ -585,6 +587,17 @@  static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
 		/* emulate the endpoint attributes of a v1 device */
 		if (csep2->bmControls & UAC2_CONTROL_PITCH)
 			attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
+		break;
+	}
+	case UAC_VERSION_3: {
+		struct uac3_iso_endpoint_descriptor *csep3 =
+			(struct uac3_iso_endpoint_descriptor *) csep;
+
+		/* emulate the endpoint attributes of a v1 device */
+		if (csep3->bmControls & UAC2_CONTROL_PITCH)
+			attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
+		break;
+	}
 	}
 
 	return attributes;