Skip to content

Commit 64d69b5

Browse files
miquelraynalalexandrebelloni
authored andcommitted
rtc: rzn1: Avoid mixing variables
In the ->set_offset() callback, the 'val' variable is used for two different purposes at the same time, which is oviously wrong: - It contains the intermediate value of the SUBU register that must be written at the end of ->set_offset(). - It is used in the middle of the above calculations to poll the CTL2 register for a specific value. Let's introduce a 'ctl2' variable just for the readl_poll_timeout() call and use it there in place of 'var'. In order to avoid mixing those two variables again, let's rename the remaining occurences of 'val' into 'subu' and initialize it to 0 to avoid the uninitialized variable situation reported by Tom Rix and Colin Ian King already. Fixes: be4a11c ("rtc: rzn1: Add oscillator offset support") Reported-by: Tom Rix <[email protected]> Reported-by: Colin Ian King <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Signed-off-by: Alexandre Belloni <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b520cbe commit 64d69b5

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/rtc/rtc-rzn1.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int rzn1_rtc_set_offset(struct device *dev, long offset)
272272
struct rzn1_rtc *rtc = dev_get_drvdata(dev);
273273
unsigned int steps;
274274
int stepsh, stepsl;
275-
u32 val;
275+
u32 subu = 0, ctl2;
276276
int ret;
277277

278278
/*
@@ -288,7 +288,7 @@ static int rzn1_rtc_set_offset(struct device *dev, long offset)
288288
if (stepsh >= -0x3E && stepsh <= 0x3E) {
289289
/* 1017 ppb per step */
290290
steps = stepsh;
291-
val |= RZN1_RTC_SUBU_DEV;
291+
subu |= RZN1_RTC_SUBU_DEV;
292292
} else if (stepsl >= -0x3E && stepsl <= 0x3E) {
293293
/* 3051 ppb per step */
294294
steps = stepsl;
@@ -300,18 +300,18 @@ static int rzn1_rtc_set_offset(struct device *dev, long offset)
300300
return 0;
301301

302302
if (steps > 0) {
303-
val |= steps + 1;
303+
subu |= steps + 1;
304304
} else {
305-
val |= RZN1_RTC_SUBU_DECR;
306-
val |= (~(-steps - 1)) & 0x3F;
305+
subu |= RZN1_RTC_SUBU_DECR;
306+
subu |= (~(-steps - 1)) & 0x3F;
307307
}
308308

309-
ret = readl_poll_timeout(rtc->base + RZN1_RTC_CTL2, val,
310-
!(val & RZN1_RTC_CTL2_WUST), 100, 2000000);
309+
ret = readl_poll_timeout(rtc->base + RZN1_RTC_CTL2, ctl2,
310+
!(ctl2 & RZN1_RTC_CTL2_WUST), 100, 2000000);
311311
if (ret)
312312
return ret;
313313

314-
writel(val, rtc->base + RZN1_RTC_SUBU);
314+
writel(subu, rtc->base + RZN1_RTC_SUBU);
315315

316316
return 0;
317317
}

0 commit comments

Comments
 (0)