Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp701996ybz; Fri, 1 May 2020 07:04:39 -0700 (PDT) X-Google-Smtp-Source: APiQypIjBT+pkt6llDHCLYfo4tXB7dQzx88d37/SlYEqVnv32wuKyal2ACBh6pAh61SxubFB4eX1 X-Received: by 2002:aa7:c98a:: with SMTP id c10mr3716992edt.94.1588341879838; Fri, 01 May 2020 07:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588341879; cv=none; d=google.com; s=arc-20160816; b=KkGKeV1dLQxzZ0IRIuyFYiJvqt4WbafAEVEy+SLRsiKxENb0d6FxmrVUBc3+vZOUBG XwNjxbqB7hMtCOXlxczgFqbBlLNFaBvpV1VktD6AXvQ4fW/j8jHfrsRyYAim9gEmqwSH 81NhvnypUu01SvFzODMui7UdURfHcXEJgd6uKZyemGxnylFHkttkYYrRHxQJgrR0XcBy eB1lZlVOTCvkayfV4esD73D1Syh5UAx6B47R4iD5IsTg9oB2seqR/DBwq/u2EPIEuavd X92rzHKHZitxrbDdCaer+X1FA0xamAudXFFBUxiaWOpP8YShtgAObH00g87jX3qBLfEy du7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2zxufR/67GASeImM6iqmP9dSDMqvII7r2FrbcMn6iaM=; b=Oyi0ebe0obhAH38dat58oHwTTXznNgFy8PSc8szZXS4Fmj7A90+4YHxEKXRoiA7+Nd W04BSw3KD2B14t7/UAKo9QRVoIAVe/skEnwwHJwRQ0X8yVfAA46KGtbgL6IfsMZwpoLV aLBDxT+yTAy3jmuI7uSxl1DeKdRZn2P3HLj7IyYOdKZTkP/aU9lUK8jzMbvKx5WLPpr2 LzOXmGP9iEFrQJau+FwZBQDAQNVrgSgcC1DnUxFF+UebuneE7guafQW3BRNuK63wSRcQ 0ky9Srn7iDfuyEjGYjUaT2vfxcaayJXIBKstPxc52yz2DVuUDpUZcqwFJTHOvpVCzzJs pU9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JCr95xPy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t27si1694193edt.100.2020.05.01.07.04.16; Fri, 01 May 2020 07:04:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JCr95xPy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729148AbgEAN0B (ORCPT + 99 others); Fri, 1 May 2020 09:26:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:47302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729124AbgEANZ7 (ORCPT ); Fri, 1 May 2020 09:25:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B3AA20757; Fri, 1 May 2020 13:25:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588339558; bh=0ddaoSfvKALWn7x17WA7VemeWlSQsiVyT/+WjRgZR3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JCr95xPyf433kh3RpgsWjnoXegIJuV/DI4y+aTpf7JvIo8PIb30EG0H4PWr2wGgYZ E7QSrlC5/GqWrKOtU94JwlMVQEi+HUG2KYUgjN9PIFSYYMlpio9M9epeBMm0NrCFgX J1tSigZg950iJFPGihaUpehOsF1+l3ifKgHWQ+WE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Skobkin , Alexander Tsoy , Takashi Iwai Subject: [PATCH 4.4 38/70] ALSA: usb-audio: Filter out unsupported sample rates on Focusrite devices Date: Fri, 1 May 2020 15:21:26 +0200 Message-Id: <20200501131525.578464968@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200501131513.302599262@linuxfoundation.org> References: <20200501131513.302599262@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Tsoy commit 1c826792586f526a5a5cd21d55aad388f5bb0b23 upstream. Many Focusrite devices supports a limited set of sample rates per altsetting. These includes audio interfaces with ADAT ports: - Scarlett 18i6, 18i8 1st gen, 18i20 1st gen; - Scarlett 18i8 2nd gen, 18i20 2nd gen; - Scarlett 18i8 3rd gen, 18i20 3rd gen; - Clarett 2Pre USB, 4Pre USB, 8Pre USB. Maximum rate is exposed in the last 4 bytes of Format Type descriptor which has a non-standard bLength = 10. Tested-by: Alexey Skobkin Signed-off-by: Alexander Tsoy Cc: Link: https://lore.kernel.org/r/20200418175815.12211-1-alexander@tsoy.me Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/usb/format.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) --- a/sound/usb/format.c +++ b/sound/usb/format.c @@ -223,6 +223,52 @@ static int parse_audio_format_rates_v1(s } /* + * Many Focusrite devices supports a limited set of sampling rates per + * altsetting. Maximum rate is exposed in the last 4 bytes of Format Type + * descriptor which has a non-standard bLength = 10. + */ +static bool focusrite_valid_sample_rate(struct snd_usb_audio *chip, + struct audioformat *fp, + unsigned int rate) +{ + struct usb_interface *iface; + struct usb_host_interface *alts; + unsigned char *fmt; + unsigned int max_rate; + + iface = usb_ifnum_to_if(chip->dev, fp->iface); + if (!iface) + return true; + + alts = &iface->altsetting[fp->altset_idx]; + fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, + NULL, UAC_FORMAT_TYPE); + if (!fmt) + return true; + + if (fmt[0] == 10) { /* bLength */ + max_rate = combine_quad(&fmt[6]); + + /* Validate max rate */ + if (max_rate != 48000 && + max_rate != 96000 && + max_rate != 192000 && + max_rate != 384000) { + + usb_audio_info(chip, + "%u:%d : unexpected max rate: %u\n", + fp->iface, fp->altsetting, max_rate); + + return true; + } + + return rate <= max_rate; + } + + return true; +} + +/* * Helper function to walk the array of sample rate triplets reported by * the device. The problem is that we need to parse whole array first to * get to know how many sample rates we have to expect. @@ -258,6 +304,11 @@ static int parse_uac2_sample_rate_range( } for (rate = min; rate <= max; rate += res) { + /* Filter out invalid rates on Focusrite devices */ + if (USB_ID_VENDOR(chip->usb_id) == 0x1235 && + !focusrite_valid_sample_rate(chip, fp, rate)) + goto skip_rate; + if (fp->rate_table) fp->rate_table[nr_rates] = rate; if (!fp->rate_min || rate < fp->rate_min) @@ -272,6 +323,7 @@ static int parse_uac2_sample_rate_range( break; } +skip_rate: /* avoid endless loop */ if (res == 0) break;