Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp775149img; Tue, 26 Feb 2019 08:23:39 -0800 (PST) X-Google-Smtp-Source: AHgI3IarPRrb5irr94zq3cdNR0ZGjyaDDHcF+frEwOD9UqY84btx2kF94QRW57wPeFXuhpWf+9vu X-Received: by 2002:a63:aa46:: with SMTP id x6mr25197983pgo.452.1551198219147; Tue, 26 Feb 2019 08:23:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551198219; cv=none; d=google.com; s=arc-20160816; b=iIVPQ4cYqLUohCpVLplMR/1bDeezs7xPyTHZyeAaUIHQYlzqzWWa8z7BoGpSX8cEsR g9Pcz2+/0R/OhkF3OMBh1mAzmtjovFumy5JJv0763LD5dTs29Yl3DvYMPWecuph68ZiM Xr5u2GB9rVFz+2UzGTn8rQxDgFJWU4KFD39K2W/KpxxdlCHE68EM6Y9plDu3WYJtXSUb +Yo/NgkDNP4SxiMxOkX30eKLTaXKZdTLkim7dIojkfB8W0e7f3m4IKsQWd2tGJHRLlSf eEFN+ej7WUj7syftF1baBbOtXi79vOh6AhETN3IEteaU2MBrzC2jxYoSzLlr4c7Giq+W 4zwA== 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=iBKPSsrkqD/I+NqUT441hOMdauH7N07h2jjHLfK+AnI=; b=yHuOrvqNYPLn36p1Ft12k567GGtajD24fwoFD4sUCBVPErW6r9DHY4JHnYJR5CS8+c 16EynIzbSCcYl77zGNOHIlRyBaZK+0z/dRDYHcGKfAHlzm0rNE1q4Wq6e70jNL+m6SyN ptqyerLrMjzKCia/27qipMD1ROwCOidV/SoeY1RKzosVWGiiK0wwReRhzLMlDI4nyqKE Lhcl/38SRapv5rwlfCAiKAG82IHYD3kL7L5n9h8AG9b6WXwcLkWqbsk3Ijct8ble9Fhe XH4fc6N5gY9zXhiWkpuE2IR5ro1TkML84SfQDsI5mn3Jk1z7NjDVkYmkWkDMjcJmZme6 Npag== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=PjhNqiCt; 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 s19si12588788pfh.25.2019.02.26.08.23.24; Tue, 26 Feb 2019 08:23:39 -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=PjhNqiCt; 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 S1729022AbfBZQWp (ORCPT + 99 others); Tue, 26 Feb 2019 11:22:45 -0500 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:36168 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727286AbfBZQWo (ORCPT ); Tue, 26 Feb 2019 11:22:44 -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=iBKPSsrkqD/I+NqUT441hOMdauH7N07h2jjHLfK+AnI=; b=PjhNqiCtrUbf 2pr++4miFO197tNqqM5+bhkF93HKL4Uf8HAhYZcJxdviZLTjMEr62EffZV2yyLI0lbhMewf7SOIqQ 7NkUa9Tq7NjqlTTmzUBVawUxXN9O3psRYo4MAKwS4DJgwvzB72rwAlh1sngbp7HhtcWiOJx17M/fa iaA3o=; Received: from cpc102320-sgyl38-2-0-cust46.18-2.cable.virginm.net ([82.37.168.47] helo=debutante.sirena.org.uk) by heliosphere.sirena.org.uk with esmtpa (Exim 4.89) (envelope-from ) id 1gyfUv-000091-Mt; Tue, 26 Feb 2019 16:22:25 +0000 Received: by debutante.sirena.org.uk (Postfix, from userid 1000) id 3DC5E1121A0A; Tue, 26 Feb 2019 16:22:25 +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: i2s: fix race condition in irq handler" to the asoc tree In-Reply-To: <1551189070-15469-7-git-send-email-olivier.moysan@st.com> X-Patchwork-Hint: ignore Message-Id: <20190226162225.3DC5E1121A0A@debutante.sirena.org.uk> Date: Tue, 26 Feb 2019 16:22:25 +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: i2s: 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 3005decf4fe43e65d882dce838716bd6715757c1 Mon Sep 17 00:00:00 2001 From: Olivier Moysan Date: Tue, 26 Feb 2019 14:51:09 +0100 Subject: [PATCH] ASoC: stm32: i2s: 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_i2s.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sound/soc/stm/stm32_i2s.c b/sound/soc/stm/stm32_i2s.c index 9edb753ffa1b..42ce87a35104 100644 --- a/sound/soc/stm/stm32_i2s.c +++ b/sound/soc/stm/stm32_i2s.c @@ -201,6 +201,7 @@ enum i2s_datlen { * @base: mmio register base virtual address * @phys_addr: I2S registers physical base address * @lock_fd: lock to manage race conditions in full duplex mode + * @irq_lock: prevent race condition with IRQ * @dais_name: DAI name * @mclk_rate: master clock frequency (Hz) * @fmt: DAI protocol @@ -222,6 +223,7 @@ struct stm32_i2s_data { void __iomem *base; dma_addr_t phys_addr; spinlock_t lock_fd; /* Manage race conditions for full duplex */ + spinlock_t irq_lock; /* used to prevent race condition with IRQ */ char dais_name[STM32_I2S_DAI_NAME_SIZE]; unsigned int mclk_rate; unsigned int fmt; @@ -263,8 +265,10 @@ static irqreturn_t stm32_i2s_isr(int irq, void *devid) if (flags & I2S_SR_TIFRE) dev_dbg(&pdev->dev, "Frame error\n"); - if (err) + spin_lock(&i2s->irq_lock); + if (err && i2s->substream) snd_pcm_stop_xrun(i2s->substream); + spin_unlock(&i2s->irq_lock); return IRQ_HANDLED; } @@ -540,9 +544,12 @@ static int stm32_i2s_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) { struct stm32_i2s_data *i2s = snd_soc_dai_get_drvdata(cpu_dai); + unsigned long flags; int ret; + spin_lock_irqsave(&i2s->irq_lock, flags); i2s->substream = substream; + spin_unlock_irqrestore(&i2s->irq_lock, flags); ret = clk_prepare_enable(i2s->i2sclk); if (ret < 0) { @@ -673,13 +680,16 @@ static void stm32_i2s_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) { struct stm32_i2s_data *i2s = snd_soc_dai_get_drvdata(cpu_dai); - - i2s->substream = NULL; + unsigned long flags; regmap_update_bits(i2s->regmap, STM32_I2S_CGFR_REG, I2S_CGFR_MCKOE, (unsigned int)~I2S_CGFR_MCKOE); clk_disable_unprepare(i2s->i2sclk); + + spin_lock_irqsave(&i2s->irq_lock, flags); + i2s->substream = NULL; + spin_unlock_irqrestore(&i2s->irq_lock, flags); } static int stm32_i2s_dai_probe(struct snd_soc_dai *cpu_dai) @@ -874,6 +884,7 @@ static int stm32_i2s_probe(struct platform_device *pdev) i2s->pdev = pdev; i2s->ms_flg = I2S_MS_NOT_SET; spin_lock_init(&i2s->lock_fd); + spin_lock_init(&i2s->irq_lock); platform_set_drvdata(pdev, i2s); ret = stm32_i2s_dais_init(pdev, i2s); -- 2.20.1