From patchwork Fri May 4 01:24:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Bilovol X-Patchwork-Id: 10379613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3410A60159 for ; Fri, 4 May 2018 01:32:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23A41292E6 for ; Fri, 4 May 2018 01:32:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17284292E7; Fri, 4 May 2018 01:32:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64C5D292EB for ; Fri, 4 May 2018 01:32:34 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E1F59267641; Fri, 4 May 2018 03:25:13 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id BCDE72675FA; Fri, 4 May 2018 03:25:01 +0200 (CEST) Received: from mail-lf0-f66.google.com (mail-lf0-f66.google.com [209.85.215.66]) by alsa0.perex.cz (Postfix) with ESMTP id B782F2675D4 for ; Fri, 4 May 2018 03:24:57 +0200 (CEST) Received: by mail-lf0-f66.google.com with SMTP id m18-v6so28661551lfb.0 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=UHqxtz4ZIyrFMLRhtk3i3B4KGmGX6C6IQMfF/3IA5obcUe6Hgdc1EIBZNA0fPj+nt0 ruF6qjtHfn3ZckUYJazgJcVnWjJRQwvgiMlgUEQO1htkwTtFQ4Y+K/BGDiO1+PvHjW/Y IVQj5ks0ezftab5vGdf0JKMc53RII/ONtqkxyMktMLgbud2IAjcHRqq32WH4L65CrZiV ew8Ajrqia/1t+Wb1tHbkbx6szswFUovUpFBX2019E840fB4UczK/P3ebfdYT8zxv4Yp4 JycwbyGRu9roBUK6jLnExfspj6s6cVCl17VWeTTQ6s8JjeRhJ/p3uTCdeZfT/i1BEYr6 FvRQ== X-Gm-Message-State: ALQs6tA6CrE4nJtH9ccCeBaBhNP0z9Px7FV/pdKYnub523nwI7yA6QNz 3GLzvuNTlAXTcuyS6MWJb+8= X-Google-Smtp-Source: AB8JxZqHRqLzPRa9+YDuHSazWMtbdEsSr0Ki8Mwz/GvANm/cA8s0LGTyEFHL8LFwOZJvYjqEIfEJdw== 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 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> Cc: Jorge , alsa-devel@alsa-project.org, Andrew Chant , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [alsa-devel] [PATCH v2 4/7] ALSA: usb: Only get AudioControl header for UAC1 class. X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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");