aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/lib.c')
-rw-r--r--drivers/rtc/lib.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/drivers/rtc/lib.c b/drivers/rtc/lib.c
index 9714cb3d1e29..23284580df97 100644
--- a/drivers/rtc/lib.c
+++ b/drivers/rtc/lib.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * rtc and date/time utility functions 3 * rtc and date/time utility functions
3 * 4 *
@@ -5,11 +6,7 @@
5 * Author: Alessandro Zummo <a.zummo@towertech.it> 6 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * 7 *
7 * based on arch/arm/common/rtctime.c and other bits 8 * based on arch/arm/common/rtctime.c and other bits
8 * 9 */
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13 10
14#include <linux/export.h> 11#include <linux/export.h>
15#include <linux/rtc.h> 12#include <linux/rtc.h>
@@ -25,7 +22,7 @@ static const unsigned short rtc_ydays[2][13] = {
25 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } 22 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
26}; 23};
27 24
28#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400) 25#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
29 26
30/* 27/*
31 * The number of days in the month. 28 * The number of days in the month.
@@ -41,11 +38,10 @@ EXPORT_SYMBOL(rtc_month_days);
41 */ 38 */
42int rtc_year_days(unsigned int day, unsigned int month, unsigned int year) 39int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
43{ 40{
44 return rtc_ydays[is_leap_year(year)][month] + day-1; 41 return rtc_ydays[is_leap_year(year)][month] + day - 1;
45} 42}
46EXPORT_SYMBOL(rtc_year_days); 43EXPORT_SYMBOL(rtc_year_days);
47 44
48
49/* 45/*
50 * rtc_time64_to_tm - Converts time64_t to rtc_time. 46 * rtc_time64_to_tm - Converts time64_t to rtc_time.
51 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date. 47 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
@@ -97,13 +93,15 @@ EXPORT_SYMBOL(rtc_time64_to_tm);
97 */ 93 */
98int rtc_valid_tm(struct rtc_time *tm) 94int rtc_valid_tm(struct rtc_time *tm)
99{ 95{
100 if (tm->tm_year < 70 96 if (tm->tm_year < 70 ||
101 || ((unsigned)tm->tm_mon) >= 12 97 tm->tm_year > (INT_MAX - 1900) ||
102 || tm->tm_mday < 1 98 ((unsigned int)tm->tm_mon) >= 12 ||
103 || tm->tm_mday > rtc_month_days(tm->tm_mon, ((unsigned)tm->tm_year + 1900)) 99 tm->tm_mday < 1 ||
104 || ((unsigned)tm->tm_hour) >= 24 100 tm->tm_mday > rtc_month_days(tm->tm_mon,
105 || ((unsigned)tm->tm_min) >= 60 101 ((unsigned int)tm->tm_year + 1900)) ||
106 || ((unsigned)tm->tm_sec) >= 60) 102 ((unsigned int)tm->tm_hour) >= 24 ||
103 ((unsigned int)tm->tm_min) >= 60 ||
104 ((unsigned int)tm->tm_sec) >= 60)
107 return -EINVAL; 105 return -EINVAL;
108 106
109 return 0; 107 return 0;
@@ -116,7 +114,7 @@ EXPORT_SYMBOL(rtc_valid_tm);
116 */ 114 */
117time64_t rtc_tm_to_time64(struct rtc_time *tm) 115time64_t rtc_tm_to_time64(struct rtc_time *tm)
118{ 116{
119 return mktime64(((unsigned)tm->tm_year + 1900), tm->tm_mon + 1, 117 return mktime64(((unsigned int)tm->tm_year + 1900), tm->tm_mon + 1,
120 tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); 118 tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
121} 119}
122EXPORT_SYMBOL(rtc_tm_to_time64); 120EXPORT_SYMBOL(rtc_tm_to_time64);