From patchwork Mon Mar 25 16:00:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10869577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CED117E6 for ; Mon, 25 Mar 2019 16:21:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43AA529184 for ; Mon, 25 Mar 2019 16:21:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37FEC293C3; Mon, 25 Mar 2019 16:21:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2ACAA29184 for ; Mon, 25 Mar 2019 16:21:20 +0000 (UTC) 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 D425B871; Mon, 25 Mar 2019 17:03:50 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D425B871 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1553529880; bh=/Un6rrGvReL82AxvQYnlAtaxU+p0FtGhjdRkFsfrV3I=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=OXXNfMUsiRhv0wnmgs8FSgMQfB3ozfnnNoZQVxn8ufHTBBHyAmhVHFCubwFaE+0u7 RynpEAb9diNQO310DC9sfpliXYFsa8+saOA51ZspzrVRDdpuScWLYx8Eg3lqdsSDp4 wk7W77/qkcLw/QXTW/RkLWry2Xhff6Y0oMcULDNk= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 09897F89727; Mon, 25 Mar 2019 17:01:36 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id B2F70F89717; Mon, 25 Mar 2019 17:01:26 +0100 (CET) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id C8CC1F80C0F; Mon, 25 Mar 2019 17:01:22 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C8CC1F80C0F Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 87C133C00DD; Mon, 25 Mar 2019 17:01:22 +0100 (CET) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id W0r9sNwF8bGB; Mon, 25 Mar 2019 17:01:15 +0100 (CET) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 889893C013F; Mon, 25 Mar 2019 17:01:05 +0100 (CET) Received: from vmlxhi-087.adit-jv.com (10.72.93.172) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.435.0; Mon, 25 Mar 2019 17:01:04 +0100 From: To: , , , Date: Mon, 25 Mar 2019 17:00:38 +0100 Message-ID: <1553529644-5654-5-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1553529644-5654-1-git-send-email-twischer@de.adit-jv.com> References: <1553529644-5654-1-git-send-email-twischer@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: Timo Wischer , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [alsa-devel] [PATCH 04/10] ALSA: aloop: Use always spin_lock_irqsave() for cable->lock 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" X-Virus-Scanned: ClamAV using ClamSMTP From: Timo Wischer to allow the usage of timer callbacks from interrupt context. For example the sound timer. Signed-off-by: Timo Wischer --- sound/drivers/aloop.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c index 11e8ed6..c6217c4 100644 --- a/sound/drivers/aloop.c +++ b/sound/drivers/aloop.c @@ -272,6 +272,7 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) struct loopback_pcm *dpcm = runtime->private_data; struct loopback_cable *cable = dpcm->cable; int err = 0, stream = 1 << substream->stream; + unsigned long flags; switch (cmd) { case SNDRV_PCM_TRIGGER_START: @@ -281,39 +282,39 @@ static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) dpcm->last_jiffies = jiffies; dpcm->pcm_rate_shift = 0; dpcm->last_drift = 0; - spin_lock(&cable->lock); + spin_lock_irqsave(&cable->lock, flags); cable->running |= stream; cable->pause &= ~stream; err = loopback_timer_start(dpcm); - spin_unlock(&cable->lock); + spin_unlock_irqrestore(&cable->lock, flags); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) loopback_active_notify(dpcm); break; case SNDRV_PCM_TRIGGER_STOP: - spin_lock(&cable->lock); + spin_lock_irqsave(&cable->lock, flags); cable->running &= ~stream; cable->pause &= ~stream; err = loopback_timer_stop(dpcm); - spin_unlock(&cable->lock); + spin_unlock_irqrestore(&cable->lock, flags); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) loopback_active_notify(dpcm); break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_SUSPEND: - spin_lock(&cable->lock); + spin_lock_irqsave(&cable->lock, flags); cable->pause |= stream; err = loopback_timer_stop(dpcm); - spin_unlock(&cable->lock); + spin_unlock_irqrestore(&cable->lock, flags); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) loopback_active_notify(dpcm); break; case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: - spin_lock(&cable->lock); + spin_lock_irqsave(&cable->lock, flags); dpcm->last_jiffies = jiffies; cable->pause &= ~stream; err = loopback_timer_start(dpcm); - spin_unlock(&cable->lock); + spin_unlock_irqrestore(&cable->lock, flags); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) loopback_active_notify(dpcm); break; @@ -557,12 +558,13 @@ static snd_pcm_uframes_t loopback_pointer(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct loopback_pcm *dpcm = runtime->private_data; + unsigned long flags; snd_pcm_uframes_t pos; - spin_lock(&dpcm->cable->lock); + spin_lock_irqsave(&dpcm->cable->lock, flags); loopback_pos_update(dpcm->cable); pos = dpcm->buf_pos; - spin_unlock(&dpcm->cable->lock); + spin_unlock_irqrestore(&dpcm->cable->lock, flags); return bytes_to_frames(runtime, pos); } @@ -679,10 +681,12 @@ static void free_cable(struct snd_pcm_substream *substream) if (!cable) return; if (cable->streams[!substream->stream]) { + unsigned long flags; + /* other stream is still alive */ - spin_lock_irq(&cable->lock); + spin_lock_irqsave(&cable->lock, flags); cable->streams[substream->stream] = NULL; - spin_unlock_irq(&cable->lock); + spin_unlock_irqrestore(&cable->lock, flags); } else { /* free the cable */ loopback->cables[substream->number][dev] = NULL; @@ -698,6 +702,7 @@ static int loopback_open(struct snd_pcm_substream *substream) struct loopback_cable *cable = NULL; int err = 0; int dev = get_cable_index(substream); + unsigned long flags; mutex_lock(&loopback->cable_lock); dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); @@ -753,9 +758,9 @@ static int loopback_open(struct snd_pcm_substream *substream) else runtime->hw = cable->hw; - spin_lock_irq(&cable->lock); + spin_lock_irqsave(&cable->lock, flags); cable->streams[substream->stream] = dpcm; - spin_unlock_irq(&cable->lock); + spin_unlock_irqrestore(&cable->lock, flags); unlock: if (err < 0) {