Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/allwinner Sanity-check the date before storing ...
details: https://anonhg.NetBSD.org/src/rev/3d4855104fca
branches: trunk
changeset: 333281:3d4855104fca
user: martin <martin%NetBSD.org@localhost>
date: Mon Oct 27 08:51:59 2014 +0000
description:
Sanity-check the date before storing it in the RTC, error out for non
representable dates.
diffstat:
sys/arch/arm/allwinner/awin_rtc.c | 34 +++++++++++++++++++++++++++++-----
1 files changed, 29 insertions(+), 5 deletions(-)
diffs (64 lines):
diff -r 485831969177 -r 3d4855104fca sys/arch/arm/allwinner/awin_rtc.c
--- a/sys/arch/arm/allwinner/awin_rtc.c Mon Oct 27 07:49:25 2014 +0000
+++ b/sys/arch/arm/allwinner/awin_rtc.c Mon Oct 27 08:51:59 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_rtc.c,v 1.2 2014/10/12 17:20:58 jmcneill Exp $ */
+/* $NetBSD: awin_rtc.c,v 1.3 2014/10/27 08:51:59 martin Exp $ */
/*-
* Copyright (c) 2014 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awin_rtc.c,v 1.2 2014/10/12 17:20:58 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_rtc.c,v 1.3 2014/10/27 08:51:59 martin Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -135,18 +135,42 @@
awin_rtc_settime(todr_chip_handle_t tch, struct clock_ymdhms *dt)
{
struct awin_rtc_softc *sc = tch->cookie;
- uint32_t yymmdd, hhmmss, losc;
+ uint32_t yymmdd, hhmmss, losc, maxyear;
losc = RTC_READ(sc, sc->sc_loscctrl_reg);
if (losc & AWIN_LOSC_CTRL_BUSY)
return EBUSY;
- yymmdd = 0;
- yymmdd |= __SHIFTIN(dt->dt_year - POSIX_BASE_YEAR,
+ /*
+ * Sanity check the date before writing it back
+ */
+ if (dt->dt_year < POSIX_BASE_YEAR) {
+ aprint_normal_dev(sc->sc_dev, "year pre the epoch: %llu, "
+ "not writing back time\n", dt->dt_year);
+ return EIO;
+ }
+ maxyear = __SHIFTOUT(0xffffffff,
+ awin_chip_id() == AWIN_CHIP_ID_A31 ?
+ AWIN_A31_RTC_YY_MM_DD_YEAR : AWIN_RTC_YY_MM_DD_YEAR)
+ + POSIX_BASE_YEAR;
+ if (dt->dt_year > maxyear) {
+ aprint_normal_dev(sc->sc_dev, "year exceeds avialable field:"
+ " %llu, not writing back time\n", dt->dt_year);
+ return EIO;
+ }
+
+ yymmdd = __SHIFTIN(dt->dt_year - POSIX_BASE_YEAR,
awin_chip_id() == AWIN_CHIP_ID_A31 ?
AWIN_A31_RTC_YY_MM_DD_YEAR : AWIN_RTC_YY_MM_DD_YEAR);
+
+ KASSERT(__SHIFTOUT(yymmdd,
+ awin_chip_id() == AWIN_CHIP_ID_A31 ?
+ AWIN_A31_RTC_YY_MM_DD_YEAR : AWIN_RTC_YY_MM_DD_YEAR) +
+ POSIX_BASE_YEAR == dt->dt_year);
+
yymmdd |= __SHIFTIN(dt->dt_mon, AWIN_RTC_YY_MM_DD_MONTH);
yymmdd |= __SHIFTIN(dt->dt_day, AWIN_RTC_YY_MM_DD_DAY);
+
hhmmss = 0;
hhmmss |= __SHIFTIN(dt->dt_wday, AWIN_RTC_HH_MM_SS_WK_NO);
hhmmss |= __SHIFTIN(dt->dt_hour, AWIN_RTC_HH_MM_SS_HOUR);
Home |
Main Index |
Thread Index |
Old Index