* [PATCH RESEND 0/2] rtc: initial patches to fix borkage of rtc-s35390a
@ 2016-05-11 7:11 Uwe Kleine-König
2016-05-11 7:11 ` [rtc-linux] [PATCH RESEND 1/2] rtc: initialize output parameter for read alarm to "uninitialized" Uwe Kleine-König
2016-05-11 7:11 ` [rtc-linux] [PATCH RESEND 2/2] rtc: make rtc_time64_to_tm save to use for dates before 1970 Uwe Kleine-König
0 siblings, 2 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2016-05-11 7:11 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni
Cc: rtc-linux, Michael Langer, Byron Bradley, Manuel Röder
Hello,
[I'm resending because only a single patch made it to the rtc list, don't know
why.]
here are two patches that improve the rtc core's robustness regarding
stuff the rtc-s35390a does. That is in .read_alarm it only assigns
alm->time.tm_wday, alm->time.tm_hour and alm->time.tm_min which as of
now makes the kernel report things like:
[ 2.257418] rtc rtc0: invalid alarm value: 1900-1-29 1193031:57:16
.
The open issues (I'm aware of) but which are orthogonal to the patches
here are:
- The core doesn't handle a driver setting alm->time.tm_wday but not
alm->time.tm_mday.
- The chip has status bits that signal if an irq is pending, but these
are cleared at read and the first read during driver probe doesn't
check for these bits set. (There are more such read-to-clear bits,
e.g. when the battery backing was lost ...)
The result is that the irq isn't acked (by unsetting INT2AE) which
prevents some devices (e.g. QNAP TS-41x) to shutdown.
(https://bugs.debian.org/794266)
So with the two patches in this series the QNAP TS-41x still fails to
shutdown, but it is handled a bit better.
I'd consider this merge window material.
Uwe Kleine-König (2):
rtc: initialize output parameter for read alarm to "uninitialized"
rtc: make rtc_time64_to_tm save to use for dates before 1970
drivers/rtc/interface.c | 12 +++++++++++-
drivers/rtc/rtc-lib.c | 13 +++++++++----
2 files changed, 20 insertions(+), 5 deletions(-)
--
2.8.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [rtc-linux] [PATCH RESEND 1/2] rtc: initialize output parameter for read alarm to "uninitialized"
2016-05-11 7:11 [PATCH RESEND 0/2] rtc: initial patches to fix borkage of rtc-s35390a Uwe Kleine-König
@ 2016-05-11 7:11 ` Uwe Kleine-König
2016-05-29 23:27 ` [rtc-linux] " Alexandre Belloni
2016-05-11 7:11 ` [rtc-linux] [PATCH RESEND 2/2] rtc: make rtc_time64_to_tm save to use for dates before 1970 Uwe Kleine-König
1 sibling, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2016-05-11 7:11 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni
Cc: rtc-linux, Michael Langer, Byron Bradley, Manuel Röder
rtc drivers are supposed to set values they don't support to -1. To
simplify this for drivers and also make it harder for them to get it
wrong initialize the values to -1.
Signed-off-by: Uwe Kleine-K=C3=B6nig <uwe@kleine-koenig.org>
---
drivers/rtc/interface.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 9ef5f6f89f98..99475908e556 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -104,7 +104,17 @@ static int rtc_read_alarm_internal(struct rtc_device *=
rtc, struct rtc_wkalrm *al
else if (!rtc->ops->read_alarm)
err =3D -EINVAL;
else {
- memset(alarm, 0, sizeof(struct rtc_wkalrm));
+ alarm->enabled =3D 0;
+ alarm->pending =3D 0;
+ alarm->time.tm_sec =3D -1;
+ alarm->time.tm_min =3D -1;
+ alarm->time.tm_hour =3D -1;
+ alarm->time.tm_mday =3D -1;
+ alarm->time.tm_mon =3D -1;
+ alarm->time.tm_year =3D -1;
+ alarm->time.tm_wday =3D -1;
+ alarm->time.tm_yday =3D -1;
+ alarm->time.tm_isdst =3D -1;
err =3D rtc->ops->read_alarm(rtc->dev.parent, alarm);
}
=20
--=20
2.8.1
--=20
--=20
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "=
rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [rtc-linux] [PATCH RESEND 2/2] rtc: make rtc_time64_to_tm save to use for dates before 1970
2016-05-11 7:11 [PATCH RESEND 0/2] rtc: initial patches to fix borkage of rtc-s35390a Uwe Kleine-König
2016-05-11 7:11 ` [rtc-linux] [PATCH RESEND 1/2] rtc: initialize output parameter for read alarm to "uninitialized" Uwe Kleine-König
@ 2016-05-11 7:11 ` Uwe Kleine-König
1 sibling, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2016-05-11 7:11 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni
Cc: rtc-linux, Michael Langer, Byron Bradley, Manuel Röder
When the time parameter to rtc_time64_to_tm is negative and so
represents a date before 1970 several outputs were calculated wrongly.
A comment in the code signaled that the code doesn't handle negative
times but that didn't stop __rtc_read_alarm to still pass negative
values.
For example with time=3D-2208565980 (1900-01-05 21:27 UTC) the days variabl=
e
was assigned a negative value (-25562) which was then used to calculate
secs =3D time - (unsigned int) days * 86400;
resulting in an overflow in both the multiplication and the subtraction
yielding secs =3D 4294958116 which is then used to calculate
tm_hour =3D 1193043; tm_min =3D 55; tm_sec =3D 16.
With the changes in this patch the time stamp from the example above is
converted correctly.
Signed-off-by: Uwe Kleine-K=C3=B6nig <uwe@kleine-koenig.org>
---
drivers/rtc/rtc-lib.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index e6bfb9c42a10..0140ce7088ac 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -53,15 +53,20 @@ EXPORT_SYMBOL(rtc_year_days);
void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
{
unsigned int month, year;
- unsigned long secs;
+ s32 secs
int days;
=20
- /* time must be positive */
- days =3D div_s64(time, 86400);
- secs =3D time - (unsigned int) days * 86400;
+ days =3D div_s64_rem(time, 86400, &secs);
+
+ if (secs < 0) {
+ secs +=3D 86400;
+ days -=3D 1;
+ }
=20
/* day of the week, 1970-01-01 was a Thursday */
tm->tm_wday =3D (days + 4) % 7;
+ if (tm->tm_wday < 0)
+ tm->tm_wday +=3D 7;
=20
year =3D 1970 + days / 365;
days -=3D (year - 1970) * 365
--=20
2.8.1
--=20
--=20
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "=
rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [rtc-linux] Re: [PATCH RESEND 1/2] rtc: initialize output parameter for read alarm to "uninitialized"
2016-05-11 7:11 ` [rtc-linux] [PATCH RESEND 1/2] rtc: initialize output parameter for read alarm to "uninitialized" Uwe Kleine-König
@ 2016-05-29 23:27 ` Alexandre Belloni
0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2016-05-29 23:27 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Alessandro Zummo, rtc-linux, Michael Langer, Byron Bradley,
Manuel Röder
On 11/05/2016 at 09:11:23 +0200, Uwe Kleine-K=C3=B6nig wrote :
> rtc drivers are supposed to set values they don't support to -1. To
> simplify this for drivers and also make it harder for them to get it
> wrong initialize the values to -1.
>=20
> Signed-off-by: Uwe Kleine-K=C3=B6nig <uwe@kleine-koenig.org>
> ---
> drivers/rtc/interface.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>=20
Applied, thanks.
--=20
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
--=20
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "=
rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-05-29 23:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-11 7:11 [PATCH RESEND 0/2] rtc: initial patches to fix borkage of rtc-s35390a Uwe Kleine-König
2016-05-11 7:11 ` [rtc-linux] [PATCH RESEND 1/2] rtc: initialize output parameter for read alarm to "uninitialized" Uwe Kleine-König
2016-05-29 23:27 ` [rtc-linux] " Alexandre Belloni
2016-05-11 7:11 ` [rtc-linux] [PATCH RESEND 2/2] rtc: make rtc_time64_to_tm save to use for dates before 1970 Uwe Kleine-König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox