diff mbox

[15/21] time: Add time64_to_tm()

Message ID 1465448705-25055-16-git-send-email-deepa.kernel@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Deepa Dinamani June 9, 2016, 5:04 a.m. UTC
time_to_tm() takes time_t as an argument.
time_t is not y2038 safe.
Add time64_to_tm() that takes time64_t as an argument
which is y2038 safe.
The plan is to eventually replace all calls to time_to_tm()
by time64_to_tm().

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/time.h   | 15 ++++++++++++++-
 kernel/time/timeconv.c | 11 ++++++-----
 2 files changed, 20 insertions(+), 6 deletions(-)

Comments

John Stultz June 14, 2016, 9:18 p.m. UTC | #1
On Wed, Jun 8, 2016 at 10:04 PM, Deepa Dinamani <deepa.kernel@gmail.com> wrote:
> time_to_tm() takes time_t as an argument.
> time_t is not y2038 safe.
> Add time64_to_tm() that takes time64_t as an argument
> which is y2038 safe.
> The plan is to eventually replace all calls to time_to_tm()
> by time64_to_tm().
>
> Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
> Cc: John Stultz <john.stultz@linaro.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>

This looks sane to me. Are you hoping for me to queue this, or would
you like i to go though the fsdev maintainers with my ack?

In either case.

Acked-by: John Stultz <john.stultz@linaro.org>

thanks
-john
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Deepa Dinamani June 15, 2016, 5:44 p.m. UTC | #2
On Tue, Jun 14, 2016 at 2:18 PM, John Stultz <john.stultz@linaro.org> wrote:
> On Wed, Jun 8, 2016 at 10:04 PM, Deepa Dinamani <deepa.kernel@gmail.com> wrote:
>> time_to_tm() takes time_t as an argument.
>> time_t is not y2038 safe.
>> Add time64_to_tm() that takes time64_t as an argument
>> which is y2038 safe.
>> The plan is to eventually replace all calls to time_to_tm()
>> by time64_to_tm().
>>
>> Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
>> Cc: John Stultz <john.stultz@linaro.org>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>
> This looks sane to me. Are you hoping for me to queue this, or would
> you like i to go though the fsdev maintainers with my ack?
>
> In either case.
>
> Acked-by: John Stultz <john.stultz@linaro.org>

This is only used by the scsi fnic driver.
I will separate these 2 patches from this CURRENT_TIME series and
then both the patches can be merged through the respective trees.

-Deepa
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
John Stultz June 17, 2016, 8:52 p.m. UTC | #3
On Wed, Jun 15, 2016 at 10:44 AM, Deepa Dinamani <deepa.kernel@gmail.com> wrote:
> On Tue, Jun 14, 2016 at 2:18 PM, John Stultz <john.stultz@linaro.org> wrote:
>> On Wed, Jun 8, 2016 at 10:04 PM, Deepa Dinamani <deepa.kernel@gmail.com> wrote:
>>> time_to_tm() takes time_t as an argument.
>>> time_t is not y2038 safe.
>>> Add time64_to_tm() that takes time64_t as an argument
>>> which is y2038 safe.
>>> The plan is to eventually replace all calls to time_to_tm()
>>> by time64_to_tm().
>>>
>>> Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
>>> Cc: John Stultz <john.stultz@linaro.org>
>>> Cc: Thomas Gleixner <tglx@linutronix.de>
>>
>> This looks sane to me. Are you hoping for me to queue this, or would
>> you like i to go though the fsdev maintainers with my ack?
>>
>> In either case.
>>
>> Acked-by: John Stultz <john.stultz@linaro.org>
>
> This is only used by the scsi fnic driver.
> I will separate these 2 patches from this CURRENT_TIME series and
> then both the patches can be merged through the respective trees.

Sorry, this was not quite clear. I've gone ahead and queued this one
patch for testing, but let me know and I'll drop it if its going
through a different tree.

thanks
-john
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Deepa Dinamani June 17, 2016, 8:59 p.m. UTC | #4
On Fri, Jun 17, 2016 at 1:52 PM, John Stultz <john.stultz@linaro.org> wrote:
> On Wed, Jun 15, 2016 at 10:44 AM, Deepa Dinamani <deepa.kernel@gmail.com> wrote:
>> On Tue, Jun 14, 2016 at 2:18 PM, John Stultz <john.stultz@linaro.org> wrote:
>>> On Wed, Jun 8, 2016 at 10:04 PM, Deepa Dinamani <deepa.kernel@gmail.com> wrote:
>>>> time_to_tm() takes time_t as an argument.
>>>> time_t is not y2038 safe.
>>>> Add time64_to_tm() that takes time64_t as an argument
>>>> which is y2038 safe.
>>>> The plan is to eventually replace all calls to time_to_tm()
>>>> by time64_to_tm().
>>>>
>>>> Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
>>>> Cc: John Stultz <john.stultz@linaro.org>
>>>> Cc: Thomas Gleixner <tglx@linutronix.de>
>>>
>>> This looks sane to me. Are you hoping for me to queue this, or would
>>> you like i to go though the fsdev maintainers with my ack?
>>>
>>> In either case.
>>>
>>> Acked-by: John Stultz <john.stultz@linaro.org>
>>
>> This is only used by the scsi fnic driver.
>> I will separate these 2 patches from this CURRENT_TIME series and
>> then both the patches can be merged through the respective trees.
>
> Sorry, this was not quite clear. I've gone ahead and queued this one
> patch for testing, but let me know and I'll drop it if its going
> through a different tree.

Ok.This works too.

Thanks,
Deepa
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Arnd Bergmann June 17, 2016, 9:06 p.m. UTC | #5
On Friday, June 17, 2016 1:59:06 PM CEST Deepa Dinamani wrote:
> On Fri, Jun 17, 2016 at 1:52 PM, John Stultz <john.stultz@linaro.org> wrote:
> > On Wed, Jun 15, 2016 at 10:44 AM, Deepa Dinamani <deepa.kernel@gmail.com> wrote:
> >> On Tue, Jun 14, 2016 at 2:18 PM, John Stultz <john.stultz@linaro.org> wrote:
> >>> On Wed, Jun 8, 2016 at 10:04 PM, Deepa Dinamani <deepa.kernel@gmail.com> wrote:
> >>>> time_to_tm() takes time_t as an argument.
> >>>> time_t is not y2038 safe.
> >>>> Add time64_to_tm() that takes time64_t as an argument
> >>>> which is y2038 safe.
> >>>> The plan is to eventually replace all calls to time_to_tm()
> >>>> by time64_to_tm().
> >>>>
> >>>> Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
> >>>> Cc: John Stultz <john.stultz@linaro.org>
> >>>> Cc: Thomas Gleixner <tglx@linutronix.de>
> >>>
> >>> This looks sane to me. Are you hoping for me to queue this, or would
> >>> you like i to go though the fsdev maintainers with my ack?
> >>>
> >>> In either case.
> >>>
> >>> Acked-by: John Stultz <john.stultz@linaro.org>
> >>
> >> This is only used by the scsi fnic driver.
> >> I will separate these 2 patches from this CURRENT_TIME series and
> >> then both the patches can be merged through the respective trees.
> >
> > Sorry, this was not quite clear. I've gone ahead and queued this one
> > patch for testing, but let me know and I'll drop it if its going
> > through a different tree.
> 
> Ok.This works too.

Actually I have three more patches for other drivers that could use the
time64_to_tm() function. I'll post them next week and we can decide whether
we want to queue the driver changes on top (with the respective Ack).

	Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/time.h b/include/linux/time.h
index 297f09f..4cea09d 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -205,7 +205,20 @@  struct tm {
 	int tm_yday;
 };
 
-void time_to_tm(time_t totalsecs, int offset, struct tm *result);
+void time64_to_tm(time64_t totalsecs, int offset, struct tm *result);
+
+/**
+ * time_to_tm - converts the calendar time to local broken-down time
+ *
+ * @totalsecs	the number of seconds elapsed since 00:00:00 on January 1, 1970,
+ *		Coordinated Universal Time (UTC).
+ * @offset	offset seconds adding to totalsecs.
+ * @result	pointer to struct tm variable to receive broken-down time
+ */
+static inline void time_to_tm(time_t totalsecs, int offset, struct tm *result)
+{
+	time64_to_tm(totalsecs, offset, result);
+}
 
 /**
  * timespec_to_ns - Convert timespec to nanoseconds
diff --git a/kernel/time/timeconv.c b/kernel/time/timeconv.c
index 86628e7..7142580 100644
--- a/kernel/time/timeconv.c
+++ b/kernel/time/timeconv.c
@@ -67,20 +67,21 @@  static const unsigned short __mon_yday[2][13] = {
 #define SECS_PER_DAY	(SECS_PER_HOUR * 24)
 
 /**
- * time_to_tm - converts the calendar time to local broken-down time
+ * time64_to_tm - converts the calendar time to local broken-down time
  *
  * @totalsecs	the number of seconds elapsed since 00:00:00 on January 1, 1970,
  *		Coordinated Universal Time (UTC).
  * @offset	offset seconds adding to totalsecs.
  * @result	pointer to struct tm variable to receive broken-down time
  */
-void time_to_tm(time_t totalsecs, int offset, struct tm *result)
+void time64_to_tm(time64_t totalsecs, int offset, struct tm *result)
 {
 	long days, rem, y;
+	int remainder;
 	const unsigned short *ip;
 
-	days = totalsecs / SECS_PER_DAY;
-	rem = totalsecs % SECS_PER_DAY;
+	days = div_s64_rem(totalsecs, SECS_PER_DAY, &remainder);
+	rem = remainder;
 	rem += offset;
 	while (rem < 0) {
 		rem += SECS_PER_DAY;
@@ -124,4 +125,4 @@  void time_to_tm(time_t totalsecs, int offset, struct tm *result)
 	result->tm_mon = y;
 	result->tm_mday = days + 1;
 }
-EXPORT_SYMBOL(time_to_tm);
+EXPORT_SYMBOL(time64_to_tm);