Skip to contentSkip to conversation

mpt2sas: Remove usage of 'struct timeval'

PATCH RESEND Superseded Tina Ruchandani 3 participants 4 messages Oct 30, 2015 – Nov 12, 2015 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 mpt2sas: Remove usage of 'struct timeval'

'struct timeval' will have its tv_sec value overflow on 32-bit systems in year 2038 and beyond. This patch replaces the use of struct timeval for computing mpi_request.TimeStamp, and instead uses ktime_t which provides 64-bit seconds value. The timestamp computed remains unaffected (milliseconds since Unix epoch).

---
 drivers/scsi/mpt2sas/mpt2sas_base.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/mpt2sas/mpt2sas_base.c +4 -4
index 58e4521..6d80477 100644
@@ -57,6 +57,7 @@
 #include <linux/sort.h>
 #include <linux/io.h>
 #include <linux/time.h>
+#include <linux/ktime.h>
 #include <linux/kthread.h>
 #include <linux/aer.h>
 
@@ -3616,7 +3617,7 @@ _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
 	Mpi2IOCInitRequest_t mpi_request;
 	Mpi2IOCInitReply_t mpi_reply;
 	int i, r = 0;
-	struct timeval current_time;
+	ktime_t current_time;
 	u16 ioc_status;
 	u32 reply_post_free_array_sz = 0;
 	Mpi2IOCInitRDPQArrayEntry *reply_post_free_array = NULL;
@@ -3678,9 +3679,8 @@ _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
 	/* This time stamp specifies number of milliseconds
 	 * since epoch ~ midnight January 1, 1970.
 	 */
-	do_gettimeofday(&current_time);
-	mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
-	    (current_time.tv_usec / 1000));
+	current_time = ktime_get_real();
+	mpi_request.TimeStamp = cpu_to_le64(ktime_to_ms(current_time));
 
 	if (ioc->logging_level & MPT_DEBUG_INIT) {
 		__le32 *mfp;
Signature · 6 lines
2.2.0.rc0.207.ga3a616c

_______________________________________________
Y2038 mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/y2038
maintainer
#1 lore raw
Quoted 9 lines · Tina Ruchandani

'struct timeval' will have its tv_sec value overflow on 32-bit systems in year 2038 and beyond. This patch replaces the use of struct timeval for computing mpi_request.TimeStamp, and instead uses ktime_t which provides
64-bit seconds value. The timestamp computed remains unaffected (milliseconds
since Unix epoch).

Can you wait a cycle on this? Martin Petersen is on a mission to wrangle the mpt2/3sas merger in this window, which will conflict with this.

James

Quoted 39 lines

drivers/scsi/mpt2sas/mpt2sas_base.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/mpt2sas/mpt2sas_base.c +2 -1
index 58e4521..6d80477 100644
@@ -57,6 +57,7 @@
 #include <linux/sort.h>
 #include <linux/io.h>
 #include <linux/time.h>
+#include <linux/ktime.h>
 #include <linux/kthread.h>
 #include <linux/aer.h>
 
@@ -3616,7 +3617,7 @@ _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc,
 int sleep_flag)
 	Mpi2IOCInitRequest_t mpi_request;
 	Mpi2IOCInitReply_t mpi_reply;
 	int i, r = 0;
-	struct timeval current_time;
+	ktime_t current_time;
 	u16 ioc_status;
 	u32 reply_post_free_array_sz = 0;
	Mpi2IOCInitRDPQArrayEntry *reply_post_free_array = NULL;
drivers/scsi/mpt2sas/mpt2sas_base.c +2 -3
@@ -3678,9 +3679,8 @@ _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc,
 int sleep_flag)
 	/* This time stamp specifies number of milliseconds
 	 * since epoch ~ midnight January 1, 1970.
 	 */
-	do_gettimeofday(&current_time);
-	mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
-	    (current_time.tv_usec / 1000));
+	current_time = ktime_get_real();
+	mpi_request.TimeStamp = cpu_to_le64(ktime_to_ms(current_time));
 
 	if (ioc->logging_level & MPT_DEBUG_INIT) {
		__le32 *mfp;
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#2 lore raw
Quoted 2 lines

Can you wait a cycle on this? Martin Petersen is on a mission to wrangle the mpt2/3sas merger in this window, which will conflict with this.

James,
No issues. Making a note here though that the patches for mpt2sas_base.c and mpt3sas_base.c are identical, I submitted the latter before I saw your email.
Tina

#3 lore raw
In reply to Tina Ruchandani
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Tina" == Tina Ruchandani <[email protected]> writes:

Tina,

Tina> 'struct timeval' will have its tv_sec value overflow on 32-bit Tina> systems in year 2038 and beyond. This patch replaces the use of Tina> struct timeval for computing mpi_request.TimeStamp, and instead Tina> uses ktime_t which provides 64-bit seconds value. The timestamp Tina> computed remains unaffected (milliseconds since Unix epoch).

We just consolidated the mpt2sas and mpt3sas drivers into one so I'm afraid your time tweaks will have to be rebased. I encourage you repost in a couple of weeks after the merge window dust settles.

Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering