Skip to content

Commit 915593a

Browse files
Tom Rixalexandrebelloni
authored andcommitted
rtc: check if __rtc_read_time was successful
Clang static analysis reports this issue interface.c:810:8: warning: Passed-by-value struct argument contains uninitialized data now = rtc_tm_to_ktime(tm); ^~~~~~~~~~~~~~~~~~~ tm is set by a successful call to __rtc_read_time() but its return status is not checked. Check if it was successful before setting the enabled flag. Move the decl of err to function scope. Fixes: 2b2f5ff ("rtc: interface: ignore expired timers when enqueuing new timers") Signed-off-by: Tom Rix <trix@redhat.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20220326194236.2916310-1-trix@redhat.com
1 parent 4b2dc39 commit 915593a

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

drivers/rtc/interface.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,13 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
804804
struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue);
805805
struct rtc_time tm;
806806
ktime_t now;
807+
int err;
808+
809+
err = __rtc_read_time(rtc, &tm);
810+
if (err)
811+
return err;
807812

808813
timer->enabled = 1;
809-
__rtc_read_time(rtc, &tm);
810814
now = rtc_tm_to_ktime(tm);
811815

812816
/* Skip over expired timers */
@@ -820,7 +824,6 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
820824
trace_rtc_timer_enqueue(timer);
821825
if (!next || ktime_before(timer->node.expires, next->expires)) {
822826
struct rtc_wkalrm alarm;
823-
int err;
824827

825828
alarm.time = rtc_ktime_to_tm(timer->node.expires);
826829
alarm.enabled = 1;

0 commit comments

Comments
 (0)