]> asedeno.scripts.mit.edu Git - linux.git/commit
scsi: arcmsr: avoid do_gettimeofday
authorArnd Bergmann <arnd@arndb.de>
Sun, 21 Jan 2018 23:12:26 +0000 (00:12 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 23 Jan 2018 01:04:02 +0000 (20:04 -0500)
commit45596c7889a4454e340863c112dbc6cf525e5647
tree35b0b1a731a698cdb017e44730da08d7e01d9876
parent9c661a49e4318f11934115adb4c5a91e15efc0cc
scsi: arcmsr: avoid do_gettimeofday

The arcmsr uses its own implementation of time_to_tm(), along with
do_gettimeofday() to read the current time. While the algorithm used
here is fine in principle, it suffers from two problems:

- it assigns the seconds portion of the timeval to a 32-bit unsigned
  integer that overflows in 2106 even on 64-bit architectures.

- do_gettimeofday() returns a time_t that overflows in 2038 on all
  32-bit systems.

This changes the time retrieval function to ktime_get_real_seconds(),
which returns a proper 64-bit value, and replaces the open-coded
time_to_tm() algorithm with a call to the safe time64_to_tm().

I checked way all numbers are indexed and found that months are given in
range 0..11 while the days are in range 1..31, same as 'struct tm', but
the year value that the firmware expects starts in 2000 while 'struct
tm' is based on year 1900, so it needs a small adjustment.

[mkp: checkpatch tweaks]

Fixes: b416c099472a ("scsi: arcmsr: Add a function to set date and time to firmware")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Ching Huang <ching2048@areca.com.tw>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/arcmsr/arcmsr_hba.c