Skip to contentSkip to conversation

rtc: zynqmp: initialize fract_tick

PATCH In review [email protected] 3 participants 3 messages Jul 27, 2022 – Aug 5, 2022

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 rtc: zynqmp: initialize fract_tick

From: Alexandre Belloni <[email protected]>

fract_tick is used uninitialized when fract_offset is 0

---
 drivers/rtc/rtc-zynqmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-zynqmp.c +1 -1
index 1dd389b891fe..c9b85c838ebe 100644
@@ -203,7 +203,7 @@ static int xlnx_rtc_set_offset(struct device *dev, long offset)
 	struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
 	unsigned long long rtc_ppb = RTC_PPB;
 	unsigned int tick_mult = do_div(rtc_ppb, xrtcdev->freq);
-	unsigned char fract_tick;
+	unsigned char fract_tick = 0;
 	unsigned int calibval;
 	short int  max_tick;
 	int fract_offset;
Signature · 1 line
2.36.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · On 7/27/22 12:00, [email protected] wrote:

From: Alexandre Belloni <[email protected]>

fract_tick is used uninitialized when fract_offset is 0

---
  drivers/rtc/rtc-zynqmp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-zynqmp.c +1 -2
index 1dd389b891fe..c9b85c838ebe 100644
@@ -203,7 +203,7 @@ static int xlnx_rtc_set_offset(struct device *dev, long offset)
         struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
         unsigned long long rtc_ppb = RTC_PPB;
         unsigned int tick_mult = do_div(rtc_ppb, xrtcdev->freq);
-       unsigned char fract_tick;
+       unsigned char fract_tick = 0;
         unsigned int calibval;
         short int  max_tick;
         int fract_offset;
--
Quoted 2 lines

2.36.1

Thanks,
Michal

Reviewed-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 6 lines · On Wed, Jul 27, 2022 at 12:00:18PM +0200, [email protected] wrote:

From: Alexandre Belloni <[email protected]>

fract_tick is used uninitialized when fract_offset is 0

Is this going to be applied soon? This is one of the warnings breaking allmodconfig with clang right now:

    drivers/rtc/rtc-zynqmp.c:223:7: error: variable 'fract_tick' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
                    if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) {
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/rtc/rtc-zynqmp.c:238:6: note: uninitialized use occurs here
            if (fract_tick)
                ^~~~~~~~~~
    drivers/rtc/rtc-zynqmp.c:223:3: note: remove the 'if' if its condition is always true
                    if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) {
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/rtc/rtc-zynqmp.c:218:6: error: variable 'fract_tick' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
            if (fract_offset) {
                ^~~~~~~~~~~~
    drivers/rtc/rtc-zynqmp.c:238:6: note: uninitialized use occurs here
            if (fract_tick)
                ^~~~~~~~~~
    drivers/rtc/rtc-zynqmp.c:218:2: note: remove the 'if' if its condition is always true
            if (fract_offset) {
            ^~~~~~~~~~~~~~~~~~
    drivers/rtc/rtc-zynqmp.c:206:26: note: initialize the variable 'fract_tick' to silence this warning
            unsigned char fract_tick;
                                    ^
                                    = '\0'
    2 errors generated.
Quoted 21 lines
---
 drivers/rtc/rtc-zynqmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-zynqmp.c +1 -1
index 1dd389b891fe..c9b85c838ebe 100644
@@ -203,7 +203,7 @@ static int xlnx_rtc_set_offset(struct device *dev, long offset)
 	struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
 	unsigned long long rtc_ppb = RTC_PPB;
 	unsigned int tick_mult = do_div(rtc_ppb, xrtcdev->freq);
-	unsigned char fract_tick;
+	unsigned char fract_tick = 0;
 	unsigned int calibval;
 	short int  max_tick;
 	int fract_offset;
Signature · 1 line
2.36.1