From nobody Wed Feb 11 00:54:53 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0D6DC77B7C for ; Thu, 11 May 2023 12:10:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237962AbjEKMKK (ORCPT ); Thu, 11 May 2023 08:10:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238076AbjEKMKB (ORCPT ); Thu, 11 May 2023 08:10:01 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E71D40C3 for ; Thu, 11 May 2023 05:09:27 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba6939e78a0so5535323276.0 for ; Thu, 11 May 2023 05:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683806967; x=1686398967; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=st4R3zKUH/xDsc4YN+VqInFo/FugaRQOoRBGi61bjqE=; b=m+lpwYdAygmfKOuXS+rQL/1j+qy/4Jz6w5tgYS6IE7Pba0DbUI9SEMsJqPLxgiQmSv DHcJyttCt2F2R2E36BgSM5sBH56vGVofydABwW/EmBIyxn4cW/Oahy1bBHUIREI6+DSg /hTZO1DqOjYEQvTQstR7p+Fs7gycdc2Ps0s1IQXVLp2IP8iqySVFSNNJTC1E+jUSFEnD dQkzy8yX7o3wt4oGzUyFNsBt2ATKu9Bk/T750q27YoO2as2FiLJz1cjtUU/FkHw6s1ZF eOl9Y35rL64M/+9X2qvKk3C+n2bPfAEyHsDdVwOoBAO00l3a66vxlb/sjXpZZ9rYU6vb 6o3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683806967; x=1686398967; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=st4R3zKUH/xDsc4YN+VqInFo/FugaRQOoRBGi61bjqE=; b=AZUwRrlGeERyFj8zFS7XeED+88XhZsYT/D1iVyZggF19F/g8eLqbzJUfwF+Z97jya8 SdE2KAC57wxlzYI+G+pccfRupsu2mCnLKdFD4dlZuvgD/3EcsqhM4srejh0sOs97lzfh orutLSqKbbbJi6rDDdk4iPzY5jXNSZ9lmyyJts2kQFKms2vrJdanGs1h1v8OdqhqhNFJ OupjNEhZi96jGgH9LuIxLiDJaZ5f2f9TvtR/qpx8qPpk6XPzCkA3o6AoM7KrER8aC4NO JHszKAA+1x3g1nxD9z/LM/Z2rJ/ZqYGzlGZBDslLyUYOPiR9Iix1ZTv9JLHm/8/X6t+Q lBkQ== X-Gm-Message-State: AC+VfDwtTh5Uf6rh4Gx/u3WJVylXhSH2T8XP4/qReJAMY44Z0P1nT8U5 G1bKbndbZHHb+eFGKrVt5rHhfztmrW4/K82WcA== X-Google-Smtp-Source: ACHHUZ49WZh7iQOeS0awLJJmsXs+E42WhPdiu6SF2appFp6ziPx5fny2JHtoWPEWZ19dxRNoHu1piFy54NK2S2VgeQ== X-Received: from yixuanjiang.ntc.corp.google.com ([2401:fa00:fc:202:6c9a:64c9:7e44:6b1d]) (user=yixuanjiang job=sendgmr) by 2002:a25:1283:0:b0:b9a:672d:23c9 with SMTP id 125-20020a251283000000b00b9a672d23c9mr12770147ybs.0.1683806966890; Thu, 11 May 2023 05:09:26 -0700 (PDT) Date: Thu, 11 May 2023 20:08:38 +0800 In-Reply-To: <20230511120841.2096524-1-yixuanjiang@google.com> Mime-Version: 1.0 References: <20230511120841.2096524-1-yixuanjiang@google.com> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230511120841.2096524-4-yixuanjiang@google.com> Subject: [PATCH 3/6] ASoC: soc-pcm: Fix and cleanup DPCM locking From: yixuanjiang To: tiwai@suse.com, lgirdwood@gmail.com, broonie@kernel.org Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Takashi Iwai , Pierre-Louis Bossart , Kai Vehmanen , Bard Liao , Ranjani Sridharan , Yixuan Jiang , stable@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Takashi Iwai [ Upstream commit b7898396f4bbe160f546d0c5e9fa17cca9a7d153 ] The existing locking for DPCM has several issues a) a confusing mix of card->mutex and card->pcm_mutex. b) a dpcm_lock spinlock added inconsistently and on paths that could be recursively taken. The use of irqsave/irqrestore was also overkill. The suggested model is: 1) The pcm_mutex is the top-most protection of BE links in the FE. The pcm_mutex is applied always on either the top PCM callbacks or the external call from DAPM, not taken in the internal functions. 2) the FE stream lock is taken in higher levels before invoking dpcm_be_dai_trigger() 3) when adding and deleting a BE, both the pcm_mutex and FE stream lock are taken. Signed-off-by: Takashi Iwai [clarification of commit message by plbossart] Signed-off-by: Pierre-Louis Bossart Reviewed-by: Kai Vehmanen Reviewed-by: Bard Liao Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/20211207173745.15850-4-pierre-louis.bossart= @linux.intel.com Signed-off-by: Mark Brown Fixes: aa9ff6a4955f ("ASoC: soc-compress: Reposition and add pcm_mutex") Signed-off-by: Yixuan Jiang Cc: stable@vger.kernel.org # 5.15+ --- include/sound/soc.h | 2 - sound/soc/soc-core.c | 1 - sound/soc/soc-pcm.c | 229 ++++++++++++++++++++++++++++--------------- 3 files changed, 152 insertions(+), 80 deletions(-) diff --git a/include/sound/soc.h b/include/sound/soc.h index 0fa0a34582322..c653c5ece68ca 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -907,8 +907,6 @@ struct snd_soc_card { struct mutex pcm_mutex; enum snd_soc_pcm_subclass pcm_subclass; =20 - spinlock_t dpcm_lock; - int (*probe)(struct snd_soc_card *card); int (*late_probe)(struct snd_soc_card *card); int (*remove)(struct snd_soc_card *card); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index edebb3f50a069..f24e32c765a24 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2339,7 +2339,6 @@ int snd_soc_register_card(struct snd_soc_card *card) mutex_init(&card->mutex); mutex_init(&card->dapm_mutex); mutex_init(&card->pcm_mutex); - spin_lock_init(&card->dpcm_lock); =20 return snd_soc_bind_card(card); } diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 373f20bd14301..a9869203804e7 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -27,6 +27,31 @@ #include #include =20 +static inline void snd_soc_dpcm_mutex_lock(struct snd_soc_pcm_runtime *rtd) +{ + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); +} + +static inline void snd_soc_dpcm_mutex_unlock(struct snd_soc_pcm_runtime *r= td) +{ + mutex_unlock(&rtd->card->pcm_mutex); +} + +#define snd_soc_dpcm_mutex_assert_held(rtd) \ + lockdep_assert_held(&(rtd)->card->pcm_mutex) + +static inline void snd_soc_dpcm_stream_lock_irq(struct snd_soc_pcm_runtime= *rtd, + int stream) +{ + snd_pcm_stream_lock_irq(snd_soc_dpcm_get_substream(rtd, stream)); +} + +static inline void snd_soc_dpcm_stream_unlock_irq(struct snd_soc_pcm_runti= me *rtd, + int stream) +{ + snd_pcm_stream_unlock_irq(snd_soc_dpcm_get_substream(rtd, stream)); +} + #define DPCM_MAX_BE_USERS 8 =20 static inline const char *soc_cpu_dai_name(struct snd_soc_pcm_runtime *rtd) @@ -73,7 +98,6 @@ static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime= *fe, struct snd_pcm_hw_params *params =3D &fe->dpcm[stream].hw_params; struct snd_soc_dpcm *dpcm; ssize_t offset =3D 0; - unsigned long flags; =20 /* FE state */ offset +=3D scnprintf(buf + offset, size - offset, @@ -101,7 +125,6 @@ static ssize_t dpcm_show_state(struct snd_soc_pcm_runti= me *fe, goto out; } =20 - spin_lock_irqsave(&fe->card->dpcm_lock, flags); for_each_dpcm_be(fe, stream, dpcm) { struct snd_soc_pcm_runtime *be =3D dpcm->be; params =3D &dpcm->hw_params; @@ -122,7 +145,6 @@ static ssize_t dpcm_show_state(struct snd_soc_pcm_runti= me *fe, params_channels(params), params_rate(params)); } - spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); out: return offset; } @@ -145,11 +167,13 @@ static ssize_t dpcm_state_read_file(struct file *file= , char __user *user_buf, if (!buf) return -ENOMEM; =20 + snd_soc_dpcm_mutex_lock(fe); for_each_pcm_streams(stream) if (snd_soc_dai_stream_valid(asoc_rtd_to_cpu(fe, 0), stream)) offset +=3D dpcm_show_state(fe, stream, buf + offset, out_count - offset); + snd_soc_dpcm_mutex_unlock(fe); =20 ret =3D simple_read_from_buffer(user_buf, count, ppos, buf, offset); =20 @@ -221,14 +245,14 @@ static void dpcm_set_fe_update_state(struct snd_soc_p= cm_runtime *fe, struct snd_pcm_substream *substream =3D snd_soc_dpcm_get_substream(fe, stream); =20 - snd_pcm_stream_lock_irq(substream); + snd_soc_dpcm_stream_lock_irq(fe, stream); if (state =3D=3D SND_SOC_DPCM_UPDATE_NO && fe->dpcm[stream].trigger_pendi= ng) { dpcm_fe_dai_do_trigger(substream, fe->dpcm[stream].trigger_pending - 1); fe->dpcm[stream].trigger_pending =3D 0; } fe->dpcm[stream].runtime_update =3D state; - snd_pcm_stream_unlock_irq(substream); + snd_soc_dpcm_stream_unlock_irq(fe, stream); } =20 static void dpcm_set_be_update_state(struct snd_soc_pcm_runtime *be, @@ -256,7 +280,7 @@ void snd_soc_runtime_action(struct snd_soc_pcm_runtime = *rtd, struct snd_soc_dai *dai; int i; =20 - lockdep_assert_held(&rtd->card->pcm_mutex); + snd_soc_dpcm_mutex_assert_held(rtd); =20 for_each_rtd_dais(rtd, i, dai) snd_soc_dai_action(dai, stream, action); @@ -309,6 +333,8 @@ int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *= fe, int dir, { struct snd_soc_dpcm *dpcm; =20 + snd_soc_dpcm_mutex_assert_held(fe); + for_each_dpcm_be(fe, dir, dpcm) { =20 struct snd_soc_pcm_runtime *be =3D dpcm->be; @@ -646,14 +672,14 @@ static int soc_pcm_components_close(struct snd_pcm_su= bstream *substream, return ret; } =20 -static int soc_pcm_clean(struct snd_pcm_substream *substream, int rollback) +static int soc_pcm_clean(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_substream *substream, int rollback) { - struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); struct snd_soc_component *component; struct snd_soc_dai *dai; int i; =20 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); + snd_soc_dpcm_mutex_assert_held(rtd); =20 if (!rollback) snd_soc_runtime_deactivate(rtd, substream->stream); @@ -665,9 +691,6 @@ static int soc_pcm_clean(struct snd_pcm_substream *subs= tream, int rollback) =20 soc_pcm_components_close(substream, rollback); =20 - - mutex_unlock(&rtd->card->pcm_mutex); - snd_soc_pcm_component_pm_runtime_put(rtd, substream, rollback); =20 for_each_rtd_components(rtd, i, component) @@ -682,9 +705,21 @@ static int soc_pcm_clean(struct snd_pcm_substream *sub= stream, int rollback) * freed here. The cpu DAI, codec DAI, machine and components are also * shutdown. */ +static int __soc_pcm_close(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_substream *substream) +{ + return soc_pcm_clean(rtd, substream, 0); +} + +/* PCM close ops for non-DPCM streams */ static int soc_pcm_close(struct snd_pcm_substream *substream) { - return soc_pcm_clean(substream, 0); + struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); + + snd_soc_dpcm_mutex_lock(rtd); + soc_pcm_clean(rtd, substream, 0); + snd_soc_dpcm_mutex_unlock(rtd); + return 0; } =20 static int soc_hw_sanity_check(struct snd_pcm_substream *substream) @@ -730,21 +765,21 @@ static int soc_hw_sanity_check(struct snd_pcm_substre= am *substream) * then initialized and any private data can be allocated. This also calls * startup for the cpu DAI, component, machine and codec DAI. */ -static int soc_pcm_open(struct snd_pcm_substream *substream) +static int __soc_pcm_open(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_substream *substream) { - struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); struct snd_soc_component *component; struct snd_soc_dai *dai; int i, ret =3D 0; =20 + snd_soc_dpcm_mutex_assert_held(rtd); + for_each_rtd_components(rtd, i, component) pinctrl_pm_select_default_state(component->dev); =20 ret =3D snd_soc_pcm_component_pm_runtime_get(rtd, substream); if (ret < 0) - goto pm_err; - - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); + goto err; =20 ret =3D soc_pcm_components_open(substream); if (ret < 0) @@ -786,16 +821,26 @@ static int soc_pcm_open(struct snd_pcm_substream *sub= stream) snd_soc_runtime_activate(rtd, substream->stream); ret =3D 0; err: - mutex_unlock(&rtd->card->pcm_mutex); -pm_err: if (ret < 0) { - soc_pcm_clean(substream, 1); + soc_pcm_clean(rtd, substream, 1); dev_err(rtd->dev, "%s() failed (%d)", __func__, ret); } =20 return ret; } =20 +/* PCM open ops for non-DPCM streams */ +static int soc_pcm_open(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); + int ret; + + snd_soc_dpcm_mutex_lock(rtd); + ret =3D __soc_pcm_open(rtd, substream); + snd_soc_dpcm_mutex_unlock(rtd); + return ret; +} + static void codec2codec_close_delayed_work(struct snd_soc_pcm_runtime *rtd) { /* @@ -811,13 +856,13 @@ static void codec2codec_close_delayed_work(struct snd= _soc_pcm_runtime *rtd) * rate, etc. This function is non atomic and can be called multiple time= s, * it can refer to the runtime info. */ -static int soc_pcm_prepare(struct snd_pcm_substream *substream) +static int __soc_pcm_prepare(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_substream *substream) { - struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); struct snd_soc_dai *dai; int i, ret =3D 0; =20 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); + snd_soc_dpcm_mutex_assert_held(rtd); =20 ret =3D snd_soc_link_prepare(substream); if (ret < 0) @@ -845,14 +890,24 @@ static int soc_pcm_prepare(struct snd_pcm_substream *= substream) snd_soc_dai_digital_mute(dai, 0, substream->stream); =20 out: - mutex_unlock(&rtd->card->pcm_mutex); - if (ret < 0) dev_err(rtd->dev, "ASoC: %s() failed (%d)\n", __func__, ret); =20 return ret; } =20 +/* PCM prepare ops for non-DPCM streams */ +static int soc_pcm_prepare(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); + int ret; + + snd_soc_dpcm_mutex_lock(rtd); + ret =3D __soc_pcm_prepare(rtd, substream); + snd_soc_dpcm_mutex_unlock(rtd); + return ret; +} + static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params, unsigned int mask) { @@ -864,13 +919,13 @@ static void soc_pcm_codec_params_fixup(struct snd_pcm= _hw_params *params, interval->max =3D channels; } =20 -static int soc_pcm_hw_clean(struct snd_pcm_substream *substream, int rollb= ack) +static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_substream *substream, int rollback) { - struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); struct snd_soc_dai *dai; int i; =20 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); + snd_soc_dpcm_mutex_assert_held(rtd); =20 /* clear the corresponding DAIs parameters when going to be inactive */ for_each_rtd_dais(rtd, i, dai) { @@ -900,16 +955,28 @@ static int soc_pcm_hw_clean(struct snd_pcm_substream = *substream, int rollback) snd_soc_dai_hw_free(dai, substream, rollback); } =20 - mutex_unlock(&rtd->card->pcm_mutex); return 0; } =20 /* * Frees resources allocated by hw_params, can be called multiple times */ +static int __soc_pcm_hw_free(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_substream *substream) +{ + return soc_pcm_hw_clean(rtd, substream, 0); +} + +/* hw_free PCM ops for non-DPCM streams */ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) { - return soc_pcm_hw_clean(substream, 0); + struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); + int ret; + + snd_soc_dpcm_mutex_lock(rtd); + ret =3D __soc_pcm_hw_free(rtd, substream); + snd_soc_dpcm_mutex_unlock(rtd); + return ret; } =20 /* @@ -917,15 +984,15 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *= substream) * function can also be called multiple times and can allocate buffers * (using snd_pcm_lib_* ). It's non-atomic. */ -static int soc_pcm_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *params) +static int __soc_pcm_hw_params(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) { - struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); struct snd_soc_dai *cpu_dai; struct snd_soc_dai *codec_dai; int i, ret =3D 0; =20 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); + snd_soc_dpcm_mutex_assert_held(rtd); =20 ret =3D soc_pcm_params_symmetry(substream, params); if (ret) @@ -997,16 +1064,27 @@ static int soc_pcm_hw_params(struct snd_pcm_substrea= m *substream, =20 ret =3D snd_soc_pcm_component_hw_params(substream, params); out: - mutex_unlock(&rtd->card->pcm_mutex); - if (ret < 0) { - soc_pcm_hw_clean(substream, 1); + soc_pcm_hw_clean(rtd, substream, 1); dev_err(rtd->dev, "ASoC: %s() failed (%d)\n", __func__, ret); } =20 return ret; } =20 +/* hw_params PCM ops for non-DPCM streams */ +static int soc_pcm_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); + int ret; + + snd_soc_dpcm_mutex_lock(rtd); + ret =3D __soc_pcm_hw_params(rtd, substream, params); + snd_soc_dpcm_mutex_unlock(rtd); + return ret; +} + static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); @@ -1126,7 +1204,8 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime= *fe, struct snd_pcm_substream *fe_substream; struct snd_pcm_substream *be_substream; struct snd_soc_dpcm *dpcm; - unsigned long flags; + + snd_soc_dpcm_mutex_assert_held(fe); =20 /* only add new dpcms */ for_each_dpcm_be(fe, stream, dpcm) { @@ -1156,10 +1235,10 @@ static int dpcm_be_connect(struct snd_soc_pcm_runti= me *fe, dpcm->fe =3D fe; be->dpcm[stream].runtime =3D fe->dpcm[stream].runtime; dpcm->state =3D SND_SOC_DPCM_LINK_STATE_NEW; - spin_lock_irqsave(&fe->card->dpcm_lock, flags); + snd_soc_dpcm_stream_lock_irq(fe, stream); list_add(&dpcm->list_be, &fe->dpcm[stream].be_clients); list_add(&dpcm->list_fe, &be->dpcm[stream].fe_clients); - spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + snd_soc_dpcm_stream_unlock_irq(fe, stream); =20 dev_dbg(fe->dev, "connected new DPCM %s path %s %s %s\n", stream ? "capture" : "playback", fe->dai_link->name, @@ -1204,8 +1283,10 @@ static void dpcm_be_reparent(struct snd_soc_pcm_runt= ime *fe, void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream) { struct snd_soc_dpcm *dpcm, *d; - unsigned long flags; =20 + snd_soc_dpcm_mutex_assert_held(fe); + + snd_soc_dpcm_stream_lock_irq(fe, stream); for_each_dpcm_be_safe(fe, stream, dpcm, d) { dev_dbg(fe->dev, "ASoC: BE %s disconnect check for %s\n", stream ? "capture" : "playback", @@ -1223,12 +1304,11 @@ void dpcm_be_disconnect(struct snd_soc_pcm_runtime = *fe, int stream) =20 dpcm_remove_debugfs_state(dpcm); =20 - spin_lock_irqsave(&fe->card->dpcm_lock, flags); list_del(&dpcm->list_be); list_del(&dpcm->list_fe); - spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); kfree(dpcm); } + snd_soc_dpcm_stream_unlock_irq(fe, stream); } =20 /* get BE for DAI widget and stream */ @@ -1442,12 +1522,9 @@ int dpcm_process_paths(struct snd_soc_pcm_runtime *f= e, void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream) { struct snd_soc_dpcm *dpcm; - unsigned long flags; =20 - spin_lock_irqsave(&fe->card->dpcm_lock, flags); for_each_dpcm_be(fe, stream, dpcm) dpcm_set_be_update_state(dpcm->be, stream, SND_SOC_DPCM_UPDATE_NO); - spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); } =20 void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream, @@ -1483,12 +1560,12 @@ void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *f= e, int stream, continue; =20 if (be->dpcm[stream].state !=3D SND_SOC_DPCM_STATE_HW_FREE) { - soc_pcm_hw_free(be_substream); + __soc_pcm_hw_free(be, be_substream); be->dpcm[stream].state =3D SND_SOC_DPCM_STATE_HW_FREE; } } =20 - soc_pcm_close(be_substream); + __soc_pcm_close(be, be_substream); be_substream->runtime =3D NULL; be->dpcm[stream].state =3D SND_SOC_DPCM_STATE_CLOSE; } @@ -1536,7 +1613,7 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *f= e, int stream) stream ? "capture" : "playback", be->dai_link->name); =20 be_substream->runtime =3D be->dpcm[stream].runtime; - err =3D soc_pcm_open(be_substream); + err =3D __soc_pcm_open(be, be_substream); if (err < 0) { be->dpcm[stream].users--; if (be->dpcm[stream].users < 0) @@ -1780,7 +1857,7 @@ static int dpcm_fe_dai_startup(struct snd_pcm_substre= am *fe_substream) dev_dbg(fe->dev, "ASoC: open FE %s\n", fe->dai_link->name); =20 /* start the DAI frontend */ - ret =3D soc_pcm_open(fe_substream); + ret =3D __soc_pcm_open(fe, fe_substream); if (ret < 0) goto unwind; =20 @@ -1811,6 +1888,8 @@ static int dpcm_fe_dai_shutdown(struct snd_pcm_substr= eam *substream) struct snd_soc_pcm_runtime *fe =3D asoc_substream_to_rtd(substream); int stream =3D substream->stream; =20 + snd_soc_dpcm_mutex_assert_held(fe); + dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE); =20 /* shutdown the BEs */ @@ -1819,7 +1898,7 @@ static int dpcm_fe_dai_shutdown(struct snd_pcm_substr= eam *substream) dev_dbg(fe->dev, "ASoC: close FE %s\n", fe->dai_link->name); =20 /* now shutdown the frontend */ - soc_pcm_close(substream); + __soc_pcm_close(fe, substream); =20 /* run the stream stop event */ dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); @@ -1864,7 +1943,7 @@ void dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *= fe, int stream) dev_dbg(be->dev, "ASoC: hw_free BE %s\n", be->dai_link->name); =20 - soc_pcm_hw_free(be_substream); + __soc_pcm_hw_free(be, be_substream); =20 be->dpcm[stream].state =3D SND_SOC_DPCM_STATE_HW_FREE; } @@ -1875,13 +1954,13 @@ static int dpcm_fe_dai_hw_free(struct snd_pcm_subst= ream *substream) struct snd_soc_pcm_runtime *fe =3D asoc_substream_to_rtd(substream); int stream =3D substream->stream; =20 - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + snd_soc_dpcm_mutex_lock(fe); dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE); =20 dev_dbg(fe->dev, "ASoC: hw_free FE %s\n", fe->dai_link->name); =20 /* call hw_free on the frontend */ - soc_pcm_hw_free(substream); + soc_pcm_hw_clean(fe, substream, 0); =20 /* only hw_params backends that are either sinks or sources * to this frontend DAI */ @@ -1890,7 +1969,7 @@ static int dpcm_fe_dai_hw_free(struct snd_pcm_substre= am *substream) fe->dpcm[stream].state =3D SND_SOC_DPCM_STATE_HW_FREE; dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); =20 - mutex_unlock(&fe->card->mutex); + snd_soc_dpcm_mutex_unlock(fe); return 0; } =20 @@ -1934,7 +2013,7 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime = *fe, int stream) dev_dbg(be->dev, "ASoC: hw_params BE %s\n", be->dai_link->name); =20 - ret =3D soc_pcm_hw_params(be_substream, &dpcm->hw_params); + ret =3D __soc_pcm_hw_params(be, be_substream, &dpcm->hw_params); if (ret < 0) goto unwind; =20 @@ -1964,7 +2043,7 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime = *fe, int stream) (be->dpcm[stream].state !=3D SND_SOC_DPCM_STATE_STOP)) continue; =20 - soc_pcm_hw_free(be_substream); + __soc_pcm_hw_free(be, be_substream); } =20 return ret; @@ -1976,7 +2055,7 @@ static int dpcm_fe_dai_hw_params(struct snd_pcm_subst= ream *substream, struct snd_soc_pcm_runtime *fe =3D asoc_substream_to_rtd(substream); int ret, stream =3D substream->stream; =20 - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + snd_soc_dpcm_mutex_lock(fe); dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE); =20 memcpy(&fe->dpcm[stream].hw_params, params, @@ -1990,7 +2069,7 @@ static int dpcm_fe_dai_hw_params(struct snd_pcm_subst= ream *substream, params_channels(params), params_format(params)); =20 /* call hw_params on the frontend */ - ret =3D soc_pcm_hw_params(substream, params); + ret =3D __soc_pcm_hw_params(fe, substream, params); if (ret < 0) dpcm_be_dai_hw_free(fe, stream); else @@ -1998,7 +2077,7 @@ static int dpcm_fe_dai_hw_params(struct snd_pcm_subst= ream *substream, =20 out: dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); - mutex_unlock(&fe->card->mutex); + snd_soc_dpcm_mutex_unlock(fe); =20 if (ret < 0) dev_err(fe->dev, "ASoC: %s failed (%d)\n", __func__, ret); @@ -2269,7 +2348,7 @@ int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *f= e, int stream) dev_dbg(be->dev, "ASoC: prepare BE %s\n", be->dai_link->name); =20 - ret =3D soc_pcm_prepare(be_substream); + ret =3D __soc_pcm_prepare(be, be_substream); if (ret < 0) break; =20 @@ -2287,7 +2366,7 @@ static int dpcm_fe_dai_prepare(struct snd_pcm_substre= am *substream) struct snd_soc_pcm_runtime *fe =3D asoc_substream_to_rtd(substream); int stream =3D substream->stream, ret =3D 0; =20 - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + snd_soc_dpcm_mutex_lock(fe); =20 dev_dbg(fe->dev, "ASoC: prepare FE %s\n", fe->dai_link->name); =20 @@ -2306,7 +2385,7 @@ static int dpcm_fe_dai_prepare(struct snd_pcm_substre= am *substream) goto out; =20 /* call prepare on the frontend */ - ret =3D soc_pcm_prepare(substream); + ret =3D __soc_pcm_prepare(fe, substream); if (ret < 0) goto out; =20 @@ -2314,7 +2393,7 @@ static int dpcm_fe_dai_prepare(struct snd_pcm_substre= am *substream) =20 out: dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO); - mutex_unlock(&fe->card->mutex); + snd_soc_dpcm_mutex_unlock(fe); =20 if (ret < 0) dev_err(fe->dev, "ASoC: %s() failed (%d)\n", __func__, ret); @@ -2365,7 +2444,6 @@ static int dpcm_run_update_startup(struct snd_soc_pcm= _runtime *fe, int stream) struct snd_soc_dpcm *dpcm; enum snd_soc_dpcm_trigger trigger =3D fe->dai_link->trigger[stream]; int ret =3D 0; - unsigned long flags; =20 dev_dbg(fe->dev, "ASoC: runtime %s open on FE %s\n", stream ? "capture" : "playback", fe->dai_link->name); @@ -2434,7 +2512,6 @@ static int dpcm_run_update_startup(struct snd_soc_pcm= _runtime *fe, int stream) dpcm_be_dai_shutdown(fe, stream); disconnect: /* disconnect any pending BEs */ - spin_lock_irqsave(&fe->card->dpcm_lock, flags); for_each_dpcm_be(fe, stream, dpcm) { struct snd_soc_pcm_runtime *be =3D dpcm->be; =20 @@ -2446,7 +2523,6 @@ static int dpcm_run_update_startup(struct snd_soc_pcm= _runtime *fe, int stream) be->dpcm[stream].state =3D=3D SND_SOC_DPCM_STATE_NEW) dpcm->state =3D SND_SOC_DPCM_LINK_STATE_FREE; } - spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); =20 if (ret < 0) dev_err(fe->dev, "ASoC: %s() failed (%d)\n", __func__, ret); @@ -2521,7 +2597,7 @@ int snd_soc_dpcm_runtime_update(struct snd_soc_card *= card) struct snd_soc_pcm_runtime *fe; int ret =3D 0; =20 - mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass); /* shutdown all old paths first */ for_each_card_rtds(card, fe) { ret =3D soc_dpcm_fe_runtime_update(fe, 0); @@ -2537,7 +2613,7 @@ int snd_soc_dpcm_runtime_update(struct snd_soc_card *= card) } =20 out: - mutex_unlock(&card->mutex); + mutex_unlock(&card->pcm_mutex); return ret; } EXPORT_SYMBOL_GPL(snd_soc_dpcm_runtime_update); @@ -2548,6 +2624,8 @@ static void dpcm_fe_dai_cleanup(struct snd_pcm_substr= eam *fe_substream) struct snd_soc_dpcm *dpcm; int stream =3D fe_substream->stream; =20 + snd_soc_dpcm_mutex_assert_held(fe); + /* mark FE's links ready to prune */ for_each_dpcm_be(fe, stream, dpcm) dpcm->state =3D SND_SOC_DPCM_LINK_STATE_FREE; @@ -2562,12 +2640,12 @@ static int dpcm_fe_dai_close(struct snd_pcm_substre= am *fe_substream) struct snd_soc_pcm_runtime *fe =3D asoc_substream_to_rtd(fe_substream); int ret; =20 - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + snd_soc_dpcm_mutex_lock(fe); ret =3D dpcm_fe_dai_shutdown(fe_substream); =20 dpcm_fe_dai_cleanup(fe_substream); =20 - mutex_unlock(&fe->card->mutex); + snd_soc_dpcm_mutex_unlock(fe); return ret; } =20 @@ -2578,7 +2656,7 @@ static int dpcm_fe_dai_open(struct snd_pcm_substream = *fe_substream) int ret; int stream =3D fe_substream->stream; =20 - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + snd_soc_dpcm_mutex_lock(fe); fe->dpcm[stream].runtime =3D fe_substream->runtime; =20 ret =3D dpcm_path_get(fe, stream, &list); @@ -2595,7 +2673,7 @@ static int dpcm_fe_dai_open(struct snd_pcm_substream = *fe_substream) dpcm_clear_pending_state(fe, stream); dpcm_path_put(&list); open_end: - mutex_unlock(&fe->card->mutex); + snd_soc_dpcm_mutex_unlock(fe); return ret; } =20 @@ -2856,10 +2934,8 @@ static int snd_soc_dpcm_check_state(struct snd_soc_p= cm_runtime *fe, struct snd_soc_dpcm *dpcm; int state; int ret =3D 1; - unsigned long flags; int i; =20 - spin_lock_irqsave(&fe->card->dpcm_lock, flags); for_each_dpcm_fe(be, stream, dpcm) { =20 if (dpcm->fe =3D=3D fe) @@ -2873,7 +2949,6 @@ static int snd_soc_dpcm_check_state(struct snd_soc_pc= m_runtime *fe, } } } - spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); =20 /* it's safe to do this BE DAI */ return ret; --=20 2.40.1.521.gf1e218fcd8-goog