From: sashiko-bot@kernel.org
To: phucduc.bui@gmail.com
Cc: wsa+renesas@sang-engineering.com, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 09/11] ASoC: renesas: fsi: Add SPU clock support
Date: Tue, 09 Jun 2026 01:47:03 +0000 [thread overview]
Message-ID: <20260609014703.963871F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609013107.5995-10-phucduc.bui@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Low] Redundant device tree clock lookup and devres allocation for missing optional clock.
Pre-existing issues:
- [High] TOCTOU race in interrupt processing leading to NULL pointer dereference and unclocked register accesses.
--
commit 86706e81d382bcf14351e2e3d3945e492662cf7c
Author: bui duc phuc <phucduc.bui@gmail.com>
ASoC: renesas: fsi: Add SPU clock support
FSI register accesses on the r8a7740 require the SPU bus clock to be
enabled. Add support for acquiring and managing the SPU clock via the
device tree to ensure proper register access.
> diff --git a/sound/soc/renesas/fsi.c b/sound/soc/renesas/fsi.c
> index 13988c7dc926e..6c432c7235a41 100644
> --- a/sound/soc/renesas/fsi.c
> +++ b/sound/soc/renesas/fsi.c
[ ... ]
> @@ -1004,6 +1006,13 @@ static int fsi_clk_init(struct device *dev, struct fsi_priv *fsi)
> if (IS_ERR(clock->own))
> return dev_err_probe(dev, PTR_ERR(clock->own), "Can't get fck clock\n");
>
> + if (!master->clk_spu) {
> + master->clk_spu = devm_clk_get_optional(dev, "spu");
> + if (IS_ERR(master->clk_spu))
> + return dev_err_probe(dev, PTR_ERR(master->clk_spu),
> + "Can't get spu clock\n");
> + }
> +
[Severity: Low]
Does this code result in redundant device tree lookups and devres allocations
if the optional clock is missing?
Since fsi_clk_init() is called twice (once for FSIA and once for FSIB), if the
optional "spu" clock is not in the device tree, devm_clk_get_optional()
returns NULL.
The second time fsi_clk_init() is called, the (!master->clk_spu) check will
pass again, causing another devm_clk_get_optional() lookup and allocating a
second devres tracking node for a NULL clock pointer.
Could the clock acquisition be moved to a master-level initialization function
instead?
[Severity: High]
This is a pre-existing issue, but does a TOCTOU race condition exist between
interrupt processing and ALSA trigger stops that could lead to a NULL pointer
dereference or external abort?
In the interrupt handler path, functions like fsi_pio_transfer() and
fsi_count_fifo_err() check stream activity by calling fsi_stream_is_working():
sound/soc/renesas/fsi.c:fsi_pio_transfer() {
...
if (!fsi_stream_is_working(fsi, io))
return -EINVAL;
buf = fsi_pio_get_area(fsi, io);
...
}
However, fsi_stream_is_working() acquires master->lock, checks if
io->substream is valid, and immediately drops the lock before returning.
Concurrently, ALSA core can call fsi_dai_trigger(SNDRV_PCM_TRIGGER_STOP),
which invokes fsi_stream_quit(). This function takes master->lock, sets
io->substream to NULL, drops the lock, and disables the hardware clocks.
If CPU2 stops the stream right after CPU1's fsi_stream_is_working() drops the
lock, CPU1 can then call fsi_pio_get_area() and unconditionally dereference
io->substream->runtime, causing a fatal NULL pointer dereference.
Similarly, in fsi_count_fifo_err(), the same race window exists before
calling fsi_reg_read(fsi, DOFF_ST), which can trigger a synchronous external
abort if the clock has already been disabled by CPU2.
Could we hold the lock across the entire interrupt processing sequence, or
validate io->substream safely under the lock without dropping it prematurely?
> /* external clock */
> if (xck) {
> clock->xck = devm_clk_get_optional(dev, is_porta ? "xcka" : "xckb");
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260609013107.5995-1-phucduc.bui@gmail.com?part=9
next prev parent reply other threads:[~2026-06-09 1:47 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 1:30 [PATCH v5 00/11] ASoC: renesas: fsi: Fix system hang by adding SPU clock phucduc.bui
2026-06-09 1:30 ` [PATCH v5 01/11] ASoC: dt-bindings: renesas,fsi: add support multiple clocks phucduc.bui
2026-06-09 1:41 ` sashiko-bot
2026-06-09 6:54 ` Krzysztof Kozlowski
2026-06-09 8:11 ` Bui Duc Phuc
2026-06-09 8:17 ` Krzysztof Kozlowski
2026-06-09 8:42 ` Bui Duc Phuc
2026-06-09 8:54 ` Krzysztof Kozlowski
2026-06-09 9:05 ` Bui Duc Phuc
2026-06-09 1:30 ` [PATCH v5 02/11] ARM: dts: renesas: r8a7740: Add clocks for FSI phucduc.bui
2026-06-09 1:30 ` [PATCH v5 03/11] ASoC: renesas: fsi: Fix trigger stop ordering phucduc.bui
2026-06-09 1:43 ` sashiko-bot
2026-06-09 1:31 ` [PATCH v5 04/11] ASoC: renesas: fsi: Move fsi_stream_is_working() phucduc.bui
2026-06-09 1:44 ` sashiko-bot
2026-06-09 1:31 ` [PATCH v5 05/11] ASoC: renesas: fsi: Fix register access from in-flight IRQ after shutdown phucduc.bui
2026-06-09 1:59 ` sashiko-bot
2026-06-09 1:31 ` [PATCH v5 06/11] ASoC: renesas: fsi: Move fsi_clk_init() phucduc.bui
2026-06-09 1:46 ` sashiko-bot
2026-06-09 1:31 ` [PATCH v5 07/11] ASoC: renesas: fsi: Use devm_clk_get_optional() for optional clocks phucduc.bui
2026-06-09 1:31 ` [PATCH v5 08/11] ASoC: renesas: fsi: refactor clock initialization phucduc.bui
2026-06-09 1:43 ` sashiko-bot
2026-06-09 1:31 ` [PATCH v5 09/11] ASoC: renesas: fsi: Add SPU clock support phucduc.bui
2026-06-09 1:47 ` sashiko-bot [this message]
2026-06-09 1:31 ` [PATCH v5 10/11] ASoC: renesas: fsi: add fsi_clk_prepare/unprepare() phucduc.bui
2026-06-09 1:51 ` sashiko-bot
2026-06-09 1:31 ` [PATCH v5 11/11] ASoC: renesas: fsi: Add SPU clock control in hw_startup/shutdown phucduc.bui
2026-06-09 1:50 ` sashiko-bot
2026-06-09 6:57 ` [PATCH v5 00/11] ASoC: renesas: fsi: Fix system hang by adding SPU clock Kuninori Morimoto
2026-06-09 9:49 ` Bui Duc Phuc
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=20260609014703.963871F00893@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.