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 08/11] iio: adc: stm32-mdf: add dma buffered acquisition support
Date: Wed, 18 Nov 2026 15:55:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-221387@kernel.org> (raw)
In-Reply-To: <20261118-upstream_mdf_v2-v2-8-7939d3c3720a@foss.st.com>
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [High] iio: adc: stm32-mdf: no-op W1C clear in stm32_mdf_irq() causes
IRQ storm
- [High] iio: adc: stm32-mdf: broken interleaved suspend and resume
ordering
- [High] iio: adc: stm32-mdf: NULL thread_fn in
devm_iio_triggered_buffer_setup()
- [Medium] iio: adc: stm32-mdf: wrong W1C clear in
stm32_mdf_adc_postenable()
- [Medium] iio: adc: stm32-mdf: uncleaned IRQs on error in
stm32_mdf_adc_postenable()
- [Medium] iio: adc: stm32-mdf: unbalanced kclk prepare in
stm32_mdf_adc_suspend()
- [Medium] iio: adc: stm32-mdf: zero-size cb on wrap in
stm32_mdf_adc_dma_buffer_done()
- [Medium] iio: adc: stm32-mdf: missing available_scan_masks for
interleaved mode
- [Low] iio: adc: stm32-mdf: unused PM callbacks when CONFIG_PM_SLEEP is
disabled
--
commit abc251af1764611faf8f05bc9f73b60d34b2ef36
Author: Olivier Moysan <olivier.moysan@foss.st.com>
iio: adc: stm32-mdf: add dma buffered acquisition support
This commit adds cyclic DMA buffered acquisition, watermark configuration,
and system suspend/resume support to the STM32 MDF ADC driver.
> diff --git a/drivers/iio/adc/stm32-mdf-adc.c b/drivers/iio/adc/stm32-mdf-adc.c
> index 7361ce6182bec..046ca3943a397 100644
> --- a/drivers/iio/adc/stm32-mdf-adc.c
> +++ b/drivers/iio/adc/stm32-mdf-adc.c
> @@ -823,6 +823,243 @@ static void stm32_mdf_adc_stop_conv(struct iio_dev *indio_dev)
[ ... ]
> +static void stm32_mdf_adc_dma_buffer_done(void *data)
> +{
> + struct iio_dev *indio_dev = data;
> + struct stm32_mdf_adc *adc = iio_priv(indio_dev);
> + int available = stm32_mdf_adc_dma_residue(adc);
> + size_t old_pos;
> +
> + dev_dbg(&indio_dev->dev, "pos = %d, available = %d\n", adc->bufi, available);
> + old_pos = adc->bufi;
> +
> + while (available >= indio_dev->scan_bytes) {
> + s32 *buffer = (s32 *)&adc->rx_buf[adc->bufi];
> +
> + adc->bufi += indio_dev->scan_bytes;
> + if (adc->bufi >= adc->buf_sz) {
> + if (adc->cb)
> + adc->cb(&adc->rx_buf[old_pos], adc->buf_sz - old_pos, adc->cb_priv);
> + adc->bufi = 0;
> + old_pos = 0;
> + }
> + if (adc->dev_data->type == STM32_MDF_IIO)
> + iio_push_to_buffers(indio_dev, buffer);
> + available -= indio_dev->scan_bytes;
> + }
[Severity: Medium]
In multi-channel interleaved mode on Filter 0, hardware and DMA always
transfer all num_ch 32-bit samples per scan into adc->rx_buf, but
stm32_mdf_adc_init() never sets indio_dev->available_scan_masks. If a
user enables only a subset of channels in scan_elements, does stepping
adc->bufi by the smaller indio_dev->scan_bytes without an IIO demux table
push samples from disabled interleaved filters as if they belonged to the
enabled channel?
> + if (adc->cb)
> + adc->cb(&adc->rx_buf[old_pos], adc->bufi - old_pos, adc->cb_priv);
> +}
[Severity: Medium]
When adc->bufi wraps around to 0 at adc->buf_sz inside the loop, both
adc->bufi and old_pos are reset to 0 after invoking adc->cb(). Does this
trailing check then call adc->cb() a second time with a size of 0 on every
buffer wrap-around (and whenever available < indio_dev->scan_bytes)?
[ ... ]
> +static int stm32_mdf_adc_postenable(struct iio_dev *indio_dev)
> +{
[ ... ]
> + stm32_mdf_adc_filter_set_mode(adc, true);
> +
> + regmap_clear_bits(adc->regmap, MDF_DFLTISR_REG,
> + MDF_DFLTISR_DOVRF_MASK | MDF_DFLTISR_SATF_MASK);
[Severity: Medium]
Status flags in MDF_DFLTISR_REG are write-1-to-clear (rc_w1). Because
MDF_DFLTISR_REG is volatile, regmap_clear_bits() reads the register and
writes back the value with MDF_DFLTISR_DOVRF_MASK | MDF_DFLTISR_SATF_MASK
masked to 0. Does this leave pending DOVRF and SATF flags asserted right
before enabling their interrupts, while inadvertently writing 1 to clear
any other asserted status flags in MDF_DFLTISR_REG? Clearing DOVRF and
SATF requires regmap_write().
> +
> + regmap_set_bits(adc->regmap, MDF_DFLTIER_REG,
> + MDF_DFLTIER_DOVRIE_MASK | MDF_DFLTIER_SATIE_MASK);
[Severity: High]
Enabling MDF_DFLTIER_DOVRIE_MASK and MDF_DFLTIER_SATIE_MASK here makes the
overflow and saturation handlers in stm32_mdf_irq() reachable:
drivers/iio/adc/stm32-mdf-adc.c:stm32_mdf_irq() {
...
if (flags & MDF_DFLTISR_DOVRF_MASK) {
dev_warn(&indio_dev->dev, "Data overflow detected\n");
regmap_set_bits(regmap, MDF_DFLTISR_REG, MDF_DFLTISR_DOVRF_MASK);
}
...
if (flags & MDF_DFLTISR_SATF_MASK) {
dev_warn(&indio_dev->dev, "Saturation detected\n");
regmap_set_bits(regmap, MDF_DFLTISR_REG, MDF_DFLTISR_SATF_MASK);
...
}
Because MDF_DFLTISR_REG is volatile and regmap_set_bits() passes
force = false, _regmap_update_bits() reads MDF_DFLTISR_REG, sees the
status bit is already 1, and skips the bus write. If a data overflow
occurs during DMA acquisition, will MDF_DFLTISR_DOVRF_MASK remain set
while MDF_DFLTIER_DOVRIE_MASK stays enabled, causing an infinite hardirq
storm?
> +
> + ret = stm32_mdf_adc_dma_start(indio_dev);
> + if (ret) {
> + dev_err(&indio_dev->dev, "Can't start DMA\n");
> + goto err_dma;
> + }
> +
> + ret = stm32_mdf_adc_start_conv(indio_dev);
> + if (ret) {
> + dev_err(&indio_dev->dev, "Can't start conversion\n");
> + goto err_conv;
> + }
> +
> + return 0;
> +
> +err_conv:
> + stm32_mdf_adc_dma_stop(indio_dev);
> +err_dma:
> + stm32_mdf_adc_stop_mdf(indio_dev);
[Severity: Medium]
If stm32_mdf_adc_dma_start() or stm32_mdf_adc_start_conv() fails (for
example, when adc->buf_sz is 0), does the err_dma unwind path leave
MDF_DFLTIER_DOVRIE_MASK | MDF_DFLTIER_SATIE_MASK enabled in
MDF_DFLTIER_REG?
[ ... ]
> @@ -1208,6 +1467,24 @@ static int stm32_mdf_adc_init(struct device *dev, struct iio_dev *indio_dev)
>
> init_completion(&adc->completion);
>
> + /* Optionally request DMA */
> + ret = stm32_mdf_dma_request(dev, indio_dev);
> + if (ret) {
> + if (ret != -ENODEV)
> + return dev_err_probe(dev, ret, "DMA channel request failed with\n");
> +
> + dev_dbg(dev, "No DMA support\n");
> + return 0;
> + }
> +
> + ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> + &iio_pollfunc_store_time, NULL,
> + &stm32_mdf_buffer_setup_ops);
[Severity: High]
Can attaching an IIO trigger and enabling the buffer crash or wedge the
kernel here?
devm_iio_triggered_buffer_setup() sets INDIO_BUFFER_TRIGGERED and
allocates indio_dev->pollfunc with h = iio_pollfunc_store_time,
thread = NULL, and type = IRQF_ONESHOT. When a trigger is attached and
the buffer is enabled, iio_verify_update() selects INDIO_BUFFER_TRIGGERED
over INDIO_BUFFER_SOFTWARE and iio_trigger_attach_poll_func() calls
request_threaded_irq() with IRQF_ONESHOT and thread_fn = NULL, hitting
WARN_ON_ONCE(new->flags & IRQF_ONESHOT && !new->thread_fn) in
__setup_irq(). When the trigger fires, a nested trigger such as
iio-trig-loop dereferences NULL action->thread_fn in handle_nested_irq(),
while a non-nested trigger such as iio-trig-sysfs or iio-trig-hrtimer
returns IRQ_WAKE_THREAD with no thread_fn, hitting warn_no_thread() and
never calling iio_trigger_notify_done().
The follow-up commit "iio: adc: stm32-mdf: add external timer trigger
support" adds INDIO_HARDWARE_TRIGGERED and .validate_trigger, but keeps
devm_iio_triggered_buffer_setup() with a NULL thread_fn, so
INDIO_BUFFER_TRIGGERED is still selected whenever indio_dev->trig is set.
Since samples are pushed from the DMA callback and external triggers are
routed in hardware, should this use devm_iio_kfifo_buffer_setup() (and
select IIO_KFIFO_BUF in Kconfig) instead of
devm_iio_triggered_buffer_setup()?
[ ... ]
> @@ -1479,14 +1758,48 @@ static void stm32_mdf_adc_remove(struct platform_device *pdev)
[ ... ]
> +static int stm32_mdf_adc_suspend(struct device *dev)
> +{
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct stm32_mdf_adc *adc = iio_priv(indio_dev);
> + int ret = 0;
> +
> + if (iio_buffer_enabled(indio_dev))
> + ret = stm32_mdf_adc_predisable(indio_dev);
> +
> + regcache_cache_only(adc->regmap, true);
> + regcache_mark_dirty(adc->regmap);\n+
> + return ret;
> +}
[Severity: Medium]
stm32_mdf_adc_probe() attaches adc->mdf->kclk to adc->regmap via
stm32_mdf_regmap_init() -> regmap_mmio_attach_clk(), which holds a
clk_prepare() reference on kclk. In stm32_mdf_core_suspend(), the parent
driver unprepares kclk only for sitf_list and the core regmap, not for
filter regmaps. Should stm32_mdf_adc_suspend() and stm32_mdf_adc_resume()
also unprepare and re-prepare adc->mdf->kclk so kclk does not stay
prepared across system suspend?
> +
> +static int stm32_mdf_adc_resume(struct device *dev)
> +{
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct stm32_mdf_adc *adc = iio_priv(indio_dev);
> + int ret;
> +
> + regcache_cache_only(adc->regmap, false);
> + ret = regcache_sync(adc->regmap);
> +
> + if (!ret && iio_buffer_enabled(indio_dev))
> + ret = stm32_mdf_adc_postenable(indio_dev);
> +
> + return ret;
> +}
[Severity: High]
How does suspend and resume work when interleaved (or synchronized)
filters are active?
In interleaved mode, only Filter 0 registers an IIO device, so
iio_buffer_enabled() is only ever true on Filter 0, while Filter 0 starts
and stops subordinate filters (Filters 1..N-1) by iterating
mdf->filter_list. Because child devices suspend in reverse probe order
and resume in forward probe order:
1. On suspend, Filters N-1..1 run stm32_mdf_adc_suspend() before Filter 0
and set regcache_cache_only(adc_inter->regmap, true). When Filter 0
then calls stm32_mdf_adc_predisable() -> stm32_mdf_adc_stop_filter(),
clearing MDF_DFLTCR_DFLTEN on adc_inter->regmap only updates the cache
and does not stop Filters 1..N-1 in hardware.
2. On resume, Filter 0 runs stm32_mdf_adc_resume() ->
stm32_mdf_adc_postenable() before Filters 1..N-1 have cleared
cache_only on their regmaps:
drivers/iio/adc/stm32-mdf-adc.c:stm32_mdf_adc_start_filter() {
...
if (MDF_IS_FILTER0(adc))
list_for_each_entry(adc_inter, &mdf->filter_list, entry)
if (MDF_IS_INTERLEAVED_FILT_NOT_0(adc_inter))
stm32_mdf_adc_start_filter(adc_inter);
/* Check filter status. Bypass cache to access volatile MDF_DFLTCR_ACTIVE bit */
regcache_cache_bypass(adc->regmap, true);
regmap_read(adc->regmap, MDF_DFLTCR_REG, &val);
regcache_cache_bypass(adc->regmap, false);
...
}
Calling stm32_mdf_adc_start_filter(adc_inter) while adc_inter->regmap
is still cache-only triggers WARN_ON(map->cache_only && enable) in
regcache_cache_bypass(), causes regmap_read() to fail with -EBUSY
leaving val uninitialized on the stack, traps filter configuration and
MDF_DFLTCR_DFLTEN writes in cache, and pulses MDF_GCR_TRGO before
subordinate interleaved (or st,sync slave) filters have resumed in
hardware.
In addition, stm32_mdf_adc_init() requests a DMA channel, 16 KB coherent
buffer, and triggered IIO buffer even for MDF_IS_INTERLEAVED_FILT_NOT_0()
filters that never register an IIO device.
> +
> +static SIMPLE_DEV_PM_OPS(stm32_mdf_adc_pm_ops, stm32_mdf_adc_suspend, stm32_mdf_adc_resume);
> +
> static struct platform_driver stm32_mdf_adc_driver = {
> .driver = {
> .name = "stm32-mdf-adc",
> .of_match_table = stm32_mdf_adc_match,
> + .pm = &stm32_mdf_adc_pm_ops,
> },
[Severity: Low]
When CONFIG_PM_SLEEP is disabled, SIMPLE_DEV_PM_OPS() leaves
stm32_mdf_adc_suspend() and stm32_mdf_adc_resume() unused, producing
-Wunused-function warnings. Could this use DEFINE_SIMPLE_DEV_PM_OPS() and
pm_sleep_ptr(&stm32_mdf_adc_pm_ops) instead?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-upstream_mdf_v2-v2-0-7939d3c3720a@foss.st.com?part=8
next prev parent reply other threads:[~2026-11-18 15:55 UTC|newest]
Thread overview: 24+ 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-19 9:44 ` Andy Shevchenko
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 [this message]
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
2026-11-18 15:17 ` [PATCH v2 11/11] ASoC: stm32: add mdf dai support Olivier Moysan
2026-11-18 16:08 ` sashiko-bot
2026-11-19 18:37 ` [PATCH v2 00/11] iio: adc: stm32: add mdf support for stm32mp2 Conor Dooley
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-221387@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 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.