struct timeval tv is used to get current time. 32-bit systems using 'struct timeval' will break in the year 2038, so we have to replace that code with more appropriate types.
Signed-off-by: Ksenija Stanojevic ksenija.stanojevic@gmail.com --- Changes in v2: - use functions that uses real time clock. - do not change interface by removing timeval_buf.
drivers/staging/rts5208/rtsx.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/rts5208/rtsx.h b/drivers/staging/rts5208/rtsx.h index 9e6ecb7..7d44350 100644 --- a/drivers/staging/rts5208/rtsx.h +++ b/drivers/staging/rts5208/rtsx.h @@ -37,7 +37,7 @@ #include <linux/cdrom.h> #include <linux/workqueue.h> #include <linux/timer.h> -#include <linux/time.h> +#include <linux/time64.h>
#include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> @@ -151,21 +151,21 @@ static inline struct rtsx_dev *host_to_rtsx(struct Scsi_Host *host)
static inline void get_current_time(u8 *timeval_buf, int buf_len) { - struct timeval tv; + struct timespec64 ts64;
if (!timeval_buf || (buf_len < 8)) return;
- do_gettimeofday(&tv); + getnstimeofday64(&ts64);
- timeval_buf[0] = (u8)(tv.tv_sec >> 24); - timeval_buf[1] = (u8)(tv.tv_sec >> 16); - timeval_buf[2] = (u8)(tv.tv_sec >> 8); - timeval_buf[3] = (u8)(tv.tv_sec); - timeval_buf[4] = (u8)(tv.tv_usec >> 24); - timeval_buf[5] = (u8)(tv.tv_usec >> 16); - timeval_buf[6] = (u8)(tv.tv_usec >> 8); - timeval_buf[7] = (u8)(tv.tv_usec); + timeval_buf[0] = (u8)(ts64.tv_sec >> 24); + timeval_buf[1] = (u8)(ts64.tv_sec >> 16); + timeval_buf[2] = (u8)(ts64.tv_sec >> 8); + timeval_buf[3] = (u8)(ts64.tv_sec); + timeval_buf[4] = (u8)(ts64.tv_nsec/NSEC_PER_USEC >> 24); + timeval_buf[5] = (u8)(ts64.tv_nsec/NSEC_PER_USEC >> 16); + timeval_buf[6] = (u8)(ts64.tv_nsec/NSEC_PER_USEC >> 8); + timeval_buf[7] = (u8)(ts64.tv_nsec/NSEC_PER_USEC); }
/* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
On Tuesday 21 April 2015 19:27:38 Ksenija Stanojevic wrote:
struct timeval tv is used to get current time. 32-bit systems using 'struct timeval' will break in the year 2038, so we have to replace that code with more appropriate types.
Signed-off-by: Ksenija Stanojevic ksenija.stanojevic@gmail.com
This version looks correct, but I'd do one more change for clarity:
- do_gettimeofday(&tv);
- getnstimeofday64(&ts64);
- timeval_buf[0] = (u8)(tv.tv_sec >> 24);
- timeval_buf[1] = (u8)(tv.tv_sec >> 16);
- timeval_buf[2] = (u8)(tv.tv_sec >> 8);
- timeval_buf[3] = (u8)(tv.tv_sec);
- timeval_buf[4] = (u8)(tv.tv_usec >> 24);
- timeval_buf[5] = (u8)(tv.tv_usec >> 16);
- timeval_buf[6] = (u8)(tv.tv_usec >> 8);
- timeval_buf[7] = (u8)(tv.tv_usec);
- timeval_buf[0] = (u8)(ts64.tv_sec >> 24);
- timeval_buf[1] = (u8)(ts64.tv_sec >> 16);
- timeval_buf[2] = (u8)(ts64.tv_sec >> 8);
- timeval_buf[3] = (u8)(ts64.tv_sec);
- timeval_buf[4] = (u8)(ts64.tv_nsec/NSEC_PER_USEC >> 24);
- timeval_buf[5] = (u8)(ts64.tv_nsec/NSEC_PER_USEC >> 16);
- timeval_buf[6] = (u8)(ts64.tv_nsec/NSEC_PER_USEC >> 8);
- timeval_buf[7] = (u8)(ts64.tv_nsec/NSEC_PER_USEC);
}
You are doing the 'ts64.tv_nsec/NSEC_PER_USEC' division four times. I'm pretty sure the compiler can figure that out, but it would be more obvious if you just create a temporary u32 variable that contains the usec number.
Arnd