From: Valerio Setti <vsetti@baylibre.com>
To: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: Jerome Brunet <jbrunet@baylibre.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Kevin Hilman <khilman@baylibre.com>,
linux-sound@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ASoC: meson: gx-formatter: change stream lock from mutex to spinlock
Date: Tue, 10 Nov 2026 12:14:24 +0100 [thread overview]
Message-ID: <ca4c9e4e-80bf-435d-9f55-18f1a38c4472@baylibre.com> (raw)
In-Reply-To: <CAFBinCCV+rBnfSzY6LWfCU_D=BHmWi8CoZE0aza5BhvWXw3-8Q@mail.gmail.com>
On 11/8/26 10:01 PM, Martin Blumenstingl wrote:
> Hi Valerio,
>
> On Wed, Oct 21, 2026 at 11:52 PM Valerio Setti <vsetti@baylibre.com> wrote:
> [...]
>> @@ -85,9 +85,9 @@ static void gx_formatter_detach(struct gx_formatter *formatter)
>> if (!ts)
>> return;
>>
>> - mutex_lock(&ts->lock);
>> + spin_lock_irq(&ts->lock);
>> list_del(&formatter->list);
>> - mutex_unlock(&ts->lock);
>> + spin_unlock_irq(&ts->lock);
>>
>> gx_formatter_disable(formatter);
> The documentation below states that ->ops->disable is called with the lock held.
> gx_stream_stop() does call it with the locks held but
> gx_formatter_detach here doesn't.
>
> It doesn't seem to be problematic yet because aiu-formatter-i2s.c
> doesn't register a ->disable callback.
> Can you please still look into whether this is a problem?
>
> Also for a future patch (not this bugfix anymore) it would be great to
> have lockdep_assert_held validate that the lock has been taken (inside
> ->enable, ->disable and ->prepare).
>
> [...]
>> struct gx_formatter_ops {
>> struct gx_stream *(*get_stream)(struct snd_soc_dapm_widget *w);
>> + /*
>> + * Following functions are called with gx_stream->lock held and local
>> + * IRQs disabled so they must not sleep.
>> + */
>> void (*enable)(struct regmap *map);
>> void (*disable)(struct regmap *map);
>> int (*prepare)(struct regmap *map,
Hi Martin.
Oh, good catch indeed.
As you correctly pointed out that's not a problem today because the only
formatter currently present in the tree doesn't implement the
'disable()' callback. However the upcoming AUDIN support [1] will use
that callback, so the question might remain.
Technically in 'gx_formatter_detach' the formatter is first removed from
the formatter list (with spinlock held) before being disabled. This
means that other start/stop actions cannot be called on that formatter.
So even though this is ideally safe, I think that moving
'gx_formatter_disable' under the spinlock guard is better: all the
register access are MMIO (not sleeping) and then the behavior would be
symmetrical with 'gx_formatter_attach'.
Thanks also for the suggestion about 'lockdep_assert_held'.
I will send an updated version with these problem fixed.
Thanks for the review!
--
Valerio
prev parent reply other threads:[~2026-11-10 11:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 21:52 Valerio Setti
2026-11-08 21:01 ` Martin Blumenstingl
2026-11-10 11:14 ` Valerio Setti [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ca4c9e4e-80bf-435d-9f55-18f1a38c4472@baylibre.com \
--to=vsetti@baylibre.com \
--cc=broonie@kernel.org \
--cc=jbrunet@baylibre.com \
--cc=khilman@baylibre.com \
--cc=lgirdwood@gmail.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=neil.armstrong@linaro.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®