* [PATCH] iio: adc: fsl-imx25-gcq: check the return value of the
@ 2026-10-21 22:54 Arnav Kapoor
2026-10-22 15:55 ` Frank Li
2026-10-22 16:35 ` Andy Shevchenko
0 siblings, 2 replies; 5+ messages in thread
From: Arnav Kapoor @ 2026-10-21 22:54 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam
Cc: Arnav Kapoor, linux-iio, imx, linux-arm-kernel, linux-kernel
The driver ignores the return value of all the regmap accesses. If one
of them fails, e.g. because the memory mapped registers can't be
accessed, the driver just continues with an undefined state.
The most severe case is the read of the FIFO in
mx25_gcq_get_raw_value(): the destination variable is not initialized,
so a failed read leaks uninitialized stack memory to userspace.
Check the return value of all the register accesses and propagate the
errors to the caller. In the interrupt handler, where there is not much
that can be done about a failed access, just don't use the content of
the status register if it can't be read.
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
drivers/iio/adc/fsl-imx25-gcq.c | 82 ++++++++++++++++++++++++---------
1 file changed, 60 insertions(+), 22 deletions(-)
diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
index dc310ed616a1..b6c1ed867177 100644
--- a/drivers/iio/adc/fsl-imx25-gcq.c
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -83,7 +83,13 @@ static irqreturn_t mx25_gcq_irq(int irq, void *data)
struct mx25_gcq_priv *priv = data;
u32 stats;
- regmap_read(priv->regs, MX25_ADCQ_SR, &stats);
+ /*
+ * If the status can't be read we don't know whether the conversion
+ * has finished. The interrupt is still acknowledged below, so just
+ * skip the completion and let the reader time out.
+ */
+ if (regmap_read(priv->regs, MX25_ADCQ_SR, &stats))
+ stats = 0;
if (stats & MX25_ADCQ_SR_EOQ) {
regmap_set_bits(priv->regs, MX25_ADCQ_MR,
@@ -109,15 +115,29 @@ static int mx25_gcq_get_raw_value(struct device *dev,
{
long time_left;
u32 data;
+ int ret;
/* Setup the configuration we want to use */
- regmap_write(priv->regs, MX25_ADCQ_ITEM_7_0,
- MX25_ADCQ_ITEM(0, chan->channel));
+ ret = regmap_write(priv->regs, MX25_ADCQ_ITEM_7_0,
+ MX25_ADCQ_ITEM(0, chan->channel));
+ if (ret) {
+ dev_err(dev, "Failed to setup the queue item: %d\n", ret);
+ return ret;
+ }
- regmap_clear_bits(priv->regs, MX25_ADCQ_MR, MX25_ADCQ_MR_EOQ_IRQ);
+ ret = regmap_clear_bits(priv->regs, MX25_ADCQ_MR,
+ MX25_ADCQ_MR_EOQ_IRQ);
+ if (ret) {
+ dev_err(dev, "Failed to clear the EoQ interrupt: %d\n", ret);
+ return ret;
+ }
/* Trigger queue for one run */
- regmap_set_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FQS);
+ ret = regmap_set_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FQS);
+ if (ret) {
+ dev_err(dev, "Failed to trigger the queue: %d\n", ret);
+ return ret;
+ }
time_left = wait_for_completion_interruptible_timeout(
&priv->completed, MX25_GCQ_TIMEOUT);
@@ -129,7 +149,11 @@ static int mx25_gcq_get_raw_value(struct device *dev,
return -ETIMEDOUT;
}
- regmap_read(priv->regs, MX25_ADCQ_FIFO, &data);
+ ret = regmap_read(priv->regs, MX25_ADCQ_FIFO, &data);
+ if (ret) {
+ dev_err(dev, "Failed to read the FIFO: %d\n", ret);
+ return ret;
+ }
*val = MX25_ADCQ_FIFO_DATA(data);
@@ -204,14 +228,18 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
* Setup all configurations registers with a default conversion
* configuration for each input
*/
- for (i = 0; i < MX25_NUM_CFGS; ++i)
- regmap_write(priv->regs, MX25_ADCQ_CFG(i),
- MX25_ADCQ_CFG_YPLL_OFF |
- MX25_ADCQ_CFG_XNUR_OFF |
- MX25_ADCQ_CFG_XPUL_OFF |
- MX25_ADCQ_CFG_REFP_INT |
- MX25_ADCQ_CFG_IN(i) |
- MX25_ADCQ_CFG_REFN_NGND2);
+ for (i = 0; i < MX25_NUM_CFGS; ++i) {
+ ret = regmap_write(priv->regs, MX25_ADCQ_CFG(i),
+ MX25_ADCQ_CFG_YPLL_OFF |
+ MX25_ADCQ_CFG_XNUR_OFF |
+ MX25_ADCQ_CFG_XPUL_OFF |
+ MX25_ADCQ_CFG_REFP_INT |
+ MX25_ADCQ_CFG_IN(i) |
+ MX25_ADCQ_CFG_REFN_NGND2);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to write the configuration register\n");
+ }
device_for_each_child_node_scoped(dev, child) {
u32 reg;
@@ -265,16 +293,26 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
return dev_err_probe(dev, -EINVAL,
"Invalid fsl,adc-refn property value\n");
- regmap_update_bits(priv->regs, MX25_ADCQ_CFG(reg),
- MX25_ADCQ_CFG_REFP_MASK |
- MX25_ADCQ_CFG_REFN_MASK,
- refp | refn);
+ ret = regmap_update_bits(priv->regs, MX25_ADCQ_CFG(reg),
+ MX25_ADCQ_CFG_REFP_MASK |
+ MX25_ADCQ_CFG_REFN_MASK,
+ refp | refn);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to update the configuration register\n");
}
- regmap_set_bits(priv->regs, MX25_ADCQ_CR,
- MX25_ADCQ_CR_FRST | MX25_ADCQ_CR_QRST);
- regmap_write(priv->regs, MX25_ADCQ_CR,
- MX25_ADCQ_CR_PDMSK | MX25_ADCQ_CR_QSM_FQS);
+ ret = regmap_set_bits(priv->regs, MX25_ADCQ_CR,
+ MX25_ADCQ_CR_FRST | MX25_ADCQ_CR_QRST);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to reset the conversion queue\n");
+
+ ret = regmap_write(priv->regs, MX25_ADCQ_CR,
+ MX25_ADCQ_CR_PDMSK | MX25_ADCQ_CR_QSM_FQS);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Failed to configure the conversion queue\n");
return 0;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: adc: fsl-imx25-gcq: check the return value of the
2026-10-21 22:54 [PATCH] iio: adc: fsl-imx25-gcq: check the return value of the Arnav Kapoor
@ 2026-10-22 15:55 ` Frank Li
2026-10-22 16:37 ` Andy Shevchenko
2026-10-22 16:35 ` Andy Shevchenko
1 sibling, 1 reply; 5+ messages in thread
From: Frank Li @ 2026-10-22 15:55 UTC (permalink / raw)
To: Arnav Kapoor
Cc: Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, linux-iio, imx, linux-arm-kernel, linux-kernel
On Thu, Oct 22, 2026 at 04:24:45AM +0530, Arnav Kapoor wrote:
> [You don't often get email from kapoorarnav43@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> The driver ignores the return value of all the regmap accesses. If one
> of them fails, e.g. because the memory mapped registers can't be
> accessed, the driver just continues with an undefined state.
MMIO never return failure. if write register fail at irq, it will cause
irq storm.
Frank
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: adc: fsl-imx25-gcq: check the return value of the
2026-10-21 22:54 [PATCH] iio: adc: fsl-imx25-gcq: check the return value of the Arnav Kapoor
2026-10-22 15:55 ` Frank Li
@ 2026-10-22 16:35 ` Andy Shevchenko
2026-10-22 16:44 ` Arnav Kapoor
1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-10-22 16:35 UTC (permalink / raw)
To: Arnav Kapoor
Cc: Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, linux-iio, imx, linux-arm-kernel, linux-kernel
On Thu, Oct 22, 2026 at 04:24:45AM +0530, Arnav Kapoor wrote:
> The driver ignores the return value of all the regmap accesses. If one
> of them fails, e.g. because the memory mapped registers can't be
> accessed, the driver just continues with an undefined state.
Can MMIO actually fail? It can give invalid values (due to HW being off or
wrong MMIO window). It can give a page fault, or some other error in HW,
but the read itself most likely never fails.
> The most severe case is the read of the FIFO in
> mx25_gcq_get_raw_value(): the destination variable is not initialized,
> so a failed read leaks uninitialized stack memory to userspace.
>
> Check the return value of all the register accesses and propagate the
> errors to the caller. In the interrupt handler, where there is not much
> that can be done about a failed access, just don't use the content of
> the status register if it can't be read.
I consider this change an unneeded churn until you come up with real life
example of how MMIO fails (at least on this platform, not exactly with this
driver).
Yes, I aware that checking for error codes of regmap is a good manners and
style in general, but would we do jsut that in a standalone change?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: adc: fsl-imx25-gcq: check the return value of the
2026-10-22 15:55 ` Frank Li
@ 2026-10-22 16:37 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-10-22 16:37 UTC (permalink / raw)
To: Frank Li
Cc: Arnav Kapoor, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, linux-iio, imx, linux-arm-kernel, linux-kernel
On Thu, Oct 22, 2026 at 10:55:59AM -0500, Frank Li wrote:
> On Thu, Oct 22, 2026 at 04:24:45AM +0530, Arnav Kapoor wrote:
> > The driver ignores the return value of all the regmap accesses. If one
> > of them fails, e.g. because the memory mapped registers can't be
> > accessed, the driver just continues with an undefined state.
>
> MMIO never return failure. if write register fail at irq, it will cause
> irq storm.
Strictly speaking it may lead to some CPU exceptions in some cases, but that's
different level of failures and not related to the error codes from regmap IO
accessors.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: adc: fsl-imx25-gcq: check the return value of the
2026-10-22 16:35 ` Andy Shevchenko
@ 2026-10-22 16:44 ` Arnav Kapoor
0 siblings, 0 replies; 5+ messages in thread
From: Arnav Kapoor @ 2026-10-22 16:44 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Frank Li, Jonathan Cameron, David Lechner, Nuno Sa,
Andy Shevchenko, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, linux-iio, imx, linux-arm-kernel, linux-kernel
(Resending as plain text, my earlier reply was rejected by one of the
lists.)
On Thu, Oct 22, 2026 at 07:35:59PM +0300, Andy Shevchenko wrote:
> I consider this change an unneeded churn until you come up with real life
> example of how MMIO fails
You and Frank are right. The regmap here is a plain
devm_regmap_init_mmio() without a clock, so the accesses can't return an
error, and the uninitialized-data case can't happen either. Please drop
this patch.
Thanks to both of you for the review. And Andy, thank you for going
through all of my patches today, the feedback has been very helpful.
Arnav
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-22 16:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 22:54 [PATCH] iio: adc: fsl-imx25-gcq: check the return value of the Arnav Kapoor
2026-10-22 15:55 ` Frank Li
2026-10-22 16:37 ` Andy Shevchenko
2026-10-22 16:35 ` Andy Shevchenko
2026-10-22 16:44 ` Arnav Kapoor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®