Commit 120931db authored by Mario Limonciello's avatar Mario Limonciello Committed by Alexandre Belloni
Browse files

rtc: Add support for configuring the UIP timeout for RTC reads



The UIP timeout is hardcoded to 10ms for all RTC reads, but in some
contexts this might not be enough time. Add a timeout parameter to
mc146818_get_time() and mc146818_get_time_callback().

If UIP timeout is configured by caller to be >=100 ms and a call
takes this long, log a warning.

Make all callers use 10ms to ensure no functional changes.

Cc:  <stable@vger.kernel.org> # 6.1.y
Fixes: ec5895c0 ("rtc: mc146818-lib: extract mc146818_avoid_UIP")
Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
Tested-by: default avatarMateusz Jończyk <mat.jonczyk@o2.pl>
Reviewed-by: default avatarMateusz Jończyk <mat.jonczyk@o2.pl>
Acked-by: default avatarMateusz Jończyk <mat.jonczyk@o2.pl>
Link: https://lore.kernel.org/r/20231128053653.101798-4-mario.limonciello@amd.com


Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 1311a8f0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ init_rtc_epoch(void)
static int
alpha_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
	int ret = mc146818_get_time(tm);
	int ret = mc146818_get_time(tm, 10);

	if (ret < 0) {
		dev_err_ratelimited(dev, "unable to read current time\n");
+1 −1
Original line number Diff line number Diff line
@@ -1438,7 +1438,7 @@ irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id)
	memset(&curr_time, 0, sizeof(struct rtc_time));

	if (hpet_rtc_flags & (RTC_UIE | RTC_AIE)) {
		if (unlikely(mc146818_get_time(&curr_time) < 0)) {
		if (unlikely(mc146818_get_time(&curr_time, 10) < 0)) {
			pr_err_ratelimited("unable to read current time from RTC\n");
			return IRQ_HANDLED;
		}
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ void mach_get_cmos_time(struct timespec64 *now)
		return;
	}

	if (mc146818_get_time(&tm)) {
	if (mc146818_get_time(&tm, 10)) {
		pr_err("Unable to read current time from RTC\n");
		now->tv_sec = now->tv_nsec = 0;
		return;
+1 −1
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ static unsigned int read_magic_time(void)
	struct rtc_time time;
	unsigned int val;

	if (mc146818_get_time(&time) < 0) {
	if (mc146818_get_time(&time, 10) < 0) {
		pr_err("Unable to read current time from RTC\n");
		return 0;
	}
+3 −3
Original line number Diff line number Diff line
@@ -231,7 +231,7 @@ static int cmos_read_time(struct device *dev, struct rtc_time *t)
	if (!pm_trace_rtc_valid())
		return -EIO;

	ret = mc146818_get_time(t);
	ret = mc146818_get_time(t, 10);
	if (ret < 0) {
		dev_err_ratelimited(dev, "unable to read current time\n");
		return ret;
@@ -307,7 +307,7 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
	 *
	 * Use the mc146818_avoid_UIP() function to avoid this.
	 */
	if (!mc146818_avoid_UIP(cmos_read_alarm_callback, &p))
	if (!mc146818_avoid_UIP(cmos_read_alarm_callback, 10, &p))
		return -EIO;

	if (!(p.rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
@@ -556,7 +556,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
	 *
	 * Use mc146818_avoid_UIP() to avoid this.
	 */
	if (!mc146818_avoid_UIP(cmos_set_alarm_callback, &p))
	if (!mc146818_avoid_UIP(cmos_set_alarm_callback, 10, &p))
		return -ETIMEDOUT;

	cmos->alarm_expires = rtc_tm_to_time64(&t->time);
Loading