Skip to contentSkip to conversation

rtc: hctosys: Add missing range error reporting

PATCH Applied Maciej W. Rozycki 2 participants 2 messages Nov 5, 2018 – Nov 7, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc: hctosys: Add missing range error reporting

Fix an issue with the 32-bit range error path in rtc_hctosys' where no error code is set and consequently the successful preceding call result from rtc_read_time' is propagated to rtc_hctosys_ret'. This in turn makes any subsequent call to hctosys_show' incorrectly report in sysfs that the system time has been set from this RTC while it has not.

Set the error to ERANGE then if we can't express the result due to an overflow.

Fixes b3a5ac42ab18 ("rtc: hctosys: Ensure system time doesn't overflow time_t")
---
 drivers/rtc/hctosys.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

linux-rtc-hctosys-range.diff

drivers/rtc/hctosys.c +3 -1
Index: linux-20181008-swarm64-eb/drivers/rtc/hctosys.c
===================================================================
@@ -50,8 +50,10 @@ static int __init rtc_hctosys(void)
 	tv64.tv_sec = rtc_tm_to_time64(&tm);
 
 #if BITS_PER_LONG == 32
-	if (tv64.tv_sec > INT_MAX)
+	if (tv64.tv_sec > INT_MAX) {
+		err = -ERANGE;
 		goto err_read;
+	}
 #endif
 
 	err = do_settimeofday64(&tv64);
maintainer Applied
#1 lore raw
Quoted 9 lines · Maciej W. Rozycki

Fix an issue with the 32-bit range error path in rtc_hctosys' where no error code is set and consequently the successful preceding call result from rtc_read_time' is propagated to rtc_hctosys_ret'. This in turn makes any subsequent call to hctosys_show' incorrectly report in sysfs that the system time has been set from this RTC while it has not.

Set the error to ERANGE then if we can't express the result due to an overflow.

Quoted 7 lines
Fixes b3a5ac42ab18 ("rtc: hctosys: Ensure system time doesn't overflow time_t")
---
 drivers/rtc/hctosys.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied, thanks.

Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com