From: sashiko-bot@kernel.org
To: "Valerio Setti" <vsetti@baylibre.com>
Cc: robh@kernel.org, neil.armstrong@linaro.org,
linux-amlogic@lists.infradead.org, conor+dt@kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v4 4/7] ASoC: meson: add AUDIN driver
Date: Thu, 01 Oct 2026 16:23:12 +0000 [thread overview]
Message-ID: <20261001162313.4333D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261001-audin-v4-4-2476646118b5@baylibre.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Race condition in PAUSE_RELEASE corrupts hrtimer state
- [High] Use-after-free of hrtimer data during device unbind
- [Medium] Hardware state loss in AUDIN FIFO during system suspend
--
commit 3526087ac379aa85de8aca3b698b812a10b5da4e
Author: Valerio Setti <vsetti@baylibre.com>
ASoC: meson: add AUDIN driver
AUDIN provides audio input support to the Amlogic GX based platforms
(GXBB/GXL). It is the counterpart of AIU for capture and instantiates each of
the FIFOs as a component DAI.
> diff --git a/sound/soc/meson/audin-fifo.c b/sound/soc/meson/audin-fifo.c
> new file mode 100644
> index 0000000000000..cb59bb267e845
> --- /dev/null
> +++ b/sound/soc/meson/audin-fifo.c
[ ... ]
> +static int audin_fifo_dai_trigger(struct snd_pcm_substream *substream, int cmd,
> + struct snd_soc_dai *dai)
> +{
> + struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai);
> + struct snd_soc_component *component = dai->component;
> +
> + switch (cmd) {
> + case SNDRV_PCM_TRIGGER_START:
> + case SNDRV_PCM_TRIGGER_RESUME:
> + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
> + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL,
> + AUDIN_FIFO_CTRL_EN,
> + AUDIN_FIFO_CTRL_EN);
> + WRITE_ONCE(data->running, true);
> + hrtimer_start(&data->polling_timer,
> + audin_fifo_bytes_to_ns(data, data->period_bytes),
> + HRTIMER_MODE_REL_SOFT);
[Severity: High]
Does this blindly re-enqueue the timer without synchronizing with a potentially
running callback?
If a user rapidly toggles SNDRV_PCM_IOCTL_PAUSE, PAUSE_PUSH uses a
non-blocking hrtimer_try_to_cancel(). If the timer is running and skips
snd_pcm_period_elapsed() (e.g. because delta < period_bytes), it won't take
the PCM stream lock and will execute hrtimer_forward_now() concurrently with
PAUSE_RELEASE.
PAUSE_RELEASE then blindly calls hrtimer_start(), which enqueues the timer.
When the running callback in audin_fifo_timer_cb() reads running=true, it
returns HRTIMER_RESTART, resulting in a double enqueue of the same timer
which can corrupt the hrtimer rbtree.
> + break;
> + case SNDRV_PCM_TRIGGER_SUSPEND:
> + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
> + case SNDRV_PCM_TRIGGER_STOP:
> + WRITE_ONCE(data->running, false);
> + /*
> + * PCM stream lock is held here. If the timer callback is running
> + * (i.e. it cannot be stopped) there is also hrtimer_cancel()
> + * in hw_free().
> + */
> + hrtimer_try_to_cancel(&data->polling_timer);
> + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL,
> + AUDIN_FIFO_CTRL_EN, 0);
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
[ ... ]
> +static int audin_fifo_dai_remove(struct snd_soc_dai *dai)
> +{
> + kfree(snd_soc_dai_dma_data_get_capture(dai));
> +
> + return 0;
> +}
[Severity: High]
Does this free the DAI data without waiting for the polling timer to finish?
If the driver is unbound while an audio stream is open, the ALSA core triggers
a stream stop which uses a non-blocking hrtimer_try_to_cancel(). If the timer
callback is running concurrently, it will write to this freed memory.
[ ... ]
> +int audin_fifo_sync_stop(struct snd_soc_component *component, struct snd_pcm_substream *substream)
> +{
> + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
> + struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0);
> + struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai);
> +
> + hrtimer_cancel(&data->polling_timer);
[Severity: High]
Could this deferred callback access the freed data pointer?
If the driver was unbound and audin_fifo_dai_remove() freed the DAI data,
when the file descriptor is eventually closed this deferred sync_stop callback
will access the freed data pointer to cancel the timer.
> + WRITE_ONCE(data->running, false);
> +
> + return 0;
> +}
> diff --git a/sound/soc/meson/audin.c b/sound/soc/meson/audin.c
> new file mode 100644
> index 0000000000000..808e7d4fd31a2
> --- /dev/null
> +++ b/sound/soc/meson/audin.c
[ ... ]
> +static const struct regmap_config audin_regmap_cfg = {
> + .reg_bits = 32,
> + .val_bits = 32,
> + .reg_stride = 4,
> + .max_register = 0x148,
> +};
[Severity: Medium]
Will hardware state like the channel mask and endianness be lost across
system suspend and resume cycles?
ALSA calls the driver's prepare() callback to recover a suspended stream,
but not hw_params(). Because this regmap lacks a cache configuration, it
cannot automatically restore the register state configured during hw_params()
when the system resumes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261001-audin-v4-0-2476646118b5@baylibre.com?part=4
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Valerio Setti" <vsetti@baylibre.com>
Cc: robh@kernel.org, neil.armstrong@linaro.org,
linux-amlogic@lists.infradead.org, conor+dt@kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v4 4/7] ASoC: meson: add AUDIN driver
Date: Thu, 01 Oct 2026 16:23:12 +0000 [thread overview]
Message-ID: <20261001162313.4333D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261001-audin-v4-4-2476646118b5@baylibre.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Race condition in PAUSE_RELEASE corrupts hrtimer state
- [High] Use-after-free of hrtimer data during device unbind
- [Medium] Hardware state loss in AUDIN FIFO during system suspend
--
commit 3526087ac379aa85de8aca3b698b812a10b5da4e
Author: Valerio Setti <vsetti@baylibre.com>
ASoC: meson: add AUDIN driver
AUDIN provides audio input support to the Amlogic GX based platforms
(GXBB/GXL). It is the counterpart of AIU for capture and instantiates each of
the FIFOs as a component DAI.
> diff --git a/sound/soc/meson/audin-fifo.c b/sound/soc/meson/audin-fifo.c
> new file mode 100644
> index 0000000000000..cb59bb267e845
> --- /dev/null
> +++ b/sound/soc/meson/audin-fifo.c
[ ... ]
> +static int audin_fifo_dai_trigger(struct snd_pcm_substream *substream, int cmd,
> + struct snd_soc_dai *dai)
> +{
> + struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai);
> + struct snd_soc_component *component = dai->component;
> +
> + switch (cmd) {
> + case SNDRV_PCM_TRIGGER_START:
> + case SNDRV_PCM_TRIGGER_RESUME:
> + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
> + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL,
> + AUDIN_FIFO_CTRL_EN,
> + AUDIN_FIFO_CTRL_EN);
> + WRITE_ONCE(data->running, true);
> + hrtimer_start(&data->polling_timer,
> + audin_fifo_bytes_to_ns(data, data->period_bytes),
> + HRTIMER_MODE_REL_SOFT);
[Severity: High]
Does this blindly re-enqueue the timer without synchronizing with a potentially
running callback?
If a user rapidly toggles SNDRV_PCM_IOCTL_PAUSE, PAUSE_PUSH uses a
non-blocking hrtimer_try_to_cancel(). If the timer is running and skips
snd_pcm_period_elapsed() (e.g. because delta < period_bytes), it won't take
the PCM stream lock and will execute hrtimer_forward_now() concurrently with
PAUSE_RELEASE.
PAUSE_RELEASE then blindly calls hrtimer_start(), which enqueues the timer.
When the running callback in audin_fifo_timer_cb() reads running=true, it
returns HRTIMER_RESTART, resulting in a double enqueue of the same timer
which can corrupt the hrtimer rbtree.
> + break;
> + case SNDRV_PCM_TRIGGER_SUSPEND:
> + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
> + case SNDRV_PCM_TRIGGER_STOP:
> + WRITE_ONCE(data->running, false);
> + /*
> + * PCM stream lock is held here. If the timer callback is running
> + * (i.e. it cannot be stopped) there is also hrtimer_cancel()
> + * in hw_free().
> + */
> + hrtimer_try_to_cancel(&data->polling_timer);
> + snd_soc_component_update_bits(component, dai->driver->base + AUDIN_FIFO_CTRL,
> + AUDIN_FIFO_CTRL_EN, 0);
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
[ ... ]
> +static int audin_fifo_dai_remove(struct snd_soc_dai *dai)
> +{
> + kfree(snd_soc_dai_dma_data_get_capture(dai));
> +
> + return 0;
> +}
[Severity: High]
Does this free the DAI data without waiting for the polling timer to finish?
If the driver is unbound while an audio stream is open, the ALSA core triggers
a stream stop which uses a non-blocking hrtimer_try_to_cancel(). If the timer
callback is running concurrently, it will write to this freed memory.
[ ... ]
> +int audin_fifo_sync_stop(struct snd_soc_component *component, struct snd_pcm_substream *substream)
> +{
> + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
> + struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0);
> + struct audin_fifo_dai_data *data = snd_soc_dai_dma_data_get_capture(dai);
> +
> + hrtimer_cancel(&data->polling_timer);
[Severity: High]
Could this deferred callback access the freed data pointer?
If the driver was unbound and audin_fifo_dai_remove() freed the DAI data,
when the file descriptor is eventually closed this deferred sync_stop callback
will access the freed data pointer to cancel the timer.
> + WRITE_ONCE(data->running, false);
> +
> + return 0;
> +}
> diff --git a/sound/soc/meson/audin.c b/sound/soc/meson/audin.c
> new file mode 100644
> index 0000000000000..808e7d4fd31a2
> --- /dev/null
> +++ b/sound/soc/meson/audin.c
[ ... ]
> +static const struct regmap_config audin_regmap_cfg = {
> + .reg_bits = 32,
> + .val_bits = 32,
> + .reg_stride = 4,
> + .max_register = 0x148,
> +};
[Severity: Medium]
Will hardware state like the channel mask and endianness be lost across
system suspend and resume cycles?
ALSA calls the driver's prepare() callback to recover a suspended stream,
but not hw_params(). Because this regmap lacks a cache configuration, it
cannot automatically restore the register state configured during hw_params()
when the system resumes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261001-audin-v4-0-2476646118b5@baylibre.com?part=4
next prev parent reply other threads:[~2026-10-01 16:23 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 16:06 [PATCH v4 0/7] ASoC: meson: gx: add base support for I2S audio input Valerio Setti
2026-10-01 16:06 ` Valerio Setti
2026-10-01 16:06 ` [PATCH v4 1/7] ASoC: dt-bindings: add amlogic,gxbb-audin Valerio Setti
2026-10-01 16:06 ` Valerio Setti
2026-10-02 9:42 ` Krzysztof Kozlowski
2026-10-02 9:42 ` Krzysztof Kozlowski
2026-10-01 16:06 ` [PATCH v4 2/7] ASoC: meson: build gx-formatter as a separate module Valerio Setti
2026-10-01 16:06 ` Valerio Setti
2026-10-07 8:34 ` Jerome Brunet
2026-10-07 8:34 ` Jerome Brunet
2026-10-01 16:06 ` [PATCH v4 3/7] ASoC: meson: aiu-encoder-i2s: ensure clk divider gets disabled in hw_free Valerio Setti
2026-10-01 16:06 ` Valerio Setti
2026-10-07 8:44 ` Jerome Brunet
2026-10-07 8:44 ` Jerome Brunet
2026-10-12 15:14 ` Valerio Setti
2026-10-12 15:14 ` Valerio Setti
2026-10-01 16:06 ` [PATCH v4 4/7] ASoC: meson: add AUDIN driver Valerio Setti
2026-10-01 16:06 ` Valerio Setti
2026-10-01 16:23 ` sashiko-bot [this message]
2026-10-01 16:23 ` sashiko-bot
2026-10-07 8:33 ` Jerome Brunet
2026-10-07 8:33 ` Jerome Brunet
2026-10-12 15:26 ` Valerio Setti
2026-10-12 15:26 ` Valerio Setti
2026-10-01 16:06 ` [PATCH v4 5/7] ASoC: meson: aiu: add I2S Capture DAI Valerio Setti
2026-10-01 16:06 ` Valerio Setti
2026-10-07 8:48 ` Jerome Brunet
2026-10-07 8:48 ` Jerome Brunet
2026-10-01 16:06 ` [PATCH v4 6/7] ASoC: meson: gx-card: add support for audin FIFO Valerio Setti
2026-10-01 16:06 ` Valerio Setti
2026-10-07 8:50 ` Jerome Brunet
2026-10-07 8:50 ` Jerome Brunet
2026-10-01 16:06 ` [PATCH v4 7/7] arm64: dts: amlogic: gx: add AUDIN node Valerio Setti
2026-10-01 16:06 ` Valerio Setti
2026-10-07 8:54 ` Jerome Brunet
2026-10-07 8:54 ` Jerome Brunet
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=20261001162313.4333D1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vsetti@baylibre.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.