From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39EA7C43331 for ; Sun, 29 Mar 2020 08:46:48 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C7CC20714 for ; Sun, 29 Mar 2020 08:46:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="FM04Bcxo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C7CC20714 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id BD20A1670; Sun, 29 Mar 2020 10:45:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz BD20A1670 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1585471605; bh=Q3HnEXtDnABXwa1j8UTyUWjIkn4xS8bSeOZBAA4DYps=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=FM04Bcxol2Y7/RANPWcbRBLAbtdbxOUr96i+s0O1STFEj4TKgzHxQP7qaWTaQ68Iv KiUPuU9YflLeh2o5luE2NFdJCRvdiV5FTG/6iTVz/4XFuBDhpfW2mtt42De3JW3Drm HPMQvT4vocopYB5Y8AKioKpiorK/Gdz3rm7YggV4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4C3B8F80140; Sun, 29 Mar 2020 10:45:54 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 50815F80146; Sun, 29 Mar 2020 10:45:52 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 311B9F8013F for ; Sun, 29 Mar 2020 10:45:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 311B9F8013F X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 47387AB98; Sun, 29 Mar 2020 08:45:48 +0000 (UTC) Date: Sun, 29 Mar 2020 10:45:47 +0200 Message-ID: From: Takashi Iwai To: Andreas Steinmetz Subject: Re: PATCH: ALSA USB MIDI: Fix case when USB MIDI interface has more than one extra endpoint descriptor In-Reply-To: <00decacc4cac6a9d88fe696f94a077284fb8bbb9.camel@domdv.de> References: <00decacc4cac6a9d88fe696f94a077284fb8bbb9.camel@domdv.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org, clemens@ladisch.de X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Thu, 26 Mar 2020 18:18:55 +0100, Andreas Steinmetz wrote: > > 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 > > --- a/sourd/usb/midi.c 2020-03-26 17:34:40.073929497 +0100 > +++ b/sound/usb/midi.c 2020-03-26 17:43:39.123252612 +0100 > @@ -1839,7 +1839,8 @@ > struct usb_host_endpoint *hostep; > struct usb_endpoint_descriptor *ep; > struct usb_ms_endpoint_descriptor *ms_ep; > - int i, epidx; > + int i, epidx, extralen; > + unsigned char *extra; > > intf = umidi->iface; > if (!intf) > @@ -1863,12 +1864,21 @@ > 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 || > + extralen = hostep->extralen; > + extra = hostep->extra; > +repeat: ms_ep = (struct usb_ms_endpoint_descriptor *)extra; > + if (extralen < 1) > + continue; > + if (extralen < 4 || > ms_ep->bLength < 4 || > ms_ep->bDescriptorType != USB_DT_CS_ENDPOINT || > - ms_ep->bDescriptorSubtype != UAC_MS_GENERAL) > - continue; > + ms_ep->bDescriptorSubtype != UAC_MS_GENERAL) { > + if (!extra[0]) > + continue; > + extralen -= extra[0]; > + extra += extra[0]; > + goto repeat; > + } This kind of goto-loop in a loop is really cryptic and error-prone. In general we use goto in the kernel code but only for limited situations such as the unified error code path or the restart of the whole loop after an error condition. But this doesn't fit for such exceptions and can be better rewritten with a simple loop (maybe even better to factor out to a function). So, could you revise the change to be more readable? thanks, Takashi