linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: Yizhuo <yzhai003@ucr.edu>,
	csong@cs.ucr.edu, Kate Stewart <kstewart@linuxfoundation.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Allison Randal <allison@lohutok.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Enrico Weigelt <info@metux.net>,
	Fabio Estevam <festevam@gmail.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	zhiyunq@cs.ucr.edu, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.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>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] iio: adc: imx25-gcq: Variable could be uninitialized if regmap_read() fails
Date: Tue, 1 Oct 2019 09:54:46 +0100	[thread overview]
Message-ID: <20191001095446.17bc9cd8@archlinux> (raw)
In-Reply-To: <20190930074412.up4k6zdus4y7u4xb@pengutronix.de>

On Mon, 30 Sep 2019 09:44:12 +0200
Marco Felsch <m.felsch@pengutronix.de> wrote:

> Hi Yizhuo,
> 
> thanks for your patch.
> 
> On 19-09-27 17:28, Yizhuo 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.  
> 
> IMHO the commit header should be something like: "iio: adc: imx25-gcq:
> fix uninitialized variable usage"...
> 
> and please add a fixes tag.
As with the others, before adding a fixes tag, please verify there
is an actual path to trigger this.

In this case it's an mmio regmap with no clock. For those, I'm not sure
if there is a failure path.

Still a worthwhile hardening / cleanup patch, but shouldn't be called
a fix or marked with a fixes tag because we don't want people to think
it is necessary to backport it.

Thanks,

Jonathan


> 
> > 
> > Signed-off-by: Yizhuo <yzhai003@ucr.edu>
> > ---
> >  drivers/iio/adc/fsl-imx25-gcq.c | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
> > index df19ecae52f7..dbf3e8e85aba 100644
> > --- a/drivers/iio/adc/fsl-imx25-gcq.c
> > +++ b/drivers/iio/adc/fsl-imx25-gcq.c
> > @@ -74,7 +74,10 @@ 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);
> > +	int ret = regmap_read(priv->regs, MX25_ADCQ_SR, &stats);  
> 
> Please don't do this. First declare the variable and then use it.
> 
> Regards,
>   Marco
> 
> > +
> > +	if (ret)
> > +		return ret;
> >  
> >  	if (stats & MX25_ADCQ_SR_EOQ) {
> >  		regmap_update_bits(priv->regs, MX25_ADCQ_MR,
> > @@ -121,7 +124,10 @@ static int mx25_gcq_get_raw_value(struct device *dev,
> >  		return -ETIMEDOUT;
> >  	}
> >  
> > -	regmap_read(priv->regs, MX25_ADCQ_FIFO, &data);
> > +	int ret = regmap_read(priv->regs, MX25_ADCQ_FIFO, &data);
> > +
> > +	if (ret)
> > +		return ret;
> >  
> >  	*val = MX25_ADCQ_FIFO_DATA(data);
> >  
> > -- 
> > 2.17.1
> > 
> > 
> >   
> 


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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-28  0:28 [PATCH] iio: adc: imx25-gcq: Variable could be uninitialized if regmap_read() fails Yizhuo
2019-09-30  7:44 ` Marco Felsch
2019-10-01  8:54   ` 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=20191001095446.17bc9cd8@archlinux \
    --to=jic23@kernel.org \
    --cc=allison@lohutok.net \
    --cc=csong@cs.ucr.edu \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --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=m.felsch@pengutronix.de \
    --cc=pmeerw@pmeerw.net \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.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).