Skip to content

Commit

Permalink
pata_pdc2027x: Use 64-bit timekeeping
Browse files Browse the repository at this point in the history
Function pdc_detect_pll_input_clock uses 'struct timeval'
to measure start and end times, used to compute the pll_clock value.
'struct timeval' on 32-bit systems will have its tv_sec field
overflow in year 2038 and beyond. This patch uses 'ktime_t'
(which uses 64 bits for seconds) for start and end times instead.

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Tejun Heo <tj@kernel.org>
  • Loading branch information
Tina Ruchandani authored and Tejun Heo committed Jan 27, 2015
1 parent 5529415 commit cedda4c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/ata/pata_pdc2027x.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/blkdev.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/ktime.h>
#include <scsi/scsi.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_cmnd.h>
Expand Down Expand Up @@ -605,7 +606,7 @@ static long pdc_detect_pll_input_clock(struct ata_host *host)
void __iomem *mmio_base = host->iomap[PDC_MMIO_BAR];
u32 scr;
long start_count, end_count;
struct timeval start_time, end_time;
ktime_t start_time, end_time;
long pll_clock, usec_elapsed;

/* Start the test mode */
Expand All @@ -616,14 +617,14 @@ static long pdc_detect_pll_input_clock(struct ata_host *host)

/* Read current counter value */
start_count = pdc_read_counter(host);
do_gettimeofday(&start_time);
start_time = ktime_get();

/* Let the counter run for 100 ms. */
mdelay(100);

/* Read the counter values again */
end_count = pdc_read_counter(host);
do_gettimeofday(&end_time);
end_time = ktime_get();

/* Stop the test mode */
scr = ioread32(mmio_base + PDC_SYS_CTL);
Expand All @@ -632,8 +633,7 @@ static long pdc_detect_pll_input_clock(struct ata_host *host)
ioread32(mmio_base + PDC_SYS_CTL); /* flush */

/* calculate the input clock in Hz */
usec_elapsed = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
(end_time.tv_usec - start_time.tv_usec);
usec_elapsed = (long) ktime_us_delta(end_time, start_time);

pll_clock = ((start_count - end_count) & 0x3fffffff) / 100 *
(100000000 / usec_elapsed);
Expand Down

0 comments on commit cedda4c

Please sign in to comment.