Skip to contentSkip to conversation

rtc: rzn1: Fix uninitialized variable val

PATCH In review Colin Ian King 2 participants 2 messages May 19, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: rzn1: Fix uninitialized variable val

Variable val is not being initialized and is later being read with a potentially garbage value. Fix this by initializing val to zero.

Detected by clang scan build:
warning: variable 'val' is uninitialized when used here [-Wuninitialized]

Fixes deeb4b5393e1 ("rtc: rzn1: Add new RTC driver")
---
 drivers/rtc/rtc-rzn1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-rzn1.c +1 -1
index 980ade8c9601..0b4bf6e43464 100644
@@ -272,7 +272,7 @@ static int rzn1_rtc_set_offset(struct device *dev, long offset)
 	struct rzn1_rtc *rtc = dev_get_drvdata(dev);
 	unsigned int steps;
 	int stepsh, stepsl;
-	u32 val;
+	u32 val = 0;
 	int ret;
 
 	/*
Signature · 1 line
2.35.1
maintainer
#1 lore raw

Hi Colin,

[email protected] wrote on Thu, 19 May 2022 11:06:41 +0100:

Quoted 19 lines

Variable val is not being initialized and is later being read with a potentially garbage value. Fix this by initializing val to zero.

Detected by clang scan build:
warning: variable 'val' is uninitialized when used here [-Wuninitialized]

Fixes deeb4b5393e1 ("rtc: rzn1: Add new RTC driver")
---
 drivers/rtc/rtc-rzn1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-rzn1.c +0 -0
index 980ade8c9601..0b4bf6e43464 100644

drivers/rtc/rtc-rzn1.c static int rzn1_rtc_set_offset(struct device *dev, long offset) · line 275

Quoted 5 lines
drivers/rtc/rtc-rzn1.c +1 -1
@@ -272,7 +272,7 @@ static int rzn1_rtc_set_offset(struct device *dev, long offset)
 	struct rzn1_rtc *rtc = dev_get_drvdata(dev);
 	unsigned int steps;
 	int stepsh, stepsl;
-	u32 val;
+	u32 val = 0;

There are actually two variables mixed together. "val" is used both for the readl_poll_timeout() call (where it should be a dedicated 'ctl2' variable) and for the subu register which is written at the end. This variable could be renamed 'subu' and initialized to 0 as you did.

Thanks,
Miquèl