All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
To: qxj511mail@gmail.com
Cc: Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	linux-rtc@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	qiuxiaojin@cvte.com
Subject: Re: [PATCH] rtc: rs5c372: Fix read the time from RTC is illegal When reading time from an uninitialized RTC chip, The value may be illegal
Date: Mon, 24 May 2021 13:40:48 +0900	[thread overview]
Message-ID: <CABMQnV+5gN_6BA4tYS+GugrA0HrQD9+_EkQk_emqsUy1YzFCOA@mail.gmail.com> (raw)
In-Reply-To: <20210520033156.23209-1-qxj511mail@gmail.com>

Hi,

2021年5月20日(木) 12:32 <qxj511mail@gmail.com>:
>
> From: qiuxiaojin <qiuxiaojin@cvte.com>

Please briefly describe the patch contained in the email to the subject.
And, please write a description of the patch in the text

>
> Signed-off-by: qiuxiaojin <qiuxiaojin@cvte.com>
> ---
>  drivers/rtc/rtc-rs5c372.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
> index 3bd6eaa0dcf6..ce61e15d5f3a 100644
> --- a/drivers/rtc/rtc-rs5c372.c
> +++ b/drivers/rtc/rtc-rs5c372.c
> @@ -212,6 +212,7 @@ static int rs5c372_rtc_read_time(struct device *dev, struct rtc_time *tm)
>         struct rs5c372  *rs5c = i2c_get_clientdata(client);
>         int             status = rs5c_get_regs(rs5c);
>         unsigned char ctrl2 = rs5c->regs[RS5C_REG_CTRL2];
> +       int flags_utime = 0;
>
>         if (status < 0)
>                 return status;
> @@ -239,12 +240,27 @@ static int rs5c372_rtc_read_time(struct device *dev, struct rtc_time *tm)
>         tm->tm_wday = bcd2bin(rs5c->regs[RS5C372_REG_WDAY] & 0x07);
>         tm->tm_mday = bcd2bin(rs5c->regs[RS5C372_REG_DAY] & 0x3f);
>
> +       if (tm->tm_mday < 1) {
> +               // The value read from the register may be zero, which is an illegal value

Please use C89 style commet (/* */).

> +               flags_utime = flags_utime + 1;

I like using ++ (flags_utime++).

> +               tm->tm_mday = 1;
> +       }
> +
>         /* tm->tm_mon is zero-based */
>         tm->tm_mon = bcd2bin(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1;
>
> +       if (tm->tm_mon < 0) {
> +               flags_utime = flags_utime + 1;
> +               tm->tm_mday = 0;
> +       }
> +
>         /* year is 1900 + tm->tm_year */
>         tm->tm_year = bcd2bin(rs5c->regs[RS5C372_REG_YEAR]) + 100;
>
> +       if (flags_utime > 0) {

{} is unnecessary.

> +               rs5c372_rtc_set_time(dev, tm);

A build error will occur because there is no declaration of
rs5c372_rtc_set_time.
Please make sure this can be compiled.

> +       }
> +
>         dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
>                 "mday=%d, mon=%d, year=%d, wday=%d\n",
>                 __func__,
> --
> 2.29.0
>


-- 
Nobuhiro Iwamatsu
   iwamatsu at {nigauri.org / debian.org}
   GPG ID: 40AD1FA6

  reply	other threads:[~2021-05-24  4:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-20  3:31 [PATCH] rtc: rs5c372: Fix read the time from RTC is illegal When reading time from an uninitialized RTC chip, The value may be illegal qxj511mail
2021-05-24  4:40 ` Nobuhiro Iwamatsu [this message]
     [not found]   ` <202105251924130320028@gmail.com>
2021-05-25 21:18     ` Alexandre Belloni
     [not found]       ` <202105261935305975621@gmail.com>
2021-05-26 12:12         ` Alexandre Belloni
2021-05-21  2:40 qxj511mail
2021-05-22 17:22 ` kernel test robot
2021-05-22 17:22   ` kernel test robot

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=CABMQnV+5gN_6BA4tYS+GugrA0HrQD9+_EkQk_emqsUy1YzFCOA@mail.gmail.com \
    --to=iwamatsu@nigauri.org \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=qiuxiaojin@cvte.com \
    --cc=qxj511mail@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.