From patchwork Wed Jan 6 13:36:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 12001649 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 4AD06C43381 for ; Wed, 6 Jan 2021 13:38:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26B2B23121 for ; Wed, 6 Jan 2021 13:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727058AbhAFNib (ORCPT ); Wed, 6 Jan 2021 08:38:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbhAFNi3 (ORCPT ); Wed, 6 Jan 2021 08:38:29 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7034C06135F for ; Wed, 6 Jan 2021 05:37:12 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id qw4so4967127ejb.12 for ; Wed, 06 Jan 2021 05:37:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jMFwjDy/Cb2t1FpYK1S0P8jc5Da5ImJmRl86sM+aIPk=; b=hcw+HELw6+n621TvSxRMA6A84EGzFGLBubtMuoWWoBQK2ra4z+kYXSgFsrJ9QlgfSO T+JoKmnIfj4coHADMramA+JIL0jAMfJMf66p6Sn/NZWj3+F/R7Ipl4iTz89qp97SbjRo lAXG4jYm9ktwhZAEkW7qCelPEQYbfE902wSYGOMXunoEzJ2dUgQSWUQEdRRHjvzLcvJ2 vSJk7cjLUonMBxS0On49z9BFvKtroadzDU9Iz2umCncnzZiX8ACBcBTmJo/5TYm8jTHU 7kH+G13texDDVEqoUWWgC2hRBXMoFds78AQsiynF3KN+1g5ap4lcbGVRD5oTFlKU4jgB 39ew== 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:mime-version:content-transfer-encoding; bh=jMFwjDy/Cb2t1FpYK1S0P8jc5Da5ImJmRl86sM+aIPk=; b=ir/MzBbmuxxwSN7riCp66geiZ3AQBExNL2ZAVkCgWNhcYtQT5/RNxozPgg93wF+bNK L6CSvS7Ea63uPzxe2xVKYMizS8qmVLjMzrOfxBbTKRwUbYngOGjb3eFNRH09CLZ2PV97 upt+Nu8FyVQ9QFR+ElPdP06NZo+30XUqvFqoZ535XDe0dTv2Ck77tXr57VfgffMxPv1v E6m0eLCLj3YnPvzhhWtBebU7LdL9CO9t1PT/0tiJT12CfIMesaa9llsiAfnxxdxOJ8ov wDisiWw/bQRqbWgGqXrWvEAm6aT5bVvMEMEHb21cOqRCAaQjy9Bo+TYyXA+7w0yhtpus 8XmQ== X-Gm-Message-State: AOAM530ugQUDEJU/hx8nv0owqShgpNEryjv2uPk3s8f5XVkiqQTnkYHH 7AV/dgIRQFVfAXmrilpF7XprzA== X-Google-Smtp-Source: ABdhPJzPjr2phle+6BlSN3F/cEU/QBwoLNEZacKP2OTz7iuHYHYfQv8QqRVdKmHF9oxvROZmevrfhg== X-Received: by 2002:a17:906:5f97:: with SMTP id a23mr3027841eju.128.1609940231514; Wed, 06 Jan 2021 05:37:11 -0800 (PST) Received: from localhost.localdomain (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id n20sm1259275ejo.83.2021.01.06.05.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jan 2021 05:37:10 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , Jack Pham , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] usb: gadget: u_audio: clean up locking Date: Wed, 6 Jan 2021 14:36:52 +0100 Message-Id: <20210106133652.512178-6-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210106133652.512178-1-jbrunet@baylibre.com> References: <20210106133652.512178-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org snd_pcm_stream_lock() is held when the ALSA .trigger() callback is called. The lock of 'struct uac_rtd_params' is not necessary since all its locking operation are done under the snd_pcm_stream_lock() too. Also, usb_request .complete() is called with irqs disabled, so saving and restoring the irqs is not necessary. Signed-off-by: Jerome Brunet Acked-by: Felipe Balbi --- drivers/usb/gadget/function/u_audio.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 1d12657b3b73..e985630fbe6e 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -36,9 +36,8 @@ struct uac_rtd_params { void *rbuf; unsigned int max_psize; /* MaxPacketSize of endpoint */ - struct usb_request **reqs; - spinlock_t lock; + struct usb_request **reqs; }; struct snd_uac_chip { @@ -74,7 +73,6 @@ static const struct snd_pcm_hardware uac_pcm_hardware = { static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) { unsigned int pending; - unsigned long flags, flags2; unsigned int hw_ptr; int status = req->status; struct snd_pcm_substream *substream; @@ -105,16 +103,14 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) if (!substream) goto exit; - snd_pcm_stream_lock_irqsave(substream, flags2); + snd_pcm_stream_lock(substream); runtime = substream->runtime; if (!runtime || !snd_pcm_running(substream)) { - snd_pcm_stream_unlock_irqrestore(substream, flags2); + snd_pcm_stream_unlock(substream); goto exit; } - spin_lock_irqsave(&prm->lock, flags); - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { /* * For each IN packet, take the quotient of the current data @@ -141,8 +137,6 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) hw_ptr = prm->hw_ptr; - spin_unlock_irqrestore(&prm->lock, flags); - /* Pack USB load in ALSA ring buffer */ pending = runtime->dma_bytes - hw_ptr; @@ -166,12 +160,10 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) } } - spin_lock_irqsave(&prm->lock, flags); /* update hw_ptr after data is copied to memory */ prm->hw_ptr = (hw_ptr + req->actual) % runtime->dma_bytes; hw_ptr = prm->hw_ptr; - spin_unlock_irqrestore(&prm->lock, flags); - snd_pcm_stream_unlock_irqrestore(substream, flags2); + snd_pcm_stream_unlock(substream); if ((hw_ptr % snd_pcm_lib_period_bytes(substream)) < req->actual) snd_pcm_period_elapsed(substream); @@ -187,7 +179,6 @@ static int uac_pcm_trigger(struct snd_pcm_substream *substream, int cmd) struct uac_rtd_params *prm; struct g_audio *audio_dev; struct uac_params *params; - unsigned long flags; int err = 0; audio_dev = uac->audio_dev; @@ -198,8 +189,6 @@ static int uac_pcm_trigger(struct snd_pcm_substream *substream, int cmd) else prm = &uac->c_prm; - spin_lock_irqsave(&prm->lock, flags); - /* Reset */ prm->hw_ptr = 0; @@ -216,8 +205,6 @@ static int uac_pcm_trigger(struct snd_pcm_substream *substream, int cmd) err = -EINVAL; } - spin_unlock_irqrestore(&prm->lock, flags); - /* Clear buffer after Play stops */ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !prm->ss) memset(prm->rbuf, 0, prm->max_psize * params->req_number); @@ -280,14 +267,12 @@ static int uac_pcm_open(struct snd_pcm_substream *substream) runtime->hw = uac_pcm_hardware; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - spin_lock_init(&uac->p_prm.lock); runtime->hw.rate_min = p_srate; runtime->hw.formats = uac_ssize_to_fmt(p_ssize); runtime->hw.channels_min = num_channels(p_chmask); runtime->hw.period_bytes_min = 2 * uac->p_prm.max_psize / runtime->hw.periods_min; } else { - spin_lock_init(&uac->c_prm.lock); runtime->hw.rate_min = c_srate; runtime->hw.formats = uac_ssize_to_fmt(c_ssize); runtime->hw.channels_min = num_channels(c_chmask);