[PATCH] rtc: rtc-mc146818-lib: Use is_leap_year instead of calculate leap years

Nobuhiro Iwamatsu posted 1 patch 1 month, 3 weeks ago
There is a newer version of this series
drivers/rtc/rtc-mc146818-lib.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] rtc: rtc-mc146818-lib: Use is_leap_year instead of calculate leap years
Posted by Nobuhiro Iwamatsu 1 month, 3 weeks ago
The is_leap_year() for determining leap year is provided in rtc lib.
This uses is_leap_year() instead of its own leap year determination
routine.

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
---
 drivers/rtc/rtc-mc146818-lib.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c
index 651bf3c279c74..ce4d68de05831 100644
--- a/drivers/rtc/rtc-mc146818-lib.c
+++ b/drivers/rtc/rtc-mc146818-lib.c
@@ -232,8 +232,7 @@ int mc146818_set_time(struct rtc_time *time)
 
 #ifdef CONFIG_MACH_DECSTATION
 	real_yrs = yrs;
-	leap_yr = ((!((yrs + 1900) % 4) && ((yrs + 1900) % 100)) ||
-			!((yrs + 1900) % 400));
+	leap_yr = is_leap_year(yrs + 1900);
 	yrs = 72;
 
 	/*
-- 
2.45.2
Re: [PATCH] rtc: rtc-mc146818-lib: Use is_leap_year instead of calculate leap years
Posted by Alexandre Belloni 1 month, 3 weeks ago
Hello,

On 06/10/2024 09:15:53+0900, Nobuhiro Iwamatsu wrote:
> The is_leap_year() for determining leap year is provided in rtc lib.
> This uses is_leap_year() instead of its own leap year determination
> routine.
> 
> Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
> ---
>  drivers/rtc/rtc-mc146818-lib.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c
> index 651bf3c279c74..ce4d68de05831 100644
> --- a/drivers/rtc/rtc-mc146818-lib.c
> +++ b/drivers/rtc/rtc-mc146818-lib.c
> @@ -232,8 +232,7 @@ int mc146818_set_time(struct rtc_time *time)
>  
>  #ifdef CONFIG_MACH_DECSTATION
>  	real_yrs = yrs;
> -	leap_yr = ((!((yrs + 1900) % 4) && ((yrs + 1900) % 100)) ||
> -			!((yrs + 1900) % 400));
> +	leap_yr = is_leap_year(yrs + 1900);

Could you also eliminate the leap_yr variable?

Thanks!

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Re: [PATCH] rtc: rtc-mc146818-lib: Use is_leap_year instead of calculate leap years
Posted by Nobuhiro Iwamatsu 1 month, 2 weeks ago
Hi,

2024年10月7日(月) 22:59 Alexandre Belloni <alexandre.belloni@bootlin.com>:
>
> Hello,
>
> On 06/10/2024 09:15:53+0900, Nobuhiro Iwamatsu wrote:
> > The is_leap_year() for determining leap year is provided in rtc lib.
> > This uses is_leap_year() instead of its own leap year determination
> > routine.
> >
> > Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
> > ---
> >  drivers/rtc/rtc-mc146818-lib.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c
> > index 651bf3c279c74..ce4d68de05831 100644
> > --- a/drivers/rtc/rtc-mc146818-lib.c
> > +++ b/drivers/rtc/rtc-mc146818-lib.c
> > @@ -232,8 +232,7 @@ int mc146818_set_time(struct rtc_time *time)
> >
> >  #ifdef CONFIG_MACH_DECSTATION
> >       real_yrs = yrs;
> > -     leap_yr = ((!((yrs + 1900) % 4) && ((yrs + 1900) % 100)) ||
> > -                     !((yrs + 1900) % 400));
> > +     leap_yr = is_leap_year(yrs + 1900);
>
> Could you also eliminate the leap_yr variable?
>

Yes, I will send v2  patch that deleted it.

> Thanks!

Best regards,
  Nobuhiro

-- 
Nobuhiro Iwamatsu
   iwamatsu at {nigauri.org / debian.org / kernel.org}
   GPG ID: 32247FBB40AD1FA6
Re: [PATCH] rtc: rtc-mc146818-lib: Use is_leap_year instead of calculate leap years
Posted by Maciej W. Rozycki 1 month, 3 weeks ago
On Sun, 6 Oct 2024, Nobuhiro Iwamatsu wrote:

> The is_leap_year() for determining leap year is provided in rtc lib.
> This uses is_leap_year() instead of its own leap year determination
> routine.

 Good catch!  As a DECstation maintainer:

Acked-by: Maciej W. Rozycki <macro@orcam.me.uk>

Thank you for making this clean-up to this 22 years old code!

  Maciej