Received: by 10.192.165.156 with SMTP id m28csp1203500imm; Fri, 13 Apr 2018 15:26:25 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+vRp+vOugllA7EBNMXRXwVtbP1OEUDjJ+83sNm8hN6uZdhf8xZ/iOQVZvAvke+3SJVUABS X-Received: by 10.99.52.70 with SMTP id b67mr5361435pga.258.1523658385033; Fri, 13 Apr 2018 15:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523658384; cv=none; d=google.com; s=arc-20160816; b=bpcTKnmqTTCOKMxb/IJbPHn34pOKaO4HwbLNKnevpJMnniQZghHsxRb6DIJGFB1WeG 7155o94efJ86DG0RaJcz6Pkh3uNwGpU7Hpnlw3mndtdg9CY6Kkkk6EZj6T4YuRPiBf2d DOrfNzkQmd55dHjOOqrdr3rNglziS84FqTUqB63bU0ddZg5dregpd72z21Hkchrpagg6 hpkIsJI7kjFJZp/ORv6zdhUQJ8U5ut2XiTC60yGBfzW4Vy4xbzBVP0OM6qZgjdghM6LR jxwPwShPIvz/n4IUkt3sGY0afl+5paAJFL/SdIiFcQCQ4VpSZnExL1yfRk2fTeoECxia Vm4g== 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=7NoS2qPIT10HjdIf1i9AOYCOZQJ/0RemsaOpsXR8Swk=; b=SR1D+sipbyKhaa2rHC6ad4kNAU/WTuDVChvt9QGIGEGeQKFWyDbPKBhFmvWRlmCIj5 e0FUj6CPQF4zXb5gdROHsH7PEkqQrgsb7XE0e4h/c3bPeUZt8NsYaTuumt7hNGhy4tuR Or+SFwPc+SRDiTWh/Gw9T+cEquwOxcf7zk1tlU4yAq1zLiuM/xsRultSa249RKsXXlGT R6K7jiXqg/fvT2tZRgQHQ2XBrf03xOLERrQU4ARJKo5t/ZZTaa18LWR19NYfzqPBNYba h/pWn7fgdbDJNJ9NhlbIe0AvxdqQCf0WIjc60UrthKxGqQQmC55O826ometNzKjerNKI Sz0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=M7vryjld; 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 i21si5498470pfk.34.2018.04.13.15.26.08; Fri, 13 Apr 2018 15: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=M7vryjld; 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 S1752813AbeDMWYu (ORCPT + 99 others); Fri, 13 Apr 2018 18:24:50 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:40025 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752652AbeDMWYq (ORCPT ); Fri, 13 Apr 2018 18:24:46 -0400 Received: by mail-lf0-f66.google.com with SMTP id e5-v6so14588219lfb.7 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=eQ2O8nH1wiNIqijQcG+QScnker1zpM3lyR+CM1Crmg4AP5zjYkoRIy6CtpHNP4atFN MHbWZ8w1J58gW6EWLlE2ZSl7rupMUACRL6jxcIAFCGQbH3z7FBptabtKARYLqQ2ENjQq 9+Zd8eazxVa9+DxSQyQJtH7GrLyaw5CVTV1ozkbjSo64dVk/ju1o7Ci9EKgie9Zq8TEc QNembuMV+iQtn30/2o8ydlW2/QrpIfQh4CTZo991mF7ti1e2Cf4mBA34osb+rAUxOydr 5qvcSawDXFXchvjT7VaG6g/Ve+psYYhAkgf4WMNrYFEWNnjygUOhlr9n7hxeQr6DqMNC sRHg== X-Gm-Message-State: ALQs6tBdEdhwuT+RQ/1CbRHz/QQbiwnqb8cVBJBLX0t0E9amyGpzyBZj jlOs69dkXWvU9mQI2Zx7EDk= 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 Cc: Jorge , Greg Kroah-Hartman , 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 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> 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 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