From: Arnav Kapoor <kapoorarnav43@gmail.com>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Frank Li" <Frank.Li@nxp.com>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>
Cc: Arnav Kapoor <kapoorarnav43@gmail.com>,
linux-iio@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] iio: adc: fsl-imx25-gcq: check the return value of the
Date: Thu, 22 Oct 2026 04:24:45 +0530 [thread overview]
Message-ID: <20261021225450.628499-1-kapoorarnav43@gmail.com> (raw)
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;
}
reply other threads:[~2026-10-21 22:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261021225450.628499-1-kapoorarnav43@gmail.com \
--to=kapoorarnav43@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=jic23@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=s.hauer@pengutronix.de \
/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
all inboxes | Powered by JetHome®