Received: by 10.192.165.148 with SMTP id m20csp213259imm; Thu, 3 May 2018 18:26:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpB9eWRfWUhPnNv6GlebebLKhlo9z05jvaIL2k+WtBKT4JaO0fU4cFtB+igGt60oO0knsBW X-Received: by 10.98.156.147 with SMTP id u19mr24238730pfk.74.1525397184206; Thu, 03 May 2018 18:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525397184; cv=none; d=google.com; s=arc-20160816; b=Kr26vSDOO3e/jjbzyikDGamZjPMNeFpdJwmKOHEos2sqW3BKSs/5Ivtjhdg7P7kO+g KwrArVlaasMJFlLLVenmTO7jtsN2xIAAm4VgXIcpU/mwsZwqaJVdb4KLDw0n5tXeE+4A MRBVJU08uRwPpD1VybPn7JJWRa5d5Y6p/SOjYjiXgFF2PKaGloqrGZo3KNbhjpRWVRta D5iDkxrXdo4qSU2FfwFxnec3tdrY8D1wBY1JgT1jzmA5k6m4fWYX/iNIyAWsi9DaTwQY NcULks/ZpGEvMKBGUwESNllo++OgtDbqBu7UaAKDXsgNjHSOtnSg4z/eB6qOnu6Q3Tdh R5kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=S0iJGDvmIG5DKhYEeA4VXS0xb3kgpHs042UOGEPEzAE=; b=aAfJdRxe76zNXJVV00xtf+Ijtek9TWc80sDkCdXJPup2kbMxALoPRiArkt3kP72kJJ wL7D/0IahwWfwjUKX66SfSRDe43KiARBEuYDQI79EBWpFIHEU2p9cmX4ngjUORwuOdc6 c1mLaa1+6wP89+F1pvVZYSQ5Cn4BDSKTBnrgAlWyHqodNTY6dsMRfrbys4RkIlTyC0lY sZnqhLrNFhjoPI+uOewhD6MRBwyopUIUjVaXVS66hDTjJhlXeko1GSg4PFMTGHdyeTbx dkPCewJptAhAVnofS01tPShKFp0dCMzDNS8gjrHhvUSKItPaz837v8rPEollkA0moBSx rJSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kegHWC3g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s66si15209331pfj.164.2018.05.03.18.26.10; Thu, 03 May 2018 18:26:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kegHWC3g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751551AbeEDBZA (ORCPT + 99 others); Thu, 3 May 2018 21:25:00 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:43063 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751236AbeEDBY6 (ORCPT ); Thu, 3 May 2018 21:24:58 -0400 Received: by mail-lf0-f67.google.com with SMTP id g12-v6so28642224lfb.10 for ; Thu, 03 May 2018 18:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S0iJGDvmIG5DKhYEeA4VXS0xb3kgpHs042UOGEPEzAE=; b=kegHWC3gy3l3yCWh8SB+g5/QQ4pJZnDFxNyWsRB6C6o9mWZMfyqjhemxTl/aHRSpQI 2hYNtEUisvKMiweskZCMQ2UmEF1xkd9Kw2ehoRbu+vuXANvePZA9TTBptr6B/HyOF4nG O3/02i033j0CV7U8PHv82H6FRe5wle0VOPU1rgYFP/0b0KtQo9DXefV14ZESL9Oc98BI Ix9RhPGYleIVrC8dIfe15etiUmh8cgOVQtDWTghYt/I90tIDTkaERB/K+U5LmzkP5dEy UPel3uEN48imAEqH3oHTHCIQ+VYZORKJO+pruwTAXtvhvpqtcqV53JmJrB+D33YINiuo WsVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S0iJGDvmIG5DKhYEeA4VXS0xb3kgpHs042UOGEPEzAE=; b=OCM9z3fqCLKil9O9pmyFnec6rgcz0RA0fi5yNyzttzmKYVFCRAS2jRMEkKGFB9jf9g jTHNAa9BgNyz7ipXtUvscYlMm60nTUjftjbJA8Z6KDaYPF0zHRAwLQii3Y9DWI0ZpAE3 RZMyi/YPJLjZHaB9CPndOgcDlh0E4eblDttp0A4992UPoIhgfKgnA5vq83wIbIalkJF+ 5dhY5AyajU4Pu+LgiRNm1JqZoDEQISs8Qy6t7J8i9htWNghV6sopcu5LCXu37bhkRzH3 MqQcZEukG8ZBvnZRoUsPF7WzzzNSHDBjjzlBB0B+K+o5co8Dv5JMfp0dj/ru+VKtQAl5 kFRQ== X-Gm-Message-State: ALQs6tBb8izA5Z7wZqwZwAJo8yQaxYbDwSdi5i4/xhVl+dmNH++ET5fj BwHgOT97wOs6wwBWtfMeVgI= X-Received: by 2002:a2e:9c08:: with SMTP id s8-v6mr17291292lji.97.1525397097029; Thu, 03 May 2018 18:24:57 -0700 (PDT) Received: from localhost ([62.216.57.27]) by smtp.gmail.com with ESMTPSA id n5-v6sm3026416ljh.84.2018.05.03.18.24.56 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 03 May 2018 18:24:56 -0700 (PDT) From: Ruslan Bilovol To: Takashi Iwai Cc: Jorge , Andrew Chant , Greg Kroah-Hartman , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] ALSA: usb: Only get AudioControl header for UAC1 class. Date: Fri, 4 May 2018 04:24:01 +0300 Message-Id: <1525397044-15080-5-git-send-email-ruslan.bilovol@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525397044-15080-1-git-send-email-ruslan.bilovol@gmail.com> References: <1525397044-15080-1-git-send-email-ruslan.bilovol@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jorge Sanjuan 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 [Ruslan: updated with recently added sanity checks] Signed-off-by: Ruslan Bilovol --- 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 36c289b..0d7a5d7 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