linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: imx25-gcq: fix uninitialized variable usage
@ 2019-09-30 19:53 Yizhuo
  2019-10-01  8:47 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Yizhuo @ 2019-09-30 19:53 UTC (permalink / raw)
  Cc: csong, Enrico Weigelt, Lars-Peter Clausen,
	Pengutronix Kernel Team, linux-iio, Fabio Estevam, Sascha Hauer,
	zhiyunq, linux-kernel, Stephen Boyd, Yizhuo, Kate Stewart,
	NXP Linux Team, Peter Meerwald-Stadler, Hartmut Knaack,
	Thomas Gleixner, Shawn Guo, Jonathan Cameron, linux-arm-kernel

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>
---
 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) {
+		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);
 
-- 
2.17.1


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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-01  8:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-30 19:53 [PATCH] iio: adc: imx25-gcq: fix uninitialized variable usage Yizhuo
2019-10-01  8:47 ` Jonathan Cameron

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).