Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp6624925ybn; Mon, 30 Sep 2019 00:45:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyB0u4U2f1rhhqpt5MLJaVK6Jq4191PNcYQo85i15FVmBiWhL1GetIAfL64KrnSjar552vR X-Received: by 2002:a17:906:2f10:: with SMTP id v16mr17678078eji.247.1569829516945; Mon, 30 Sep 2019 00:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569829516; cv=none; d=google.com; s=arc-20160816; b=yJ6PUNW4kLBeI0Hky2duoC2UHxQBEM8r297Ah8Mdv6jrLwOewp/fbwnQmdAYTGU1zg w93ASBDg/YDdxQnUUGWF4w5U4i+dr964rUr748NoGOIS+uVZ+ArAT8McNdVF7G7JYbOj mNyxGc9MhCOhmXvd5YFKJsEhT4kXfrAdq+9wyxoGxrHSHzubGaQtLkfoi3WKb2K3OCQp T938+2BaQHKEvmbQXQ23UpKZZp+hF/Oda9wKbVbXNVCETdrvNziXNLY3189gkqdtu4I4 wQP9k22lMaXFQ7lvP4lQ0++Xldmozd1WVdRUF3hA0V0c2vupjnq71uaaogktxQeJjJcq DPSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=bS6CJcL8QRhI+wW2/KA/SNkuTQVguGxzGlyj6/vnFq8=; b=QEFK8yXyMNFU/+YYsuaWlgNOTsKIRO7a++jvUZJ5FpqunYE2xEq1fMuzPoEH+jBis9 T1Gsysj2DjVR1TAjXy35bUI3UJn2g1+guzjo4y8/cESy6yR29ZtwQQL+295EZAnbpS6y Zhm/v1epUvhixxNWLdlAvKu1t/8gV9NMgMINX7zTaLHVCy4bUtoQot7tXr7V9udzLzpI weW5Ku9rr9qmDJwoW8Rl5fK66jeku+lrSvc/TLYCxo+fyCHMPlauSTDJe7JHwh8SKaon nTYrkFxgBN2h69pj09Ad4a8daXYvITmvXHD9Zzypf97do17SlzEGZ9ZdiejSVkzdmMuN 3EFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x62si6693786ede.352.2019.09.30.00.44.51; Mon, 30 Sep 2019 00:45:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729512AbfI3Hoa (ORCPT + 99 others); Mon, 30 Sep 2019 03:44:30 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:49597 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbfI3Hoa (ORCPT ); Mon, 30 Sep 2019 03:44:30 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iEqLy-0006Cg-VU; Mon, 30 Sep 2019 09:44:18 +0200 Received: from mfe by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1iEqLs-0000i1-B9; Mon, 30 Sep 2019 09:44:12 +0200 Date: Mon, 30 Sep 2019 09:44:12 +0200 From: Marco Felsch To: Yizhuo Cc: csong@cs.ucr.edu, Kate Stewart , Lars-Peter Clausen , Pengutronix Kernel Team , Allison Randal , Greg Kroah-Hartman , Enrico Weigelt , Fabio Estevam , Sascha Hauer , zhiyunq@cs.ucr.edu, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, NXP Linux Team , Peter Meerwald-Stadler , Hartmut Knaack , Thomas Gleixner , Shawn Guo , Jonathan Cameron , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] iio: adc: imx25-gcq: Variable could be uninitialized if regmap_read() fails Message-ID: <20190930074412.up4k6zdus4y7u4xb@pengutronix.de> References: <20190928002852.28329-1-yzhai003@ucr.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190928002852.28329-1-yzhai003@ucr.edu> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 09:37:13 up 135 days, 13:55, 87 users, load average: 0.06, 0.15, 0.15 User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > Signed-off-by: Yizhuo > --- > 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 > > > -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |