From: Joe Perches <joe@perches.com>
To: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com
Subject: Re: [PATCH] rtc: add Abracon ABx80x driver
Date: Sat, 28 Feb 2015 13:22:54 -0800 [thread overview]
Message-ID: <1425158574.31561.1.camel@perches.com> (raw)
In-Reply-To: <20150228205243.GF4094@piout.net>
On Sat, 2015-02-28 at 21:52 +0100, Alexandre Belloni wrote:
> > > diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
> > []
> > > +static int ab08xx_get_datetime(struct i2c_client *client, struct rtc_time *tm)
[]
> > > + tm->tm_sec = bcd2bin(date[AB08XX_REG_SC] & 0x7F);
> > > + tm->tm_min = bcd2bin(date[AB08XX_REG_MN] & 0x7F);
> > > + tm->tm_hour = bcd2bin(date[AB08XX_REG_HR] & 0x3F);
> > > + tm->tm_wday = date[AB08XX_REG_WD] & 0x7;
> > > + tm->tm_mday = bcd2bin(date[AB08XX_REG_DA] & 0x3F);
> > > + tm->tm_mon = bcd2bin(date[AB08XX_REG_MO] & 0x1F) - 1;
> > > + tm->tm_year = bcd2bin(date[AB08XX_REG_YR]);
> > > + if (tm->tm_year < 70)
> > > + tm->tm_year += 100;
> > > +
> > > + err = rtc_valid_tm(tm);
> > > + if (err < 0)
> > > + dev_err(&client->dev, "retrieved date/time is not valid.\n");
> >
> > Is setting the date to a known bad value really the desired thing?
>
> I'm not sure what you mean here, isn't that what is done in almost all
> the rtc drivers?
Dunno.
> A lot of those are simply using return
> rtc_valid_tm(tm); My guess is that a userspace program must not try to
> use tm when errno is not 0.
My thought was that it might be better to
use a local struct rtc_time r like
r.tm_sec = bcd2bin(date[AB08XX_REG_SC] & 0x7F);
r.tm_min = bcd2bin(date[AB08XX_REG_MN] & 0x7F);
r.tm_hour = bcd2bin(date[AB08XX_REG_HR] & 0x3F);
r.tm_wday = date[AB08XX_REG_WD] & 0x7;
r.tm_mday = bcd2bin(date[AB08XX_REG_DA] & 0x3F);
r.tm_mon = bcd2bin(date[AB08XX_REG_MO] & 0x1F) - 1;
r.tm_year = bcd2bin(date[AB08XX_REG_YR]);
if (r.tm_year < 70)
r.tm_year += 100;
err = rtc_valid_tm(&r);
if (!err)
*tm = r;
else
dev_err(&client->dev, "retrieved date/time is not valid\n");
return err;
next prev parent reply other threads:[~2015-02-28 21:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-28 19:14 [PATCH] rtc: add Abracon ABx80x driver Alexandre Belloni
2015-02-28 19:32 ` Joe Perches
2015-02-28 20:52 ` Alexandre Belloni
2015-02-28 21:22 ` Joe Perches [this message]
2015-02-28 23:09 ` Alexandre Belloni
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=1425158574.31561.1.camel@perches.com \
--to=joe@perches.com \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@free-electrons.com \
--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 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.