From patchwork Tue May 13 04:08:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard Gilmutdinov X-Patchwork-Id: 4162241 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4176E9F1C0 for ; Tue, 13 May 2014 04:10:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6964C20328 for ; Tue, 13 May 2014 04:10:10 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 41C2420306 for ; Tue, 13 May 2014 04:10:09 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 4EE7226536C; Tue, 13 May 2014 06:10:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 07D04265311; Tue, 13 May 2014 06:09:20 +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 8228B2652F1; Tue, 13 May 2014 06:09:18 +0200 (CEST) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com [209.85.217.175]) by alsa0.perex.cz (Postfix) with ESMTP id 72ACC2652E5 for ; Tue, 13 May 2014 06:09:10 +0200 (CEST) Received: by mail-lb0-f175.google.com with SMTP id l4so8174347lbv.34 for ; Mon, 12 May 2014 21:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OsFIP8/WoIGAWjtqEA3znY8zM4Kb2KZa4KmTSSOM1Tw=; b=eb/ETtoltfqEAm8oP6zeweZ/M6KFDDN1BSkv2mCKaya3P1tdMPlj5GtORU84DANgJh A+SSK31qs2OvROIFUGi+2WyH+iHN5GXx2b6ttREMs21pjQtdrh+SkCMhZOmyKNarJx3G rXjF//OyV6aA8SmTRDM6nblpGDYlAXazm1zfAco43Sdq17QADoiOjjnFAyCsBSjDvzr/ zzXE/7j1E9zexjDVDedgcwJqhgRR+xqB25WZ7bXwEiaARanDO8hkqTao0IL9SE/meM+1 kr+afCF6yejO9m21p+66rwuqENZDAruZoOj89WErZZE/Suo882H/pe2WSRP0DZP6pqpv KGbA== X-Received: by 10.152.19.195 with SMTP id h3mr20865lae.47.1399954149980; Mon, 12 May 2014 21:09:09 -0700 (PDT) Received: from localhost.localdomain ([46.191.160.54]) by mx.google.com with ESMTPSA id n3sm2930726lan.3.2014.05.12.21.09.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 May 2014 21:09:09 -0700 (PDT) From: Eduard Gilmutdinov To: alsa-devel@alsa-project.org Date: Tue, 13 May 2014 10:08:50 +0600 Message-Id: <1399954131-26516-2-git-send-email-edgilmutdinov@gmail.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1399954131-26516-1-git-send-email-edgilmutdinov@gmail.com> References: <1399954131-26516-1-git-send-email-edgilmutdinov@gmail.com> Cc: mark@xwax.org, daniel@zonque.org Subject: [alsa-devel] [RFC PATCH 1/2] Adds a check of the state of endpoints on the interface before invoking the usb_set_interface 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 Signed-off-by: Eduard Gilmutdinov --- sound/usb/pcm.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index c62a165..e6edfaf 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -453,7 +453,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) struct usb_host_interface *alts; struct usb_interface_descriptor *altsd; struct usb_interface *iface; - int err; + int err, need_init, i; iface = usb_ifnum_to_if(dev, fmt->iface); if (WARN_ON(!iface)) @@ -482,15 +482,28 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) /* set interface */ if (subs->interface != fmt->iface || subs->altset_idx != fmt->altset_idx) { - err = usb_set_interface(dev, fmt->iface, fmt->altsetting); - if (err < 0) { - dev_err(&dev->dev, - "%d:%d: usb_set_interface failed (%d)\n", - fmt->iface, fmt->altsetting, err); - return -EIO; + + need_init = iface->cur_altsetting != alts; + + if (need_init) { + err = usb_set_interface(dev, fmt->iface, fmt->altsetting); + if (err < 0) { + dev_err(&dev->dev, + "%d:%d: usb_set_interface failed (%d)\n", + fmt->iface, fmt->altsetting, err); + return -EIO; + } + dev_dbg(&dev->dev, "setting usb interface %d:%d\n", + fmt->iface, fmt->altsetting); + } + + for (i = 0; i < alts->desc.bNumEndpoints; ++i) { + if (alts->endpoint[i].desc.bEndpointAddress == fmt->endpoint) + alts->endpoint[i].enabled = 1; + else if (need_init) + alts->endpoint[i].enabled = 0; } - dev_dbg(&dev->dev, "setting usb interface %d:%d\n", - fmt->iface, fmt->altsetting); + subs->interface = fmt->iface; subs->altset_idx = fmt->altset_idx; @@ -1210,11 +1223,25 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction) { struct snd_usb_stream *as = snd_pcm_substream_chip(substream); struct snd_usb_substream *subs = &as->substream[direction]; + struct usb_interface *iface; + struct usb_host_interface *cur_alts; + int i, ep_active = 0; stop_endpoints(subs, true); if (!as->chip->shutdown && subs->interface >= 0) { - usb_set_interface(subs->dev, subs->interface, 0); + iface = usb_ifnum_to_if(subs->dev, subs->interface); + cur_alts = iface->cur_altsetting; + for (i = 0; i < cur_alts->desc.bNumEndpoints; ++i) { + if (cur_alts->endpoint[i].desc.bEndpointAddress == subs->ep_num) + cur_alts->endpoint[i].enabled = 0; + + ep_active += cur_alts->endpoint[i].enabled; + } + + if (!ep_active) + usb_set_interface(subs->dev, subs->interface, 0); + subs->interface = -1; }