Replace use of struct timeval with ktime_t to calculate connection duration. This avoids y2038 issues. Use ktime_get monotonic clock instead of gettimeofday realtime clock to guard against negative durations. Fix pr_debug to use matching %ul instead of converting value to int, so that debug does not provide misleading information. Fix connection time conversion to use interface type unsigned long instead of assuming it maps to u32.
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c | 8 +++----- drivers/staging/ft1000/ft1000-usb/ft1000_debug.c | 8 ++++---- drivers/staging/ft1000/ft1000-usb/ft1000_hw.c | 8 +++----- drivers/staging/ft1000/ft1000.h | 2 +- 4 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c index eecfa37..540b896 100644 --- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c +++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c @@ -906,7 +906,6 @@ static void ft1000_proc_drvmsg(struct net_device *dev) struct prov_record *ptr; struct pseudo_hdr *ppseudo_hdr; u16 *pmsg; - struct timeval tv; union { u8 byte[2]; u16 wrd; @@ -983,8 +982,7 @@ static void ft1000_proc_drvmsg(struct net_device *dev) netif_carrier_on(dev); netif_wake_queue(dev); info->mediastate = 1; - do_gettimeofday(&tv); - info->ConTm = tv.tv_sec; + info->ConTm = ktime_get(); } } else { pr_debug("Media is down\n"); @@ -992,7 +990,7 @@ static void ft1000_proc_drvmsg(struct net_device *dev) info->mediastate = 0; netif_carrier_off(dev); netif_stop_queue(dev); - info->ConTm = 0; + info->ConTm = ktime_set(0, 0); } } } else { @@ -1001,7 +999,7 @@ static void ft1000_proc_drvmsg(struct net_device *dev) info->mediastate = 0; netif_carrier_off(dev); netif_stop_queue(dev); - info->ConTm = 0; + info->ConTm = ktime_set(0, 0); } } break; diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c index f241a3a..d535c13 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c @@ -413,7 +413,7 @@ static long ft1000_ioctl(struct file *file, unsigned int command, int i; u16 tempword; unsigned long flags; - struct timeval tv; + ktime_t con_tm; struct IOCTL_GET_VER get_ver_data; struct IOCTL_GET_DSP_STAT get_stat_data; u8 ConnectionMsg[] = { @@ -520,9 +520,9 @@ static long ft1000_ioctl(struct file *file, unsigned int command, get_stat_data.nRxPkts = info->stats.rx_packets; get_stat_data.nTxBytes = info->stats.tx_bytes; get_stat_data.nRxBytes = info->stats.rx_bytes; - do_gettimeofday(&tv); - get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm); - pr_debug("Connection Time = %d\n", (int)get_stat_data.ConTm); + con_tm = ktime_sub(ktime_get(), info->ConTm); + get_stat_data.ConTm = (unsigned long)ktime_divns(con_tm, NSEC_PER_SEC); + pr_debug("Connection Time = %lu\n", get_stat_data.ConTm); if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data))) { pr_debug("copy fault occurred\n"); result = -EFAULT; diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c index 9ea32ce..633f525 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c @@ -619,7 +619,6 @@ static int ft1000_open(struct net_device *dev) { struct ft1000_info *pInfo = netdev_priv(dev); struct ft1000_usb *pFt1000Dev = pInfo->priv; - struct timeval tv;
pr_debug("ft1000_open is called for card %d\n", pFt1000Dev->CardNumber);
@@ -627,8 +626,7 @@ static int ft1000_open(struct net_device *dev) pInfo->stats.tx_bytes = 0; pInfo->stats.rx_packets = 0; pInfo->stats.tx_packets = 0; - do_gettimeofday(&tv); - pInfo->ConTm = tv.tv_sec; + pInfo->ConTm = ktime_get(); pInfo->ProgConStat = 0;
netif_start_queue(dev); @@ -1163,14 +1161,14 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size) if (info->mediastate == 1) { info->mediastate = 0; if (dev->NetDevRegDone) - info->ConTm = 0; + info->ConTm = ktime_set(0, 0); } } } else { pr_debug("Media is down\n"); if (info->mediastate == 1) { info->mediastate = 0; - info->ConTm = 0; + info->ConTm = ktime_set(0, 0); } } break; diff --git a/drivers/staging/ft1000/ft1000.h b/drivers/staging/ft1000/ft1000.h index 8a2e4ca..77b3f6e 100644 --- a/drivers/staging/ft1000/ft1000.h +++ b/drivers/staging/ft1000/ft1000.h @@ -347,7 +347,7 @@ struct ft1000_info { u8 HwSerNum[HWSERNUMSZ]; /* Hardware Serial Number */ u8 Sku[SKUSZ]; /* SKU */ u8 eui64[EUISZ]; /* EUI64 */ - time_t ConTm; /* Connection Time */ + ktime_t ConTm; /* Connection Time */ u8 ProductMode[MODESZ]; u8 RfCalVer[CALVERSZ]; u8 RfCalDate[CALDATESZ];