Skip to content

Commit 78d89ef

Browse files
akpm00torvalds
authored andcommitted
rtc: convert LEAP_YEAR into an inline
- the LEAP_YEAR macro is buggy - it references its arg multiple times. Fix this by turning it into a C function. - give it a more approriate name - Move it to rtc.h so that other .c files can use it, instead of copying it. Cc: dann frazier <dannf@hp.com> Acked-by: Alessandro Zummo <alessandro.zummo@towertech.it> Cc: stephane eranian <eranian@googlemail.com> Cc: "Luck, Tony" <tony.luck@intel.com> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 47367a3 commit 78d89ef

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎drivers/rtc/rtc-lib.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ static const unsigned short rtc_ydays[2][13] = {
2626
};
2727

2828
#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
29-
#define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400))
3029

3130
/*
3231
* The number of days in the month.
3332
*/
3433
int rtc_month_days(unsigned int month, unsigned int year)
3534
{
36-
return rtc_days_in_month[month] + (LEAP_YEAR(year) && month == 1);
35+
return rtc_days_in_month[month] + (is_leap_year(year) && month == 1);
3736
}
3837
EXPORT_SYMBOL(rtc_month_days);
3938

@@ -42,7 +41,7 @@ EXPORT_SYMBOL(rtc_month_days);
4241
*/
4342
int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
4443
{
45-
return rtc_ydays[LEAP_YEAR(year)][month] + day-1;
44+
return rtc_ydays[is_leap_year(year)][month] + day-1;
4645
}
4746
EXPORT_SYMBOL(rtc_year_days);
4847

@@ -66,7 +65,7 @@ void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
6665
- LEAPS_THRU_END_OF(1970 - 1);
6766
if (days < 0) {
6867
year -= 1;
69-
days += 365 + LEAP_YEAR(year);
68+
days += 365 + is_leap_year(year);
7069
}
7170
tm->tm_year = year - 1900;
7271
tm->tm_yday = days + 1;

‎include/linux/rtc.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct rtc_pll_info {
9999

100100
#ifdef __KERNEL__
101101

102+
#include <linux/types.h>
102103
#include <linux/interrupt.h>
103104

104105
extern int rtc_month_days(unsigned int month, unsigned int year);
@@ -232,6 +233,11 @@ int rtc_register(rtc_task_t *task);
232233
int rtc_unregister(rtc_task_t *task);
233234
int rtc_control(rtc_task_t *t, unsigned int cmd, unsigned long arg);
234235

236+
static inline bool is_leap_year(unsigned int year)
237+
{
238+
return (!(year % 4) && (year % 100)) || !(year % 400);
239+
}
240+
235241
#endif /* __KERNEL__ */
236242

237243
#endif /* _LINUX_RTC_H_ */

0 commit comments

Comments
 (0)