struct timeval will overflow on 32-bit systems in y2038.
Replace the use of struct timeval and do_gettimeofday() with 64 bit
ktime_get_real_seconds.

gdth uses the seconds portion of timeval in two places:
1) in an unsigned-32 timestamp field in the ioctl GDTIOCTL_EVENT
2) in an int defined local var to calculate elapsed time for a debug msg

Use ktime_get_real_seconds() cast to u32 to extend these fields to y2106.

Signed-off-by: Alison Schofield <[email protected]>
---
 drivers/scsi/gdth.c      | 8 +++-----
 drivers/scsi/gdth_proc.c | 5 ++---
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 71e1380..3da4f43 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -118,6 +118,7 @@
 #include <linux/proc_fs.h>
 #include <linux/time.h>
 #include <linux/timer.h>
+#include <linux/ktime.h>
 #include <linux/dma-mapping.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
@@ -2838,7 +2839,6 @@ static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, 
u16 source,
                                       u16 idx, gdth_evt_data *evt)
 {
     gdth_evt_str *e;
-    struct timeval tv;
 
     /* no GDTH_LOCK_HA() ! */
     TRACE2(("gdth_store_event() source %d idx %d\n", source, idx));
@@ -2854,8 +2854,7 @@ static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, 
u16 source,
             !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
             (char *)&evt->event_string)))) { 
         e = &ebuffer[elastidx];
-        do_gettimeofday(&tv);
-        e->last_stamp = tv.tv_sec;
+       e->last_stamp = (u32)ktime_get_real_seconds();
         ++e->same_count;
     } else {
         if (ebuffer[elastidx].event_source != 0) {  /* entry not free ? */
@@ -2871,8 +2870,7 @@ static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, 
u16 source,
         e = &ebuffer[elastidx];
         e->event_source = source;
         e->event_idx = idx;
-        do_gettimeofday(&tv);
-        e->first_stamp = e->last_stamp = tv.tv_sec;
+       e->first_stamp = e->last_stamp = (u32)ktime_get_real_seconds();
         e->same_count = 1;
         e->event_data = *evt;
         e->application = 0;
diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
index e66e997..992d325 100644
--- a/drivers/scsi/gdth_proc.c
+++ b/drivers/scsi/gdth_proc.c
@@ -4,6 +4,7 @@
 
 #include <linux/completion.h>
 #include <linux/slab.h>
+#include <linux/ktime.h>
 
 int gdth_set_info(struct Scsi_Host *host, char *buffer, int length)
 {
@@ -148,7 +149,6 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
     gdth_cmd_str *gdtcmd;
     gdth_evt_str *estr;
     char hrec[161];
-    struct timeval tv;
 
     char *buf;
     gdth_dskstat_str *pds;
@@ -540,8 +540,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host 
*host)
         if (estr->event_data.eu.driver.ionode == ha->hanum &&
             estr->event_source == ES_ASYNC) { 
             gdth_log_event(&estr->event_data, hrec);
-            do_gettimeofday(&tv);
-            sec = (int)(tv.tv_sec - estr->first_stamp);
+           sec = (int)((u32)ktime_get_real_seconds() - estr->first_stamp);
             if (sec < 0) sec = 0;
             seq_printf(m," date- %02d:%02d:%02d\t%s\n",
                            sec/3600, sec%3600/60, sec%60, hrec);
-- 
2.1.4

_______________________________________________
Y2038 mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/y2038

Reply via email to