From: sashiko-bot@kernel.org
To: phucduc.bui@gmail.com
Cc: wsa+renesas@sang-engineering.com, devicetree@vger.kernel.org,
conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v6 10/11] ASoC: renesas: fsi: add fsi_clk_prepare/unprepare()
Date: Tue, 09 Jun 2026 12:08:42 +0000 [thread overview]
Message-ID: <20260609120842.9D0C31F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609113836.45079-11-phucduc.bui@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but fsi_clk_enable() incorrectly handles reference counting and returns -EINVAL for subsequent streams, breaking concurrent playback and capture (full-duplex).
- [High] This problem wasn't introduced by this patch, but fsi_clk_enable() triggers sleepable mutex acquisitions (clk_set_rate) from inside an atomic trigger context, potentially causing a deadlock or kernel panic.
- [High] This problem wasn't introduced by this patch, but opening or closing an audio stream unconditionally invalidates the shared clock state, breaking any other active stream on the same DAI.
--
commit 2ca0d4af70026409e881ce4021390b9ef2e6dfa9
Author: bui duc phuc <phucduc.bui@gmail.com>
ASoC: renesas: fsi: add fsi_clk_prepare/unprepare()
This commit adds fsi_clk_prepare() and fsi_clk_unprepare() helpers and calls
them from the startup and shutdown routines. This ensures clocks are prepared
from sleepable contexts.
> diff --git a/sound/soc/renesas/fsi.c b/sound/soc/renesas/fsi.c
> index 716ecf0401fe3..e26f39dfe0598 100644
> --- a/sound/soc/renesas/fsi.c
> +++ b/sound/soc/renesas/fsi.c
[ ... ]
> @@ -730,6 +730,54 @@ static int fsi_clk_is_valid(struct fsi_priv *fsi)
> fsi->clock.rate;
> }
>
> +static int fsi_clk_prepare(struct fsi_priv *fsi)
> +{
[ ... ]
> +static void fsi_clk_unprepare(struct fsi_priv *fsi)
> +{
[ ... ]
> + clk_unprepare(spu);
> +}
[Severity: High]
This isn't a bug introduced by this patch, but does fsi_clk_enable() correctly
handle reference counting for subsequent streams?
Looking at fsi_clk_enable() in the same file:
static int fsi_clk_enable(struct device *dev, struct fsi_priv *fsi)
{
struct fsi_clk *clock = &fsi->clock;
int ret = -EINVAL;
...
if (0 == clock->count) {
...
clock->count++;
}
return ret;
}
If clock->count is greater than 0 (such as during a second stream start for
concurrent playback and capture), the if block is skipped and the function
directly returns the initialized ret value of -EINVAL. Does this break
full-duplex audio by failing the ALSA trigger operation for the second stream?
Additionally, if the second stream fails to start but later triggers an
unbalanced shutdown during cleanup, fsi_clk_disable() underflows clock->count
via the post-decrement:
static int fsi_clk_disable(struct device *dev, struct fsi_priv *fsi)
{
...
if (1 == clock->count--) {
clk_disable(clock->xck);
...
}
...
}
Could this underflow cause further clock enablement to fail?
[Severity: High]
This is also a pre-existing issue, but does fsi_dai_trigger() call sleepable
functions while in an atomic context?
The ALSA ASoC trigger callback runs in an atomic context under a spinlock
since the DAI and PCM do not have the nonatomic flag set. However, the
call chain leads to clk_set_rate() which acquires the global CCF prepare_lock
mutex and can sleep:
fsi_dai_trigger()
fsi_hw_startup()
fsi_clk_enable()
clock->set_rate()
clk_set_rate()
Could this attempt to acquire a mutex while holding a spinlock result in a
scheduling while atomic panic or deadlock?
> static int fsi_clk_enable(struct device *dev,
> struct fsi_priv *fsi)
> {
[ ... ]
> @@ -1580,7 +1628,7 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
>
> fsi_clk_invalid(fsi);
>
> - return 0;
> + return fsi_clk_prepare(fsi);
> }
>
> static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
> @@ -1588,6 +1636,7 @@ static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
> {
> struct fsi_priv *fsi = fsi_get_priv(substream);
>
> + fsi_clk_unprepare(fsi);
> fsi_clk_invalid(fsi);
[Severity: High]
This is a pre-existing issue, but does calling fsi_clk_invalid()
unconditionally here and in fsi_dai_startup() break other active streams
on the same DAI?
Because playback and capture streams share a single fsi_clk structure,
if one stream is already running and a second stream is opened or closed,
fsi_clk_invalid() zeroes out fsi->clock.rate.
Later, when the running stream is closed via fsi_dai_trigger(),
fsi_hw_shutdown() will call fsi_clk_disable(). Because the rate was wiped,
fsi_clk_is_valid() evaluates to false:
static int fsi_clk_disable(struct device *dev, struct fsi_priv *fsi)
{
if (!fsi_clk_is_valid(fsi))
return -EINVAL;
...
}
This causes fsi_clk_disable() to return early without decrementing
clock->count or disabling the hardware clocks. Does this leak the clocks
indefinitely and break the reference count for future stream startups?
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260609113836.45079-1-phucduc.bui@gmail.com?part=10
next prev parent reply other threads:[~2026-06-09 12:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 11:38 [PATCH v6 00/11] ASoC: renesas: fsi: Fix system hang by adding SPU clock phucduc.bui
2026-06-09 11:38 ` [PATCH v6 01/11] ASoC: dt-bindings: renesas,fsi: add support multiple clocks phucduc.bui
2026-06-09 11:50 ` sashiko-bot
2026-06-09 11:38 ` [PATCH v6 02/11] ARM: dts: renesas: r8a7740: Add clocks for FSI phucduc.bui
2026-06-09 11:38 ` [PATCH v6 03/11] ASoC: renesas: fsi: Fix trigger stop ordering phucduc.bui
2026-06-09 12:01 ` sashiko-bot
2026-06-09 11:38 ` [PATCH v6 04/11] ASoC: renesas: fsi: Move fsi_stream_is_working() phucduc.bui
2026-06-09 11:51 ` sashiko-bot
2026-06-09 11:38 ` [PATCH v6 05/11] ASoC: renesas: fsi: Fix register access from in-flight IRQ after shutdown phucduc.bui
2026-06-09 11:59 ` sashiko-bot
2026-06-09 11:38 ` [PATCH v6 06/11] ASoC: renesas: fsi: Move fsi_clk_init() phucduc.bui
2026-06-09 11:55 ` sashiko-bot
2026-06-09 11:38 ` [PATCH v6 07/11] ASoC: renesas: fsi: Use devm_clk_get_optional() for optional clocks phucduc.bui
2026-06-09 11:56 ` sashiko-bot
2026-06-09 11:38 ` [PATCH v6 08/11] ASoC: renesas: fsi: refactor clock initialization phucduc.bui
2026-06-09 12:06 ` sashiko-bot
2026-06-09 11:38 ` [PATCH v6 09/11] ASoC: renesas: fsi: Add SPU clock support phucduc.bui
2026-06-09 11:38 ` [PATCH v6 10/11] ASoC: renesas: fsi: add fsi_clk_prepare/unprepare() phucduc.bui
2026-06-09 12:08 ` sashiko-bot [this message]
2026-06-09 11:38 ` [PATCH v6 11/11] ASoC: renesas: fsi: Add SPU clock control in hw_startup/shutdown phucduc.bui
2026-06-09 12:10 ` sashiko-bot
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=20260609120842.9D0C31F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=phucduc.bui@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wsa+renesas@sang-engineering.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