From patchwork Sun Aug 27 11:30:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 9923777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5B01B60375 for ; Sun, 27 Aug 2017 11:31:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4858C285EE for ; Sun, 27 Aug 2017 11:31:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CF4B28616; Sun, 27 Aug 2017 11:31:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B977A285EE for ; Sun, 27 Aug 2017 11:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gaeWe9uw7X7HegdxpSHgLzcJ/2M+jN0lC4lm4Qm4q8w=; b=IKECH8mTm8PtLT ZFr3xMRI7Waerqq9ftNxHL2FGr/0mrlxUp/QldFgmFsprTWEfwMp5myPOP3+ji3unLPiwghHmvDNB MuJbzUn4m9La/yD3JmoTEpQBwO42+am67mxDHwTCP7Yk2VDAETCc6jgb2y+4Pkc1jkb71rdvaNAXE QBOnAx5sabMNenWHtQSXUMJdxjRjjBaLVXoEMgMXtmsBSxCvG0Orz9teAQiwMYyTbbWKWg3ZMOl3H XJQfgGmF5iGkL6WVhFNwwcg0w7+oQy8kT4R3uAx4XuTem6UV31ia9olmxNiut/3IU8POHJyeOmGfm yJAo+5yuIevdyXAwcJFA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dlvmq-0005Ca-UJ; Sun, 27 Aug 2017 11:31:28 +0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dlvmn-0005Ad-3o for linux-arm-kernel@lists.infradead.org; Sun, 27 Aug 2017 11:31:27 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C69EAAAB6; Sun, 27 Aug 2017 11:31:01 +0000 (UTC) Subject: Re: [PATCH v2 2/3] rtc: Add Realtek RTD1295 To: Alexandre Belloni References: <20170827003328.28370-1-afaerber@suse.de> <20170827003328.28370-3-afaerber@suse.de> <20170827091301.wbuzxkh7opz4blrc@piout.net> From: =?UTF-8?Q?Andreas_F=c3=a4rber?= Organization: SUSE Linux GmbH Message-ID: Date: Sun, 27 Aug 2017 13:30:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170827091301.wbuzxkh7opz4blrc@piout.net> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170827_043125_489741_F0B31879 X-CRM114-Status: GOOD ( 15.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-rtc@vger.kernel.org, Alessandro Zummo , Roc He , Andrew Lunn , =?UTF-8?B?6JKL5Li955C0?= , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Alexandre, Am 27.08.2017 um 11:13 schrieb Alexandre Belloni: > Not much to add, apart from the spinlock issue already spotted by Andrew. > > On 27/08/2017 at 02:33:27 +0200, Andreas Färber wrote: >> +struct rtd119x_rtc { >> + void __iomem *base; >> + struct clk *clk; >> + struct rtc_device *rtcdev; >> + unsigned base_year; > > checkpatch complains this should be made unsigned int Ouch, I forgot to add my pre-commit hook in this tree and wasn't aware of that rule yet. The RFC had it already. Fixed. >> + spinlock_t lock; >> +}; >> + >> +static inline int rtd119x_rtc_year_days(int year) >> +{ >> + return rtc_year_days(1, 12, year); > > I'm not sure it is worth wrapping rtc_year_days [snip] Well, I found your rtc_year_days rather confusing and had to play with the arguments until I got it working as expected, so I wanted an inline function (or macro) as abstraction from my three callers. Sadly the naming is rather confusing as I am looking for the number of days 365..366, whereas your rtc_year_days is meant to return 0..365 and I would just like to extract the 12th array element but need to counter the -1 subtraction. rtc_year_days(31, 11, year) + 1 is not intuitive either - reads like November (and ranges are not documented). What about exporting a convenient rtc_days_in_year(year) from rtc-lib.c accessing the table directly without rtc_year_days detour? Alternatively an inline function in rtc.h to the same effect without the array? Also despite is_leap_year() returning a bool || expression you keep using it as array index or integer to add. That assumes true == 1, whereas to my knowledge only false is guaranteed to be 0 and any non-zero value means true. So I'd expect the code to be like this: EXPORT_SYMBOL(rtc_month_days); @@ -41,7 +41,7 @@ EXPORT_SYMBOL(rtc_month_days); */ int rtc_year_days(unsigned int day, unsigned int month, unsigned int year) { - return rtc_ydays[is_leap_year(year)][month] + day-1; + return rtc_ydays[is_leap_year(year) ? 1 : 0][month] + day-1; } EXPORT_SYMBOL(rtc_year_days); @@ -69,7 +69,7 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm) - LEAPS_THRU_END_OF(1970 - 1); if (days < 0) { year -= 1; - days += 365 + is_leap_year(year); + days += 365 + (is_leap_year(year) ? 1 : 0); } tm->tm_year = year - 1900; tm->tm_yday = days + 1; The above rtc_time64_to_tm() hunk could be converted to the proposed rtc_days_in_year(). rtc-mcp795.c has another candidate. By reusing rtc_year_days I elegantly avoided is_leap_year in my code, but I could spell out 365 + (is_leap_year(year) ? 1 : 0) in my function if preferred. I dislike duplicating expressions in code. What do you think? Regards, Andreas diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c index 1ae7da5cfc60..8983a408fc30 100644 --- a/drivers/rtc/rtc-lib.c +++ b/drivers/rtc/rtc-lib.c @@ -32,7 +32,7 @@ static const unsigned short rtc_ydays[2][13] = { */ int rtc_month_days(unsigned int month, unsigned int year) { - return rtc_days_in_month[month] + (is_leap_year(year) && month == 1); + return rtc_days_in_month[month] + ((is_leap_year(year) && month == 1) ? 1 : 0); }