All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ruslan Bilovol <ruslan.bilovol@gmail.com>
To: Takashi Iwai <tiwai@suse.com>
Cc: Jorge <jorge.sanjuan@codethink.co.uk>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] ALSA: usb: Only get AudioControl header for UAC1 class.
Date: Sat, 14 Apr 2018 01:24:25 +0300	[thread overview]
Message-ID: <1523658266-2259-4-git-send-email-ruslan.bilovol@gmail.com> (raw)
In-Reply-To: <1523658266-2259-1-git-send-email-ruslan.bilovol@gmail.com>

From: Jorge Sanjuan <jorge.sanjuan@codethink.co.uk>

The control header needs to be read from buffer at this point only
in the case of UAC1 protocol. Move it inside the switch case as other
protocols such as the Basic Audio Device spec will have an empty buffer
that is latter filled as inferred.

Signed-off-by: Jorge Sanjuan <jorge.sanjuan@codethink.co.uk>
[Ruslan: updated with recently added sanity checks]
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
---
 sound/usb/card.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/sound/usb/card.c b/sound/usb/card.c
index 4a1c6bb..4d866bd 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -221,32 +221,13 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
 	struct usb_device *dev = chip->dev;
 	struct usb_host_interface *host_iface;
 	struct usb_interface_descriptor *altsd;
-	void *control_header;
 	int i, protocol;
-	int rest_bytes;
 
 	/* find audiocontrol interface */
 	host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0];
-	control_header = snd_usb_find_csint_desc(host_iface->extra,
-						 host_iface->extralen,
-						 NULL, UAC_HEADER);
 	altsd = get_iface_desc(host_iface);
 	protocol = altsd->bInterfaceProtocol;
 
-	if (!control_header) {
-		dev_err(&dev->dev, "cannot find UAC_HEADER\n");
-		return -EINVAL;
-	}
-
-	rest_bytes = (void *)(host_iface->extra + host_iface->extralen) -
-		control_header;
-
-	/* just to be sure -- this shouldn't hit at all */
-	if (rest_bytes <= 0) {
-		dev_err(&dev->dev, "invalid control header\n");
-		return -EINVAL;
-	}
-
 	switch (protocol) {
 	default:
 		dev_warn(&dev->dev,
@@ -255,7 +236,25 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
 		/* fall through */
 
 	case UAC_VERSION_1: {
-		struct uac1_ac_header_descriptor *h1 = control_header;
+		struct uac1_ac_header_descriptor *h1;
+		int rest_bytes;
+
+		h1 = snd_usb_find_csint_desc(host_iface->extra,
+							 host_iface->extralen,
+							 NULL, UAC_HEADER);
+		if (!h1) {
+			dev_err(&dev->dev, "cannot find UAC_HEADER\n");
+			return -EINVAL;
+		}
+
+		rest_bytes = (void *)(host_iface->extra +
+				host_iface->extralen) - (void *)h1;
+
+		/* just to be sure -- this shouldn't hit at all */
+		if (rest_bytes <= 0) {
+			dev_err(&dev->dev, "invalid control header\n");
+			return -EINVAL;
+		}
 
 		if (rest_bytes < sizeof(*h1)) {
 			dev_err(&dev->dev, "too short v1 buffer descriptor\n");
-- 
1.9.1

  parent reply	other threads:[~2018-04-13 22:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-13 22:24 [PATCH 0/4] USB Audio Device Class 3.0 BADD profiles support Ruslan Bilovol
2018-04-13 22:24 ` [PATCH 1/4] ALSA: usb: stream: refactor audio interface parsing Ruslan Bilovol
2018-04-19  9:55   ` [alsa-devel] " Takashi Iwai
2018-04-19  9:55     ` Takashi Iwai
2018-04-23 19:48     ` Ruslan Bilovol
2018-04-23 19:48       ` Ruslan Bilovol
2018-04-13 22:24 ` [PATCH 2/4] include: usb: audio-v3: add BADD-specific values Ruslan Bilovol
2018-04-13 22:24   ` Ruslan Bilovol
2018-04-13 22:24 ` Ruslan Bilovol [this message]
2018-04-13 22:24 ` [PATCH 4/4] ALSA: usb: add UAC3 BADD profiles support Ruslan Bilovol
2018-04-14 17:55   ` Jorge Sanjuan
2018-04-14 17:55     ` Jorge Sanjuan
2018-04-18  0:41     ` Ruslan Bilovol
2018-04-16  9:05   ` kbuild test robot, Dan Carpenter
2018-04-16  9:05     ` kbuild test robot, Dan Carpenter
2018-04-19  9:42   ` [alsa-devel] " Andrew Chant
2018-04-23 19:47     ` Ruslan Bilovol
2018-04-23 19:47       ` Ruslan Bilovol
2018-04-19 10:19   ` [alsa-devel] " Takashi Iwai
2018-04-24  7:51     ` Ruslan Bilovol
2018-04-24  7:51       ` Ruslan Bilovol

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1523658266-2259-4-git-send-email-ruslan.bilovol@gmail.com \
    --to=ruslan.bilovol@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jorge.sanjuan@codethink.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.