From: sashiko-bot@kernel.org
To: "Olivier Moysan" <olivier.moysan@foss.st.com>
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-sound@vger.kernel.org, robh@kernel.org,
conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v2 10/11] iio: adc: stm32-mdf: add dmic audio filter support
Date: Wed, 18 Nov 2026 16:06:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-221421@kernel.org> (raw)
In-Reply-To: <20261118-upstream_mdf_v2-v2-10-7939d3c3720a@foss.st.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] iio: adc: stm32-mdf: race updating cb and cb_priv in
stm32_mdf_get_buff_cb()
- [Medium] iio: adc: stm32-mdf: out-of-bounds or uninitialized channel
in stm32_mdf_audio_init()
- [Medium] iio: adc: stm32-mdf: unlocked freq reset in
stm32_mdf_adc_write_raw()
- [Medium] iio: stm32-mdf: bad mask and bypass in
stm32_mdf_adc_apply_filters_config()
- [Low] iio: adc: stm32-mdf: inaccurate kernel-doc Return for
stm32_mdf_get_sub_channels_nb()
--
commit dd4cd2a4f3dd0be22589f1468dca26c3807bd280
Author: Olivier Moysan <olivier.moysan@foss.st.com>
iio: adc: stm32-mdf: add dmic audio filter support
This commit extends the STM32 MDF filter driver to support digital
microphone audio filters and adds callback and sub-channel helpers for
audio consumers.
> diff --git a/drivers/iio/adc/stm32-mdf-adc.c b/drivers/iio/adc/stm32-mdf-adc.c
> index 97099b4adffc6..27c47bef71a42 100644
> --- a/drivers/iio/adc/stm32-mdf-adc.c
> +++ b/drivers/iio/adc/stm32-mdf-adc.c
[ ... ]
> @@ -1128,6 +1129,42 @@ static const struct iio_buffer_setup_ops stm32_mdf_buffer_setup_ops = {
> .predisable = &stm32_mdf_adc_predisable,
> };
>
> +/**
> + * stm32_mdf_get_sub_channels_nb() - Get the number of MDF sub-channels
> + * @indio_dev: MDF IIO device
> + *
> + * Return: 0 on success, or a negative error code on failure.
> + */
[Severity: Low]
The Return description in the kernel-doc says this returns 0 on success or
a negative error code on failure, whereas stm32_mdf_get_sub_channels_nb()
returns an unsigned int sub-channel count (nb_interleave or 1).
> +unsigned int stm32_mdf_get_sub_channels_nb(struct iio_dev *indio_dev)
> +{
> + struct stm32_mdf_adc *adc = iio_priv(indio_dev);
> +
> + if (MDF_IS_FILTER0(adc) && adc->mdf->nb_interleave)
> + return adc->mdf->nb_interleave;
> +
> + return 1;
> +}
> +EXPORT_SYMBOL_GPL(stm32_mdf_get_sub_channels_nb);
[Severity: Medium]
Does stm32_mdf_adc_apply_filters_config() misconfigure MDF_DFLTCICR_REG and
drop rsflt_bypass on secondary interleaved filters?
drivers/iio/adc/stm32-mdf-adc.c:stm32_mdf_adc_apply_filters_config() {
if (MDF_IS_FILTER0(adc) && adc->mdf->nb_interleave) {
list_for_each_entry(adc_inter, &adc->mdf->filter_list, entry) {
if (MDF_IS_INTERLEAVED_FILT_NOT_0(adc_inter)) {
adc_inter->datsrc = adc->datsrc;
adc_inter->cicmode = adc->cicmode;
adc_inter->decim_cic = adc->decim_cic;
adc_inter->nbdis = adc->nbdis;
adc_inter->hpf_cutoff = adc->hpf_cutoff;
stm32_mdf_adc_apply_filters_config(adc_inter, scale);
cnt++;
}
}
...
/* Configure CICR */
msk = MDF_SITFCR_SCKSRC_MASK | MDF_DFLTCICR_CICMOD_MASK |
MDF_DFLTCICR_MCICD_MASK | MDF_DFLTCICR_SCALE_MASK;
val = FIELD_PREP(MDF_SITFCR_SCKSRC_MASK, adc->datsrc) |
FIELD_PREP(MDF_DFLTCICR_CICMOD_MASK, adc->cicmode) |
FIELD_PREP(MDF_DFLTCICR_MCICD_MASK, adc->decim_cic - 1) |
FIELD_PREP(MDF_DFLTCICR_SCALE_MASK, scale);
ret = regmap_update_bits(adc->regmap, MDF_DFLTCICR_REG, msk, val);
}
When programming MDF_DFLTCICR_REG, msk and val use MDF_SITFCR_SCKSRC_MASK
(GENMASK(2, 1)) instead of MDF_DFLTCICR_DATSRC_MASK (GENMASK(1, 0)), which
shifts adc->datsrc into bits [2:1] and leaves bit 0 untouched. In
addition, the interleaved filter loop does not copy adc->rsflt_bypass to
adc_inter->rsflt_bypass, leaving the reshape filter enabled on secondary
interleaved filters when filter 0 has st,rs-filter-bypass set.
[ ... ]
> @@ -1474,6 +1514,13 @@ static int stm32_mdf_adc_read_label(struct iio_dev *indio_dev, const struct iio_
> return sysfs_emit(label, "%s\n", name);
> }
>
> +static const struct iio_info stm32_mdf_info_audio = {
> + .hwfifo_set_watermark = stm32_mdf_set_watermark,
> + .write_raw = stm32_mdf_adc_write_raw,
> + .read_raw = stm32_mdf_adc_read_raw,
> + .read_label = stm32_mdf_adc_read_label,
> +};
[Severity: Medium]
Does stm32_mdf_adc_write_raw() reset adc->requested_sample_freq outside
the direct-mode lock on error?
drivers/iio/adc/stm32-mdf-adc.c:stm32_mdf_adc_write_raw() {
...
{
IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
if (IIO_DEV_ACQUIRE_FAILED(claim))
return -EBUSY;
/* Set requested_sample_freq right now, as used by mdf_adc_set_samp_freq() */
adc->requested_sample_freq = val;
if (adc->dev_data->type == STM32_MDF_IIO) {
ret = stm32_mdf_core_lock_kclk_rate(adc->mdf);
if (!ret) {
ret = mdf_adc_set_samp_freq(indio_dev);
stm32_mdf_core_unlock_kclk_rate(adc->mdf);
}
}
}
if (ret)
adc->requested_sample_freq = 0;
...
}
The IIO_DEV_ACQUIRE_DIRECT_MODE() guard releases direct mode at the end of
the inner block, before adc->requested_sample_freq is cleared. If
stm32_mdf_core_lock_kclk_rate() or mdf_adc_set_samp_freq() fails, a
concurrent direct-mode writer or buffer enable can observe the failed
frequency or have its own valid update overwritten by 0.
> @@ -1530,6 +1577,38 @@ static irqreturn_t stm32_mdf_irq(int irq, void *arg)
> return IRQ_HANDLED;
> }
>
> +static int stm32_mdf_audio_init(struct device *dev, struct iio_dev *indio_dev)
> +{
> + struct stm32_mdf_adc *adc = iio_priv(indio_dev);
> + struct iio_chan_spec *ch;
> + int ret;
> +
> + ch = devm_kzalloc(&indio_dev->dev, sizeof(*ch), GFP_KERNEL);
> + if (!ch)
> + return -ENOMEM;
> +
> + adc->channels = devm_kzalloc(&indio_dev->dev, sizeof(*adc->channels), GFP_KERNEL);
> + if (!adc->channels)
> + return -ENOMEM;
> +
> + ret = stm32_mdf_adc_chan_init(indio_dev, ch);
> + if (ret < 0)
> + return dev_err_probe(dev, ret, "Channels init failed\n");
> +
> + indio_dev->num_channels = 1;
> + indio_dev->channels = ch;
[Severity: Medium]
Can stm32_mdf_adc_chan_init() write past ch and adc->channels or leave them
uninitialized here?
stm32_mdf_audio_init() allocates a single element for ch and adc->channels,
but stm32_mdf_adc_chan_init() loops over every child node without a
compatible property and indexes channels[chan_idx] and
adc->channels[chan_idx] without checking the count. If a dmic node has
more than one channel child node, stm32_mdf_adc_chan_init_one() writes out
of bounds on both allocations. If there are no channel child nodes (such
as on a secondary interleaved filter), stm32_mdf_adc_chan_init() returns 0,
leaving indio_dev->num_channels set to 1 with ch[0] and adc->channels[0]
uninitialized.
[ ... ]
> @@ -1599,11 +1678,77 @@ static const struct stm32_mdf_dev_data stm32h7_mdf_adc_data = {
> .init = stm32_mdf_adc_init,
> };
>
> +static const struct stm32_mdf_dev_data stm32_mdf_audio_data = {
> + .type = STM32_MDF_AUDIO,
> + .init = stm32_mdf_audio_init,
> +};
> +
> +/**
> + * stm32_mdf_get_buff_cb() - register a callback that will be called when
> + * DMA transfer period is achieved.
> + *
> + * @iio_dev: Handle to IIO device.
> + * @cb: Pointer to callback function:
> + * - data: pointer to data buffer
> + * - size: size in byte of the data buffer
> + * - private: pointer to consumer private structure.
> + * @private: Pointer to consumer private structure.
> + *
> + * Return: 0 on success, or a negative error code on failure.
> + */
> +int stm32_mdf_get_buff_cb(struct iio_dev *iio_dev,
> + int (*cb)(const void *data, size_t size, void *private), void *private)
> +{
> + struct stm32_mdf_adc *adc;
> +
> + if (!iio_dev)
> + return -EINVAL;
> + adc = iio_priv(iio_dev);
> +
> + if (!adc)
> + return -EINVAL;
> +
> + adc->cb = cb;
> + adc->cb_priv = private;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(stm32_mdf_get_buff_cb);
> +
> +/**
> + * stm32_mdf_release_buff_cb() - Unregister the buffer callback
> + *
> + * @iio_dev: Handle to IIO device.
> + *
> + * Return: 0 on success, or a negative error code on failure.
> + */
> +int stm32_mdf_release_buff_cb(struct iio_dev *iio_dev)
> +{
> + struct stm32_mdf_adc *adc;
> +
> + if (!iio_dev)
> + return -EINVAL;
> + adc = iio_priv(iio_dev);
> +
> + if (!adc)
> + return -EINVAL;
> +
> + adc->cb = NULL;
> + adc->cb_priv = NULL;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(stm32_mdf_release_buff_cb);
[Severity: High]
Can stm32_mdf_get_buff_cb() and stm32_mdf_release_buff_cb() race with
stm32_mdf_adc_dma_buffer_done() and cause a NULL pointer dereference?
In the ASoC consumer driver, iio_channel_start_all_cb() is called during
DAI prepare, which runs stm32_mdf_adc_postenable() and starts cyclic DMA
before PCM trigger start, keeping it running across trigger stop. As a
result, the DMA completion callback stm32_mdf_adc_dma_buffer_done() is
already running when stm32_mdf_get_buff_cb() and
stm32_mdf_release_buff_cb() update adc->cb and adc->cb_priv without locking
or ordering:
CPU0 CPU1
stm32_mdf_get_buff_cb()
adc->cb = cb;
stm32_mdf_adc_dma_buffer_done()
if (adc->cb)
adc->cb(..., adc->cb_priv);
<-- cb_priv is still NULL
adc->cb_priv = private;
Similarly, stm32_mdf_release_buff_cb() clears adc->cb and adc->cb_priv
without synchronizing with stm32_mdf_adc_dma_buffer_done(), so CPU1 can
pass a cleared adc->cb_priv or jump through a NULL adc->cb after the
if (adc->cb) check.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-upstream_mdf_v2-v2-0-7939d3c3720a@foss.st.com?part=10
next prev parent reply other threads:[~2026-11-18 16:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 15:17 [PATCH v2 00/11] iio: adc: stm32: add mdf support for stm32mp2 Olivier Moysan
2026-11-18 15:17 ` [PATCH v2 01/11] dt-bindings: iio: adc: add stm32mp2 mdf filter Olivier Moysan
2026-11-18 15:17 ` [PATCH v2 02/11] iio: adc: stm32-mdf: add core registration Olivier Moysan
2026-11-18 15:45 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 03/11] iio: adc: stm32-mdf: add cck clocks provider Olivier Moysan
2026-11-18 15:50 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 04/11] iio: adc: stm32-mdf: add serial interfaces support Olivier Moysan
2026-11-18 15:42 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 05/11] iio: adc: stm32-mdf: add digital filter device support Olivier Moysan
2026-11-18 15:40 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 06/11] iio: adc: stm32-mdf: configure cic filters and sample rates Olivier Moysan
2026-11-18 15:34 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 07/11] iio: adc: stm32-mdf: add direct iio conversion support Olivier Moysan
2026-11-18 15:51 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 08/11] iio: adc: stm32-mdf: add dma buffered acquisition support Olivier Moysan
2026-11-18 15:55 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 09/11] iio: adc: stm32-mdf: add external timer trigger support Olivier Moysan
2026-11-18 15:37 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 10/11] iio: adc: stm32-mdf: add dmic audio filter support Olivier Moysan
2026-11-18 16:06 ` sashiko-bot [this message]
2026-11-18 15:17 ` [PATCH v2 11/11] ASoC: stm32: add mdf dai support Olivier Moysan
2026-11-18 16:08 ` 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=sashiko-outbox-221421@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-sound@vger.kernel.org \
--cc=media-ci@linuxtv.org \
--cc=olivier.moysan@foss.st.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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