From: Andrew Morton <akpm@linux-foundation.org>
To: dann frazier <dannf@dannf.org>
Cc: alessandro.zummo@towertech.it, rtc-linux@googlegroups.com,
linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org,
eranian@googlemail.com
Subject: Re: [PATCH] add rtc platform driver for EFI
Date: Wed, 14 Jan 2009 13:25:54 -0800 [thread overview]
Message-ID: <20090114132554.1efce88f.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090114173745.GA24492@ldl.fc.hp.com>
On Wed, 14 Jan 2009 10:37:45 -0700
dann frazier <dannf@dannf.org> wrote:
> +#define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400))
gargh. We should put a tax on #defines to discourage their consumption.
How about we do this:
From: Andrew Morton <akpm@linux-foundation.org>
- 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>
Cc: 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>
---
drivers/rtc/rtc-lib.c | 7 +++----
include/linux/rtc.h | 6 ++++++
2 files changed, 9 insertions(+), 4 deletions(-)
diff -puN drivers/rtc/rtc-lib.c~rtc-convert-leap_year-into-an-inline drivers/rtc/rtc-lib.c
--- a/drivers/rtc/rtc-lib.c~rtc-convert-leap_year-into-an-inline
+++ a/drivers/rtc/rtc-lib.c
@@ -26,14 +26,13 @@ static const unsigned short rtc_ydays[2]
};
#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
-#define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400))
/*
* The number of days in the month.
*/
int rtc_month_days(unsigned int month, unsigned int year)
{
- return rtc_days_in_month[month] + (LEAP_YEAR(year) && month == 1);
+ return rtc_days_in_month[month] + (is_leap_year(year) && month == 1);
}
EXPORT_SYMBOL(rtc_month_days);
@@ -42,7 +41,7 @@ EXPORT_SYMBOL(rtc_month_days);
*/
int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
{
- return rtc_ydays[LEAP_YEAR(year)][month] + day-1;
+ return rtc_ydays[is_leap_year(year)][month] + day-1;
}
EXPORT_SYMBOL(rtc_year_days);
@@ -66,7 +65,7 @@ void rtc_time_to_tm(unsigned long time,
- LEAPS_THRU_END_OF(1970 - 1);
if (days < 0) {
year -= 1;
- days += 365 + LEAP_YEAR(year);
+ days += 365 + is_leap_year(year);
}
tm->tm_year = year - 1900;
tm->tm_yday = days + 1;
diff -puN include/linux/rtc.h~rtc-convert-leap_year-into-an-inline include/linux/rtc.h
--- a/include/linux/rtc.h~rtc-convert-leap_year-into-an-inline
+++ a/include/linux/rtc.h
@@ -99,6 +99,7 @@ struct rtc_pll_info {
#ifdef __KERNEL__
+#include <linux/types.h>
#include <linux/interrupt.h>
extern int rtc_month_days(unsigned int month, unsigned int year);
@@ -232,6 +233,11 @@ int rtc_register(rtc_task_t *task);
int rtc_unregister(rtc_task_t *task);
int rtc_control(rtc_task_t *t, unsigned int cmd, unsigned long arg);
+static inline bool is_leap_year(unsigned int year)
+{
+ return (!(year % 4) && (year % 100)) || !(year % 400);
+}
+
#endif /* __KERNEL__ */
#endif /* _LINUX_RTC_H_ */
_
and then we modify your patch thusly:
From: Andrew Morton <akpm@linux-foundation.org>
Use is_leap_year()
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Alessandro Zummo <alessandro.zummo@towertech.it>
Cc: David Brownell <david-b@pacbell.net>
Cc: dann frazier <dannf@dannf.org>
Cc: dann frazier <dannf@hp.com>
Cc: stephane eranian <eranian@googlemail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
drivers/rtc/rtc-efi.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff -puN arch/ia64/kernel/time.c~rtc-add-platform-driver-for-efi-fix arch/ia64/kernel/time.c
diff -puN drivers/rtc/Kconfig~rtc-add-platform-driver-for-efi-fix drivers/rtc/Kconfig
diff -puN drivers/rtc/Makefile~rtc-add-platform-driver-for-efi-fix drivers/rtc/Makefile
diff -puN drivers/rtc/rtc-efi.c~rtc-add-platform-driver-for-efi-fix drivers/rtc/rtc-efi.c
--- a/drivers/rtc/rtc-efi.c~rtc-add-platform-driver-for-efi-fix
+++ a/drivers/rtc/rtc-efi.c
@@ -26,8 +26,6 @@
*/
#define EFI_RTC_EPOCH 1998
-#define LEAP_YEAR(year) ((!(year % 4) && (year % 100)) || !(year % 400))
-
/*
* returns day of the year [0-365]
*/
@@ -54,7 +52,7 @@ compute_wday(efi_time_t *eft)
}
for (y = EFI_RTC_EPOCH; y < eft->year; y++)
- ndays += 365 + (LEAP_YEAR(y) ? 1 : 0);
+ ndays += 365 + (is_leap_year(y) ? 1 : 0);
ndays += compute_yday(eft);
_
next prev parent reply other threads:[~2009-01-14 21:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-09 0:56 [PATCH] add rtc platform driver for EFI dann frazier
2009-01-09 2:27 ` [rtc-linux] " Alessandro Zummo
2009-01-09 21:34 ` dann frazier
2009-01-09 21:36 ` dann frazier
2009-01-13 8:39 ` Andrew Morton
2009-01-14 0:00 ` dann frazier
2009-01-14 1:17 ` dann frazier
2009-01-14 1:30 ` [rtc-linux] " Alessandro Zummo
2009-01-14 4:13 ` dann frazier
2009-01-14 4:33 ` dann frazier
2009-01-14 10:57 ` Alessandro Zummo
2009-01-14 17:37 ` dann frazier
2009-01-14 21:25 ` Andrew Morton [this message]
2009-01-14 21:39 ` [rtc-linux] " Alessandro Zummo
2009-01-14 21:46 ` dann frazier
2009-01-14 17:39 ` dann frazier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090114132554.1efce88f.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=alessandro.zummo@towertech.it \
--cc=dannf@dannf.org \
--cc=eranian@googlemail.com \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rtc-linux@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox