Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp877106pxk; Thu, 17 Sep 2020 20:04:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGoCcB0q2dWobWde8cQOeLlaVGWMHTatn/se6rgl23HMlSw+Tm3oq+Fj5S7Yta+OIKWJNy X-Received: by 2002:a50:cd5d:: with SMTP id d29mr37621390edj.318.1600398287983; Thu, 17 Sep 2020 20:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398287; cv=none; d=google.com; s=arc-20160816; b=X3p9+wqpz5J0TpGpAt0b/to39LhqAUCWpry8mEnVEHJGFgPpB5Lqai8nCGFaHI05RK /oddWpyLdr6vZ1R9p0gJvvnqQiiTBBj7qfFBSuIp1pQwgg5T4Dx2Nx39rZ7NjkqKmSKn OlQ49dRpXUGMnpQCaoqYVnoJryfk/ZirwOjpMZ05ligKtvxj6BJ5oul1f6KUmvulyqKO 7xQGjpXhUOPeO+vzkm+p3Qg6rfM+0I4Ng2X8zU8l/yS+vVY8Wt1m6WEwJ6IF9l/I7Nfn QnNwC+L8YuPjk+z0WwX1H9JsQvJZOunLZ7QTEHqTOLXS92m3JShzbono2Bo6YQcvKaLK HMWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ppJV1VSrNwJKIckyJhTQKe8+rqKkSfzNGKb+GYfjPEs=; b=KDNRZSefTDINKKzYcpJax5gF9AvnPnjPg1L2eWJ5EU1trI+mjhQwbSupaCvb4mTiGH S7t6FCNay70hRkBBmaAtYi1cumY/lWoo0f9Kma4nohoTcBIjC13hiUphIlZWQnDTJUcw 72QwS8hFcAzbwaAFNiE/wqrhSEZsSXKw49j+/ZeBFQufDi58jhPV/IKFVduMWmGQJu+p 6ABbwqW5DB/EjYREtKUGCqNELozFFm2QUnj7S2ptIdlhQqGZqADrMDYrpOQUM+ySKXfu U6phK8QcMv3KwHQYksvcoFF+awYKc28Rnz85HYo+e3oCWqSPB0YG7s8vGOUhqyaCA0Ve TM6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="kIihJ/q6"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j15si1242770ejs.51.2020.09.17.20.04.24; Thu, 17 Sep 2020 20:04:47 -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="kIihJ/q6"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727749AbgIRDAO (ORCPT + 99 others); Thu, 17 Sep 2020 23:00:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:53822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727591AbgIRCFk (ORCPT ); Thu, 17 Sep 2020 22:05:40 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 20A2023718; Fri, 18 Sep 2020 02:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394739; bh=qbSMNsJ2gHPCZ2bjnEYHCu6psAz7c1BEHIounyRdkQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kIihJ/q6cQxj6qR/S4l9OBcFzgFs30eV47Xmn4puG9tUPXXcWjbFyxFQEkU/pZF+i Jcwyv5UKLHyBbVVWd7NP5Xvj899SKmpL3MZ2ik9Op6rrmofHzdi1XVoFjljqqDhNQk L+VyF3YKLOuZTRLRxMkz9LcOGM3HIVo13d6guQfI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andreas Steinmetz , Takashi Iwai , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.4 220/330] ALSA: usb-audio: Fix case when USB MIDI interface has more than one extra endpoint descriptor Date: Thu, 17 Sep 2020 21:59:20 -0400 Message-Id: <20200918020110.2063155-220-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andreas Steinmetz [ Upstream commit 5c6cd7021a05a02fcf37f360592d7c18d4d807fb ] The Miditech MIDIFACE 16x16 (USB ID 1290:1749) has more than one extra endpoint descriptor. The first extra descriptor is: 0x06 0x30 0x00 0x00 0x00 0x00 As the code in snd_usbmidi_get_ms_info() looks only at the first extra descriptor to find USB_DT_CS_ENDPOINT the device as such is recognized but there is neither input nor output configured. The patch iterates through the extra descriptors to find the proper one. With this patch the device is correctly configured. Signed-off-by: Andreas Steinmetz Link: https://lore.kernel.org/r/1c3b431a86f69e1d60745b6110cdb93c299f120b.camel@domdv.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/usb/midi.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/sound/usb/midi.c b/sound/usb/midi.c index 0cb4142b05f64..bc9068b616bb9 100644 --- a/sound/usb/midi.c +++ b/sound/usb/midi.c @@ -1827,6 +1827,28 @@ static int snd_usbmidi_create_endpoints(struct snd_usb_midi *umidi, return 0; } +static struct usb_ms_endpoint_descriptor *find_usb_ms_endpoint_descriptor( + struct usb_host_endpoint *hostep) +{ + unsigned char *extra = hostep->extra; + int extralen = hostep->extralen; + + while (extralen > 3) { + struct usb_ms_endpoint_descriptor *ms_ep = + (struct usb_ms_endpoint_descriptor *)extra; + + if (ms_ep->bLength > 3 && + ms_ep->bDescriptorType == USB_DT_CS_ENDPOINT && + ms_ep->bDescriptorSubtype == UAC_MS_GENERAL) + return ms_ep; + if (!extra[0]) + break; + extralen -= extra[0]; + extra += extra[0]; + } + return NULL; +} + /* * Returns MIDIStreaming device capabilities. */ @@ -1864,11 +1886,8 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi *umidi, ep = get_ep_desc(hostep); if (!usb_endpoint_xfer_bulk(ep) && !usb_endpoint_xfer_int(ep)) continue; - ms_ep = (struct usb_ms_endpoint_descriptor *)hostep->extra; - if (hostep->extralen < 4 || - ms_ep->bLength < 4 || - ms_ep->bDescriptorType != USB_DT_CS_ENDPOINT || - ms_ep->bDescriptorSubtype != UAC_MS_GENERAL) + ms_ep = find_usb_ms_endpoint_descriptor(hostep); + if (!ms_ep) continue; if (usb_endpoint_dir_out(ep)) { if (endpoints[epidx].out_ep) { -- 2.25.1