linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Yizhuo <yzhai003@ucr.edu>
Cc: csong@cs.ucr.edu, Enrico Weigelt <info@metux.net>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	linux-iio@vger.kernel.org, Fabio Estevam <festevam@gmail.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	zhiyunq@cs.ucr.edu, linux-kernel@vger.kernel.org,
	Stephen Boyd <swboyd@chromium.org>,
	NXP Linux Team <linux-imx@nxp.com>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	Shawn Guo <shawnguo@kernel.org>,
	Kate Stewart <kstewart@linuxfoundation.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] iio: adc: imx25-gcq: fix uninitialized variable usage
Date: Tue, 1 Oct 2019 09:47:35 +0100	[thread overview]
Message-ID: <20191001094735.4f04bfdf@archlinux> (raw)
In-Reply-To: <20190930195358.27844-1-yzhai003@ucr.edu>

On Mon, 30 Sep 2019 12:53:54 -0700
Yizhuo <yzhai003@ucr.edu> wrote:

> In function mx25_gcq_irq(), local variable "stats" could
> be uninitialized if function regmap_read() returns -EINVAL.
> However, this value is used in if statement, which is
> potentially unsafe. The same case applied to the variable
> "data" in function mx25_gcq_get_raw_value() in the same file.
> 
> Signed-off-by: Yizhuo <yzhai003@ucr.edu>

Following similar logic to the other patch I just reviewed
for the stm32-timer-trigger, lets chase if this can happen.
In this case a clock is not provided during the regmap iomem register
and as such, the call can't actually fail.

So this one is more of a tidy up and hardening against future
problems if the code changes, than an actual fix.

Worth having, but perhaps remove the word fix from the description
unless you can find a path I've missed in which this might actually
happen as the code currently is.

One minor comment inline,

Thanks,

Jonathan
> ---
>  drivers/iio/adc/fsl-imx25-gcq.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
> index fa71489195c6..3b1e12b7c1ac 100644
> --- a/drivers/iio/adc/fsl-imx25-gcq.c
> +++ b/drivers/iio/adc/fsl-imx25-gcq.c
> @@ -73,8 +73,12 @@ static irqreturn_t mx25_gcq_irq(int irq, void *data)
>  {
>  	struct mx25_gcq_priv *priv = data;
>  	u32 stats;
> +	int ret;
>  
> -	regmap_read(priv->regs, MX25_ADCQ_SR, &stats);
> +	ret = regmap_read(priv->regs, MX25_ADCQ_SR, &stats);
> +	if (ret) {

No brackets around a single line block like this.

> +		return ret;
> +	}
>  
>  	if (stats & MX25_ADCQ_SR_EOQ) {
>  		regmap_update_bits(priv->regs, MX25_ADCQ_MR,
> @@ -100,6 +104,7 @@ static int mx25_gcq_get_raw_value(struct device *dev,
>  {
>  	long timeout;
>  	u32 data;
> +	int ret;
>  
>  	/* Setup the configuration we want to use */
>  	regmap_write(priv->regs, MX25_ADCQ_ITEM_7_0,
> @@ -121,7 +126,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 MX25_ADCQ_FIFO.\n");
> +		return ret;
> +	}
>  
>  	*val = MX25_ADCQ_FIFO_DATA(data);
>  


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      reply	other threads:[~2019-10-01  8:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-30 19:53 [PATCH] iio: adc: imx25-gcq: fix uninitialized variable usage Yizhuo
2019-10-01  8:47 ` Jonathan Cameron [this message]

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=20191001094735.4f04bfdf@archlinux \
    --to=jic23@kernel.org \
    --cc=csong@cs.ucr.edu \
    --cc=festevam@gmail.com \
    --cc=info@metux.net \
    --cc=kernel@pengutronix.de \
    --cc=knaack.h@gmx.de \
    --cc=kstewart@linuxfoundation.org \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=swboyd@chromium.org \
    --cc=tglx@linutronix.de \
    --cc=yzhai003@ucr.edu \
    --cc=zhiyunq@cs.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).