From: Jonathan Cameron <jic23@kernel.org>
To: Yizhuo <yzhai003@ucr.edu>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Mark Brown <broonie@kernel.org>,
Mugilraj Dhavachelvan <dmugil2000@gmail.com>,
Olivier Moysan <olivier.moysan@st.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Arnaud Pouliquen <arnaud.pouliquen@st.com>,
linux-iio@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: adc: stm32-dfsdm: Fix the uninitialized use if regmap_read() fails
Date: Sat, 24 Jul 2021 16:48:40 +0100 [thread overview]
Message-ID: <20210724164840.7381053b@jic23-huawei> (raw)
In-Reply-To: <20210719195313.40341-1-yzhai003@ucr.edu>
On Mon, 19 Jul 2021 19:53:11 +0000
Yizhuo <yzhai003@ucr.edu> wrote:
> Inside function stm32_dfsdm_irq(), the variable "status", "int_en"
> could be uninitialized if the regmap_read() fails and returns an error
> code. However, they are directly used in the later context to decide
> the control flow, which is potentially unsafe.
>
> Fixes: e2e6771c64625 ("IIO: ADC: add STM32 DFSDM sigma delta ADC support")
>
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>
Hi Yizhou
I want to get some review of this from people familiar with the
hardware as there is a small possibility your reordering might have
introduced a problem.
> ---
> drivers/iio/adc/stm32-dfsdm-adc.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c
> index 1cfefb3b5e56..d8b78aead942 100644
> --- a/drivers/iio/adc/stm32-dfsdm-adc.c
> +++ b/drivers/iio/adc/stm32-dfsdm-adc.c
> @@ -1292,9 +1292,11 @@ static irqreturn_t stm32_dfsdm_irq(int irq, void *arg)
> struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
> struct regmap *regmap = adc->dfsdm->regmap;
> unsigned int status, int_en;
> + int ret;
>
> - regmap_read(regmap, DFSDM_ISR(adc->fl_id), &status);
> - regmap_read(regmap, DFSDM_CR2(adc->fl_id), &int_en);
Moving this later is only valid if there aren't any side effects.
The current ordering is strange enough it makes me wonder if there might be!
Jonathan
> + ret = regmap_read(regmap, DFSDM_ISR(adc->fl_id), &status);
> + if (ret)
> + return IRQ_HANDLED;
>
> if (status & DFSDM_ISR_REOCF_MASK) {
> /* Read the data register clean the IRQ status */
> @@ -1303,6 +1305,9 @@ static irqreturn_t stm32_dfsdm_irq(int irq, void *arg)
> }
>
> if (status & DFSDM_ISR_ROVRF_MASK) {
> + ret = regmap_read(regmap, DFSDM_CR2(adc->fl_id), &int_en);
> + if (ret)
> + return IRQ_HANDLED;
> if (int_en & DFSDM_CR2_ROVRIE_MASK)
> dev_warn(&indio_dev->dev, "Overrun detected\n");
> regmap_update_bits(regmap, DFSDM_ICR(adc->fl_id),
next prev parent reply other threads:[~2021-07-24 15:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-19 19:53 [PATCH] iio: adc: stm32-dfsdm: Fix the uninitialized use if regmap_read() fails Yizhuo
2021-07-24 15:48 ` Jonathan Cameron [this message]
2021-08-08 17:32 ` Jonathan Cameron
2021-08-09 2:36 ` Yizhuo Zhai
2021-10-03 15:47 ` Jonathan Cameron
2021-10-05 8:18 ` Olivier MOYSAN
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=20210724164840.7381053b@jic23-huawei \
--to=jic23@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=andy.shevchenko@gmail.com \
--cc=arnaud.pouliquen@st.com \
--cc=broonie@kernel.org \
--cc=dmugil2000@gmail.com \
--cc=krzk@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=olivier.moysan@st.com \
--cc=yzhai003@ucr.edu \
/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;
as well as URLs for NNTP newsgroup(s).