32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately. However, this driver is not broken in 2038 since we are using only the microseconds portion of the current time.
This patch replaces struct timeval and do_gettimeofday() with ktime_get_real_ns() which returns a 64 bit value which is safer than struct timeval. ktime_get_real_ns() is also faster than the computations done in this macro previously to get the same value.
Signed-off-by: Amitoj Kaur Chawla amitoj1606@gmail.com --- drivers/scsi/bfa/bfa_cs.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/bfa/bfa_cs.h b/drivers/scsi/bfa/bfa_cs.h index 91a8aa3..eeafef0 100644 --- a/drivers/scsi/bfa/bfa_cs.h +++ b/drivers/scsi/bfa/bfa_cs.h @@ -22,6 +22,7 @@ #ifndef __BFA_CS_H__ #define __BFA_CS_H__
+#include <linux/ktime.h> #include "bfad_drv.h"
/* @@ -32,13 +33,7 @@ #define BFA_TRC_MAX (4 * 1024) #endif
-#define BFA_TRC_TS(_trcm) \ - ({ \ - struct timeval tv; \ - \ - do_gettimeofday(&tv); \ - (tv.tv_sec*1000000+tv.tv_usec); \ - }) +#define BFA_TRC_TS(_trcm) (ktime_get_real_ns() / NSEC_PER_USEC)
#ifndef BFA_TRC_TS #define BFA_TRC_TS(_trcm) ((_trcm)->ticks++)
On Sunday 01 November 2015 19:21:58 Amitoj Kaur Chawla wrote:
-#define BFA_TRC_TS(_trcm) \
({ \
struct timeval tv; \
\
do_gettimeofday(&tv); \
(tv.tv_sec*1000000+tv.tv_usec); \
})
+#define BFA_TRC_TS(_trcm) (ktime_get_real_ns() / NSEC_PER_USEC)
This change is broken on 32-bit architectures, as you are doing a 64-bit integer division that we don't allow in the kernel. If you try to build the entire kernel for 32-bit, you will get a link error here.
Also, you probably don't want to do the expensive division in a function that is called as often as this one. This probably needs some help from the driver maintainer, to answer how the timestamp is used, but using the original algorithm would at least make it no less efficient than it is today. Alternatively, using
#define BFA_TRC_TS(_trcm) (ktime_get_ns() >> 10)
could give an approximation by doing a bit shift (division by 1024) instead of the division by 1000.
Arnd