From patchwork Fri Apr 13 22:24:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Bilovol X-Patchwork-Id: 10340853 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 BFC2160329 for ; Fri, 13 Apr 2018 22:25:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE284287C1 for ; Fri, 13 Apr 2018 22:25:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2FE028A22; Fri, 13 Apr 2018 22:25:18 +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 0A383287C1 for ; Fri, 13 Apr 2018 22:25:17 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B26F42673D3; Sat, 14 Apr 2018 00:24:54 +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 E970126732C; Sat, 14 Apr 2018 00:24:47 +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 AFF1B267079 for ; Sat, 14 Apr 2018 00:24:45 +0200 (CEST) Received: by mail-lf0-f66.google.com with SMTP id u3-v6so14609733lff.5 for ; Fri, 13 Apr 2018 15:24:45 -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=7NoS2qPIT10HjdIf1i9AOYCOZQJ/0RemsaOpsXR8Swk=; b=M7vryjldQYrOVzejufJ95SFkUep4lWVGXxUrijsPpatLvgnjHEM8eih7J1BEb5ekPg b81QR/eWhNYjWk0IGDZ0S3QulS280rn/uIVV89tH0xB2+Q/ZBqfRCnvtQ8OKBOZCuUWW Lyly/L1GcNdU1EoegyU2tETiYaecLKx5cbuZ8XdF19tbyhxjMsl8KNH/AXjNqGvXRRi/ W9mU+wGXD1ONPCs61QCXufGZ1JJ7NE14+GJqijfWlBd2w2R2+1YiRCmw39s102qlqZRD huC/iD12HlLqgurBHMXZP8XaWGu4CpTmjcHid2oJrUmwOFQ9Sjfz75W6K4qMd3F5wZ8g q6Iw== 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=7NoS2qPIT10HjdIf1i9AOYCOZQJ/0RemsaOpsXR8Swk=; b=AQ0+MTUGxCeFaF+OCEhpPbGJGIsWa1uNGS8F3LrUr55NDYppTFIRn8+ZpGang1VrTj Hfb/eexaPOcOABBMlQoRePstzH0MjhTnfSIBagHA5fZSIYKmDUSJQzYjkLG9hy1CyR6r oVwyv28FJcbaFDbm+666m35FecHDMtNTCjI4rqwdrrmvQKEYjS3BXG//f2OVRH9AUgUN H0WZLpykTzRHFEPlhZPTqreGPpWyNdKM0zRGAq18VcPfS1jXHn9ropwZKP3rMG4OYsTP vw7oJzuNPBxg+loGpX5+7JMgiTSAxBBl5RlgW0rmYFMIxiZcZcl4n5xP3D2WTxDgAqCw 4Q/A== X-Gm-Message-State: ALQs6tC1br78j3Htr2n454nZZG59YsyR1n1ZM8sseHU7xPCCf7ZtKenA t0kbuxP9deIOe9nVx9jh3lY= X-Google-Smtp-Source: AIpwx4+wcVB35nXy2CAejAvDV49Lh5A6OqAVJuOvOk83uA3G0XMhvr9Lmzpy5BJDtGpHTHf47bCcbg== X-Received: by 10.46.5.200 with SMTP id 191mr4617253ljf.8.1523658284838; Fri, 13 Apr 2018 15:24:44 -0700 (PDT) Received: from localhost ([62.216.62.149]) by smtp.gmail.com with ESMTPSA id g22sm1135604lje.36.2018.04.13.15.24.43 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 13 Apr 2018 15:24:44 -0700 (PDT) From: Ruslan Bilovol To: Takashi Iwai Date: Sat, 14 Apr 2018 01:24:25 +0300 Message-Id: <1523658266-2259-4-git-send-email-ruslan.bilovol@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523658266-2259-1-git-send-email-ruslan.bilovol@gmail.com> References: <1523658266-2259-1-git-send-email-ruslan.bilovol@gmail.com> Cc: Jorge , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [alsa-devel] [PATCH 3/4] 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 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");