rtc: retry to read rtc time if it fails

We add a retry here if the __rtc_read_time call fails or the
rtc_tm_to_ktime result is KTIME_MAX.

Signed-off-by: Yongliang Gao <leonylgao@tencent.com>
Reviewed-by: Jianping Liu <frankjpliu@tencent.com>
Signed-off-by: Jianping Liu <frankjpliu@tencent.com>
This commit is contained in:
Yongliang Gao 2024-11-21 10:31:59 +08:00 committed by Jianping Liu
parent 6ddc70a757
commit 784345b5ac
1 changed files with 9 additions and 3 deletions

View File

@ -13,6 +13,7 @@
#include <linux/module.h>
#include <linux/log2.h>
#include <linux/workqueue.h>
#include <linux/delay.h>
#define CREATE_TRACE_POINTS
#include <trace/events/rtc.h>
@ -922,13 +923,19 @@ again:
if (err) {
dev_err(&rtc->dev, "Failed to read rtc time, err=%d\n", err);
rtc_show_time(rtc, &tm);
goto out;
mutex_unlock(&rtc->ops_lock);
msleep(1000);
mutex_lock(&rtc->ops_lock);
goto again;
}
now = rtc_tm_to_ktime(tm);
if (now == KTIME_MAX) {
dev_err(&rtc->dev, "Failed to convert rtc time\n");
rtc_show_time(rtc, &tm);
goto out;
mutex_unlock(&rtc->ops_lock);
msleep(1000);
mutex_lock(&rtc->ops_lock);
goto again;
}
while ((next = timerqueue_getnext(&rtc->timerqueue))) {
if (next->expires > now)
@ -980,7 +987,6 @@ reprogram:
rtc_alarm_disable(rtc);
}
out:
pm_relax(rtc->dev.parent);
mutex_unlock(&rtc->ops_lock);
}