Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2047343imb; Sun, 3 Mar 2019 16:07:10 -0800 (PST) X-Google-Smtp-Source: APXvYqzJHSHdUD4yinrm5QssfhALQoBPixltZaU/A1520tn3/3yVSMlC8Macp86OfxY5u9ymrKVQ X-Received: by 2002:a62:a113:: with SMTP id b19mr17059725pff.227.1551658030281; Sun, 03 Mar 2019 16:07:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551658030; cv=none; d=google.com; s=arc-20160816; b=LblxH9TE7U57pJRsppJPiZlGW86yQFqCJ995Ts2IL51zpVBW0xnEDlVhUirYrq7Tww w6MN97tLP9o1IpYwwp2Kdbev8vxMF6bsT93JwLvlsTQFnZyLh21jYMwGdEUkfLY2V35e 06I/30/RUaiqEjAR8Fqc/9dCrC8uPHN7D+xd161Jc6/d/9jHq3jC/MQT3pepWPmW0p2g DyrX/iF1Cy0dzcpGQQChzZFBXiT7D2LkQQl2e09+Ybpp93LNWm04lpk/lQQOWEDqdsZD F2Ae/eJm+opEnIeZfD3N878JM2HSFCAmi9YNnyIB6r7SRQdP5J2aHzr3Y0/aVbdZxKqZ Qwdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:in-reply-to:subject:cc:to :from:dkim-signature; bh=DimZzXIccX5n2wZsU7/xNpIi0EfbiwCbcwqHMcF3jfQ=; b=fKxRqc3IBy1s95Mz/K5C2dgZPcRvW/7uWBfWCat+toWSoWrpIz3JYuwwuv2Dq0qEgP S8yAPKyVUZGsbjSbs0vZoqVzeJXaj+DYZuymy/gcfFRSRVm9yhtzGmgx4w2aImIjFokx mVqPyPm8bHHTKRRLynl4csnO2la2bfDeBVP2LMSOo9Xb7XlL7ByFanT24khNrxKejge5 wTJLC1lbE83tnweomS0R8wLvqZjzZEH2gEBbrVC43vnsJoaqjg/JA38G39+3P1YmPxxi KLwnD6y3K5ff2rBm9PSPsdybnlmuGcj3FzIKpZFfH1XceyykGSsnCl5fNHWmv38QizVn 5sjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=TrXWrs0q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si4086582ply.30.2019.03.03.16.06.55; Sun, 03 Mar 2019 16:07:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=TrXWrs0q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726162AbfCDAGT (ORCPT + 99 others); Sun, 3 Mar 2019 19:06:19 -0500 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:53262 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbfCDAGO (ORCPT ); Sun, 3 Mar 2019 19:06:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=DimZzXIccX5n2wZsU7/xNpIi0EfbiwCbcwqHMcF3jfQ=; b=TrXWrs0qO36S kM7s+M0fTjK8Aif/RCQbMl1joe71qtBMijks7WOh6Tep+19BD2lAGwl0enySHtX+2v786JJGzPI06 ZT7mAGvhqBMjt/KoEBwuJC7VoOzOYLJLFS0iGLsA0BtSnxi5GjpWA7lxrLWZwwzNW+AlfTnaGIX7T vBtjw=; Received: from cpc102320-sgyl38-2-0-cust46.18-2.cable.virginm.net ([82.37.168.47] helo=finisterre.ee.mobilebroadband) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1h0b7I-0007O4-E2; Mon, 04 Mar 2019 00:06:00 +0000 Received: by finisterre.ee.mobilebroadband (Postfix, from userid 1000) id B9E0A440082; Mon, 4 Mar 2019 00:05:59 +0000 (GMT) From: Mark Brown To: Olivier Moysan Cc: Mark Brown , lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org, olivier.moysan@st.com, arnaud.pouliquen@st.com, benjamin.gaignard@st.com, alsa-devel@alsa-project.org Subject: Applied "ASoC: stm32: sai: fix race condition in irq handler" to the asoc tree In-Reply-To: <1551359965-25228-4-git-send-email-olivier.moysan@st.com> X-Patchwork-Hint: ignore Message-Id: <20190304000559.B9E0A440082@finisterre.ee.mobilebroadband> Date: Mon, 4 Mar 2019 00:05:59 +0000 (GMT) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch ASoC: stm32: sai: fix race condition in irq handler has been applied to the asoc tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From 26f98e82dd49b7c3cc5ef0edd882aa732a62b672 Mon Sep 17 00:00:00 2001 From: Olivier Moysan Date: Thu, 28 Feb 2019 14:19:23 +0100 Subject: [PATCH] ASoC: stm32: sai: fix race condition in irq handler When snd_pcm_stop_xrun() is called in interrupt routine, substream context may have already been released. Add protection on substream context. Signed-off-by: Olivier Moysan Signed-off-by: Mark Brown --- sound/soc/stm/stm32_sai_sub.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index e418f446e03b..cad415e03b5e 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -102,6 +102,7 @@ * @spdif_frm_cnt: S/PDIF playback frame counter * @iec958: iec958 data * @ctrl_lock: control lock + * @irq_lock: prevent race condition with IRQ */ struct stm32_sai_sub_data { struct platform_device *pdev; @@ -133,6 +134,7 @@ struct stm32_sai_sub_data { unsigned int spdif_frm_cnt; struct snd_aes_iec958 iec958; struct mutex ctrl_lock; /* protect resources accessed by controls */ + spinlock_t irq_lock; /* used to prevent race condition with IRQ */ }; enum stm32_sai_fifo_th { @@ -474,8 +476,10 @@ static irqreturn_t stm32_sai_isr(int irq, void *devid) status = SNDRV_PCM_STATE_XRUN; } - if (status != SNDRV_PCM_STATE_RUNNING) + spin_lock(&sai->irq_lock); + if (status != SNDRV_PCM_STATE_RUNNING && sai->substream) snd_pcm_stop_xrun(sai->substream); + spin_unlock(&sai->irq_lock); return IRQ_HANDLED; } @@ -679,8 +683,11 @@ static int stm32_sai_startup(struct snd_pcm_substream *substream, { struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); int imr, cr2, ret; + unsigned long flags; + spin_lock_irqsave(&sai->irq_lock, flags); sai->substream = substream; + spin_unlock_irqrestore(&sai->irq_lock, flags); if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { snd_pcm_hw_constraint_mask64(substream->runtime, @@ -1059,6 +1066,7 @@ static void stm32_sai_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) { struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); + unsigned long flags; regmap_update_bits(sai->regmap, STM_SAI_IMR_REGX, SAI_XIMR_MASK, 0); @@ -1069,7 +1077,9 @@ static void stm32_sai_shutdown(struct snd_pcm_substream *substream, clk_rate_exclusive_put(sai->sai_mclk); + spin_lock_irqsave(&sai->irq_lock, flags); sai->substream = NULL; + spin_unlock_irqrestore(&sai->irq_lock, flags); } static int stm32_sai_pcm_new(struct snd_soc_pcm_runtime *rtd, @@ -1433,6 +1443,7 @@ static int stm32_sai_sub_probe(struct platform_device *pdev) sai->pdev = pdev; mutex_init(&sai->ctrl_lock); + spin_lock_init(&sai->irq_lock); platform_set_drvdata(pdev, sai); sai->pdata = dev_get_drvdata(pdev->dev.parent); -- 2.20.1