Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: phucduc.bui@gmail.com
Cc: conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org,
	wsa+renesas@sang-engineering.com, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 03/10] ASoC: renesas: fsi: Fix trigger stop ordering
Date: Mon, 11 May 2026 22:44:35 +0000	[thread overview]
Message-ID: <20260511224436.A0B19C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260510084303.122426-4-phucduc.bui@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] TOCTOU race and lack of synchronization in stream stopping leads to NULL pointer dereference.
- [High] Teardown asymmetry in `fsi_remove` leads to use-after-free and NULL pointer dereference.
- [High] Lockless read-modify-write on shared FSI port registers causes hardware corruption.
- [High] Lockless modifications to shared `clock->count` cause reference count corruption.
--

commit 7ce4e3deeaefe8e811044e7b0472a2e9a2ae1d64
Author: bui duc phuc <phucduc.bui@gmail.com>

ASoC: renesas: fsi: Fix trigger stop ordering

This commit reorders calls in the stop trigger to execute fsi_stream_stop()
before fsi_hw_shutdown(). It ensures register accesses complete before the
clock is disabled to prevent a system hang.

> diff --git a/sound/soc/renesas/fsi.c b/sound/soc/renesas/fsi.c
> index 8cbd7acc26f49..94ab2e4908108 100644
> --- a/sound/soc/renesas/fsi.c
> +++ b/sound/soc/renesas/fsi.c
> @@ -1586,9 +1586,9 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
>  			ret = fsi_stream_transfer(io);
>  		break;
>  	case SNDRV_PCM_TRIGGER_STOP:

Playback and capture substreams on the same FSI port share port-level
configuration registers like CKG1, CKG2, and OUT_SEL.

Since the ALSA core serializes triggers at the substream level using
the self_group.lock, playback and capture triggers for the same DAI
can execute concurrently on different CPUs.

Does fsi_hw_startup() perform lockless read-modify-write operations on these
shared registers, and can this lack of exclusion lead to lost writes and
corrupted hardware state?

> +		fsi_stream_stop(fsi, io);

During a stream stop, fsi_stream_stop() disables DMA via
dmaengine_terminate_all() and masks device interrupts, but it does not appear
to wait for in-flight DMA callbacks or IRQ handlers to finish.

Concurrently, an executing IRQ handler calling fsi_pio_transfer() will
temporarily take master->lock in fsi_stream_is_working(), drop it, and then
locklessly access io->substream->runtime inside fsi_pio_get_area().

Similarly, an asynchronous fsi_dma_complete() callback unconditionally
dereferences io->substream in fsi_pointer_update().

Since there is no dmaengine_terminate_sync() or synchronize_irq(), could
fsi_stream_quit() race with these callbacks and clear io->substream,
resulting in a NULL pointer dereference?

The driver uses managed resources during fsi_probe(), meaning the IRQ handler
and ALSA component are unregistered after fsi_remove() returns. However,
fsi_remove() explicitly tears down the DMA streams via fsi_stream_remove(),
which calls dma_release_channel(io->chan) and sets io->chan to NULL.

Because the ALSA component is still fully registered and active while
fsi_remove() completes, userspace can still trigger ALSA operations.

If a STOP trigger occurs during this window, would calling
dmaengine_terminate_all(io->chan) here cause a NULL pointer dereference?

>  		if (!ret)
>  			ret = fsi_hw_shutdown(fsi, dai->dev);

The shared clock state for an FSI port is tracked using clock->count inside
fsi_priv.

Since playback and capture triggers for the same port can execute
concurrently on different CPUs, do fsi_clk_enable() and fsi_clk_disable()
manually modify this counter without holding any lock?

Could concurrent updates to clock->count corrupt the counter, potentially
leaving the peripheral clocks enabled permanently or disabling them while a
stream is still active?

> -		fsi_stream_stop(fsi, io);
>  		fsi_stream_quit(fsi, io);
>  		break;
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260510084303.122426-1-phucduc.bui@gmail.com?part=3

  reply	other threads:[~2026-05-11 22:44 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-10  8:42 [PATCH v3 00/10] ASoC: renesas: fsi: Fix system hang by adding SPU clock phucduc.bui
2026-05-10  8:42 ` [PATCH v3 01/10] ASoC: dt-bindings: renesas,fsi: add support multiple clocks phucduc.bui
2026-05-11  7:30   ` Geert Uytterhoeven
2026-05-11 10:25     ` Bui Duc Phuc
2026-05-11 20:45   ` sashiko-bot
2026-05-12  6:42     ` Bui Duc Phuc
2026-05-10  8:42 ` [PATCH v3 02/10] arm: dts: renesas: r8a7740: Add clocks for FSI phucduc.bui
2026-05-11 22:03   ` sashiko-bot
2026-05-10  8:42 ` [PATCH v3 03/10] ASoC: renesas: fsi: Fix trigger stop ordering phucduc.bui
2026-05-11 22:44   ` sashiko-bot [this message]
2026-05-10  8:42 ` [PATCH v3 04/10] ASoC: renesas: fsi: Fix register access from in-flight IRQ after shutdown phucduc.bui
2026-05-11  1:52   ` Kuninori Morimoto
2026-05-11 23:22   ` sashiko-bot
2026-05-10  8:42 ` [PATCH v3 05/10] ASoC: renesas: fsi: Move fsi_clk_init() phucduc.bui
2026-05-10  8:42 ` [PATCH v3 06/10] ASoC: renesas: fsi: Add shared SPU clock support phucduc.bui
2026-05-11  1:56   ` Kuninori Morimoto
2026-05-12  3:09     ` Bui Duc Phuc
2026-05-10  8:43 ` [PATCH v3 07/10] ASoC: renesas: fsi: refactor clock initialization phucduc.bui
2026-05-10 12:30   ` Mark Brown
2026-05-11  1:59   ` Kuninori Morimoto
2026-05-11 10:21     ` Bui Duc Phuc
2026-05-11 23:47   ` sashiko-bot
2026-05-10  8:43 ` [PATCH v3 08/10] ASoC: renesas: fsi: add fsi_clk_prepare/unprepare() phucduc.bui
2026-05-11  2:03   ` Kuninori Morimoto
2026-05-11 23:44   ` sashiko-bot
2026-05-10  8:43 ` [PATCH v3 09/10] ASoC: renesas: fsi: Use clock prepare handling in startup/shutdown phucduc.bui
2026-05-11  2:04   ` Kuninori Morimoto
2026-05-11 10:22     ` Bui Duc Phuc
2026-05-12  0:09   ` sashiko-bot
2026-05-10  8:43 ` [PATCH v3 10/10] ASoC: renesas: fsi: Add SPU clock control in hw_startup/shutdown phucduc.bui
2026-05-11 23:58   ` 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=20260511224436.A0B19C2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=phucduc.bui@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko@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