From patchwork Wed Jan 14 21:25:54 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 18534 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from wa-out-1516.google.com (wa-out-1516.google.com [209.85.146.160]) by ozlabs.org (Postfix) with ESMTP id D6A3ADE0BD for ; Thu, 15 Jan 2009 08:26:35 +1100 (EST) Received: by wa-out-1516.google.com with SMTP id l32so466667waf.1 for ; Wed, 14 Jan 2009 13:26:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received-spf:authentication-results:received :received:date:from:to:cc:subject:message-id:in-reply-to:references :x-mailer:mime-version:content-type:x-spam-status :x-spam-checker-version:x-mimedefang-filter:x-scanned-by:reply-to :sender:precedence:x-google-loop:mailing-list:list-id:list-post :list-help:list-unsubscribe:x-beenthere-env:x-beenthere; bh=mLUGh6Qyr8UnBKG2wileVGzcSkG8cIp9GNTEKGaoo6s=; b=CNZk8bpj5UT07t0jiItIhZZm75iP5B8f2OweFXJ8LIi4VC6ALo10saUXGPnvLsXqr+ /Ne4KEOAHdyIo1RAKlhopnV8iPPpsf8nx/kf++p8yv+9HBO8f+u8yfa0mPIq5vxL5s6h mQdLSjsDAm3lU3W7HYnTttNcbeiebGig9tEXo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results:date :from:to:cc:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:x-spam-status:x-spam-checker-version :x-mimedefang-filter:x-scanned-by:reply-to:sender:precedence :x-google-loop:mailing-list:list-id:list-post:list-help :list-unsubscribe:x-beenthere-env:x-beenthere; b=dMl9wxHnQFRbI4/UXhpPnAg0vfIaTh8HLLKk3FouCrlVcV8SkysWigllerBJlwhAp4 nkhKmYGdCiuE0uHBcnaoFMGnEzpT2RaGdpTVoB1eybRoc6XrtZtzvYAZI6Sl1qrVdkV6 B67KOMSVct8AO+8raeoGANdGBYF64zlhFRWe4= Received: by 10.141.175.5 with SMTP id c5mr47651rvp.22.1231968391807; Wed, 14 Jan 2009 13:26:31 -0800 (PST) Received: by 10.106.212.23 with SMTP id k23gr1802prg.0; Wed, 14 Jan 2009 13:26:31 -0800 (PST) X-Sender: akpm@linux-foundation.org X-Apparently-To: rtc-linux@googlegroups.com Received: by 10.115.48.12 with SMTP id a12mr63166wak.21.1231968391123; Wed, 14 Jan 2009 13:26:31 -0800 (PST) Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by mx.google.com with ESMTP id k32si19120552wah.1.2009.01.14.13.26.31; Wed, 14 Jan 2009 13:26:31 -0800 (PST) Received-SPF: pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.13 as permitted sender) client-ip=140.211.169.13; Authentication-Results: mx.google.com; spf=pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.13 as permitted sender) smtp.mail=akpm@linux-foundation.org Received: from imap1.linux-foundation.org (imap1.linux-foundation.org [140.211.169.55]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id n0ELPtFH024796 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Jan 2009 13:25:56 -0800 Received: from akpm.corp.google.com (localhost [127.0.0.1]) by imap1.linux-foundation.org (8.13.5.20060308/8.13.5/Debian-3ubuntu1.1) with SMTP id n0ELPs8A013992; Wed, 14 Jan 2009 13:25:54 -0800 Date: Wed, 14 Jan 2009 13:25:54 -0800 From: Andrew Morton To: dann frazier Cc: alessandro.zummo@towertech.it, rtc-linux@googlegroups.com, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, eranian@googlemail.com Subject: [rtc-linux] Re: [PATCH] add rtc platform driver for EFI Message-Id: <20090114132554.1efce88f.akpm@linux-foundation.org> In-Reply-To: <20090114173745.GA24492@ldl.fc.hp.com> References: <20090109005644.GH32403@ldl.fc.hp.com> <20090109032729.6e4cd5fd@i1501.lan.towertech.it> <20090109213615.GD31548@ldl.fc.hp.com> <20090113003934.0a7da676.akpm@linux-foundation.org> <20090114000043.GB24423@colo.lackof.org> <20090114011719.GD24423@colo.lackof.org> <20090114023055.1d22d09e@i1501.lan.towertech.it> <20090114041358.GA21357@ldl.fc.hp.com> <20090114043337.GB21357@ldl.fc.hp.com> <20090114115728.15f2db18@i1501.lan.towertech.it> <20090114173745.GA24492@ldl.fc.hp.com> X-Mailer: Sylpheed version 2.2.4 (GTK+ 2.8.20; i486-pc-linux-gnu) Mime-Version: 1.0 X-Spam-Status: No, hits=-4.918 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, PATCH_SUBJECT_OSDL X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.13 Reply-To: rtc-linux@googlegroups.com Sender: rtc-linux@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rtc-linux@googlegroups.com; contact rtc-linux+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rtc-linux@googlegroups.com X-BeenThere: rtc-linux@googlegroups.com On Wed, 14 Jan 2009 10:37:45 -0700 dann frazier 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 - 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 Cc: Alessandro Zummo Cc: stephane eranian Cc: "Luck, Tony" Cc: David Brownell Signed-off-by: Andrew Morton --- 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 #include 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 Use is_leap_year() Cc: "Luck, Tony" Cc: Alessandro Zummo Cc: David Brownell Cc: dann frazier Cc: dann frazier Cc: stephane eranian Signed-off-by: Andrew Morton --- 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);