* [PATCH] rtc: Fix overflow when converting time64_t to rtc_time
@ 2018-01-26 5:06 ` Baolin Wang
0 siblings, 0 replies; 6+ messages in thread
From: Baolin Wang @ 2017-12-25 11:10 UTC (permalink / raw)
To: a.zummo, alexandre.belloni
Cc: arnd, broonie, linux-rtc, linux-kernel, baolin.wang
If we convert one large time values to rtc_time, in the original formula
'days * 86400' can be overflowed in 'unsigned int' type to make the formula
get one incorrect remain seconds value. Thus we can use div_s64_rem()
function to avoid this situation.
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
drivers/rtc/rtc-lib.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 1ae7da5..ad5bb21 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -52,13 +52,11 @@ int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
*/
void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
{
- unsigned int month, year;
- unsigned long secs;
+ unsigned int month, year, secs;
int days;
/* time must be positive */
- days = div_s64(time, 86400);
- secs = time - (unsigned int) days * 86400;
+ days = div_s64_rem(time, 86400, &secs);
/* day of the week, 1970-01-01 was a Thursday */
tm->tm_wday = (days + 4) % 7;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] rtc: Fix overflow when converting time64_t to rtc_time
2018-01-26 5:06 ` [RESEND PATCH] " Baolin Wang
(?)
@ 2018-01-08 6:00 ` Baolin Wang
-1 siblings, 0 replies; 6+ messages in thread
From: Baolin Wang @ 2018-01-08 6:00 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni
Cc: Arnd Bergmann, Mark Brown, linux-rtc, LKML, Baolin Wang
Hi Alexandre,
On 25 December 2017 at 19:10, Baolin Wang <baolin.wang@linaro.org> wrote:
> If we convert one large time values to rtc_time, in the original formula
> 'days * 86400' can be overflowed in 'unsigned int' type to make the formula
> get one incorrect remain seconds value. Thus we can use div_s64_rem()
> function to avoid this situation.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Could you apply this patch if there are no other comments? Thanks.
> ---
> drivers/rtc/rtc-lib.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
> index 1ae7da5..ad5bb21 100644
> --- a/drivers/rtc/rtc-lib.c
> +++ b/drivers/rtc/rtc-lib.c
> @@ -52,13 +52,11 @@ int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
> */
> void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
> {
> - unsigned int month, year;
> - unsigned long secs;
> + unsigned int month, year, secs;
> int days;
>
> /* time must be positive */
> - days = div_s64(time, 86400);
> - secs = time - (unsigned int) days * 86400;
> + days = div_s64_rem(time, 86400, &secs);
>
> /* day of the week, 1970-01-01 was a Thursday */
> tm->tm_wday = (days + 4) % 7;
> --
> 1.7.9.5
>
--
Baolin.wang
Best Regards
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RESEND PATCH] rtc: Fix overflow when converting time64_t to rtc_time
@ 2018-01-26 5:06 ` Baolin Wang
0 siblings, 0 replies; 6+ messages in thread
From: Baolin Wang @ 2018-01-26 5:06 UTC (permalink / raw)
To: a.zummo, alexandre.belloni
Cc: arnd, broonie, linux-rtc, linux-kernel, baolin.wang
If we convert one large time values to rtc_time, in the original formula
'days * 86400' can be overflowed in 'unsigned int' type to make the formula
get one incorrect remain seconds value. Thus we can use div_s64_rem()
function to avoid this situation.
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
drivers/rtc/rtc-lib.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 1ae7da5..ad5bb21 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -52,13 +52,11 @@ int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
*/
void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
{
- unsigned int month, year;
- unsigned long secs;
+ unsigned int month, year, secs;
int days;
/* time must be positive */
- days = div_s64(time, 86400);
- secs = time - (unsigned int) days * 86400;
+ days = div_s64_rem(time, 86400, &secs);
/* day of the week, 1970-01-01 was a Thursday */
tm->tm_wday = (days + 4) % 7;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RESEND PATCH] rtc: Fix overflow when converting time64_t to rtc_time
2018-01-26 5:06 ` [RESEND PATCH] " Baolin Wang
(?)
(?)
@ 2018-01-26 9:24 ` Arnd Bergmann
2018-02-06 4:00 ` Baolin Wang
-1 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2018-01-26 9:24 UTC (permalink / raw)
To: Baolin Wang
Cc: Alessandro Zummo, Alexandre Belloni, Mark Brown, linux-rtc,
Linux Kernel Mailing List
On Fri, Jan 26, 2018 at 6:06 AM, Baolin Wang <baolin.wang@linaro.org> wrote:
> If we convert one large time values to rtc_time, in the original formula
> 'days * 86400' can be overflowed in 'unsigned int' type to make the formula
> get one incorrect remain seconds value. Thus we can use div_s64_rem()
> function to avoid this situation.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RESEND PATCH] rtc: Fix overflow when converting time64_t to rtc_time
2018-01-26 9:24 ` [RESEND PATCH] " Arnd Bergmann
@ 2018-02-06 4:00 ` Baolin Wang
0 siblings, 0 replies; 6+ messages in thread
From: Baolin Wang @ 2018-02-06 4:00 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Alessandro Zummo, Alexandre Belloni, Mark Brown, linux-rtc,
Linux Kernel Mailing List
Hi Alexandre,
On 26 January 2018 at 17:24, Arnd Bergmann <arnd@arndb.de> wrote:
> On Fri, Jan 26, 2018 at 6:06 AM, Baolin Wang <baolin.wang@linaro.org> wrote:
>> If we convert one large time values to rtc_time, in the original formula
>> 'days * 86400' can be overflowed in 'unsigned int' type to make the formula
>> get one incorrect remain seconds value. Thus we can use div_s64_rem()
>> function to avoid this situation.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
>
> Acked-by: Arnd Bergmann <arnd@arndb.de>
Could you apply this patch? Since it was pending for a while and it is
a bug fix. Thanks.
--
Baolin.wang
Best Regards
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RESEND PATCH] rtc: Fix overflow when converting time64_t to rtc_time
2018-01-26 5:06 ` [RESEND PATCH] " Baolin Wang
` (2 preceding siblings ...)
(?)
@ 2018-02-13 20:32 ` Alexandre Belloni
-1 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2018-02-13 20:32 UTC (permalink / raw)
To: Baolin Wang; +Cc: a.zummo, arnd, broonie, linux-rtc, linux-kernel
On 26/01/2018 at 13:06:01 +0800, Baolin Wang wrote:
> If we convert one large time values to rtc_time, in the original formula
> 'days * 86400' can be overflowed in 'unsigned int' type to make the formula
> get one incorrect remain seconds value. Thus we can use div_s64_rem()
> function to avoid this situation.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
> drivers/rtc/rtc-lib.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
Applied, thanks.
--
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-02-13 20:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-25 11:10 [PATCH] rtc: Fix overflow when converting time64_t to rtc_time Baolin Wang
2018-01-26 5:06 ` [RESEND PATCH] " Baolin Wang
2018-01-08 6:00 ` [PATCH] " Baolin Wang
2018-01-26 9:24 ` [RESEND PATCH] " Arnd Bergmann
2018-02-06 4:00 ` Baolin Wang
2018-02-13 20:32 ` Alexandre Belloni
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.