[OPW,kernel,RESEND,v4] staging: gdm72xx: Replace timeval with ktime_t
diff mbox

Message ID 20141030141728.GA30623@kt-Inspiron-3542
State New, archived
Headers show

Commit Message

Tapasweni Pathak Oct. 30, 2014, 2:17 p.m. UTC
struct sdu_stamp in the gdm_sdio.h is a timeval type.
'struct timeval now' is used for calculating elapsed time.

32-bit systems using 'struct timeval' will break in the year 2038,
so we have to replace that code with more appropriate types.
This patch changes the gdm72xx driver to use ktime_t.

ktime_get() is  better than using do_gettimeofday(),
because it uses the monotonic clock. ktime_sub
are used to subtract two ktime variables.

Build tested this by saying Y to WIMAX_GDM72XX.

Signed-off-by: Tapasweni Pathak <tapaswenipathak@gmail.com>
---
Changes in v4:
Changed before to an object from a pointer.

Changes in v3:
Used NSEC_PER_SEC instead of 1000000000 to improve readability.

Changes in v2:
Used ktime_to_ns instead of ktime_to_us.
TX_INTERVAL is also converted to nanoseconds.
Changed the commit message accordingly.

 drivers/staging/gdm72xx/gdm_sdio.c |   13 ++++++-------
 drivers/staging/gdm72xx/gdm_sdio.h |    4 ++--
 2 files changed, 8 insertions(+), 9 deletions(-)

--
1.7.9.5

Comments

Arnd Bergmann Oct. 30, 2014, 2:21 p.m. UTC | #1
On Thursday 30 October 2014 19:47:28 Tapasweni Pathak wrote:
> struct sdu_stamp in the gdm_sdio.h is a timeval type.
> 'struct timeval now' is used for calculating elapsed time.
> 
> 32-bit systems using 'struct timeval' will break in the year 2038,
> so we have to replace that code with more appropriate types.
> This patch changes the gdm72xx driver to use ktime_t.
> 
> ktime_get() is  better than using do_gettimeofday(),
> because it uses the monotonic clock. ktime_sub
> are used to subtract two ktime variables.
> 
> Build tested this by saying Y to WIMAX_GDM72XX.
> 
> Signed-off-by: Tapasweni Pathak <tapaswenipathak@gmail.com>
> 

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

Greg, this is a fixed version of the earlier patch you dropped as it
turned out to be broken, please apply into staging.

	Arnd

Patch
diff mbox

diff --git a/drivers/staging/gdm72xx/gdm_sdio.c b/drivers/staging/gdm72xx/gdm_sdio.c
index 7a0a0f2..4bce597 100644
--- a/drivers/staging/gdm72xx/gdm_sdio.c
+++ b/drivers/staging/gdm72xx/gdm_sdio.c
@@ -36,7 +36,7 @@ 
 #define RX_BUF_SIZE	(25*1024)

 #define TX_HZ		2000
-#define TX_INTERVAL	(1000000/TX_HZ)
+#define TX_INTERVAL	(NSEC_PER_SEC/TX_HZ)

 static struct sdio_tx *alloc_tx_struct(struct tx_cxt *tx)
 {
@@ -305,7 +305,7 @@  static void send_sdu(struct sdio_func *func, struct tx_cxt *tx)
 		put_tx_struct(t->tx_cxt, t);
 	}

-	do_gettimeofday(&tx->sdu_stamp);
+	tx->sdu_stamp = ktime_get();
 	spin_unlock_irqrestore(&tx->lock, flags);
 }

@@ -332,7 +332,7 @@  static void do_tx(struct work_struct *work)
 	struct sdio_func *func = sdev->func;
 	struct tx_cxt *tx = &sdev->tx;
 	struct sdio_tx *t = NULL;
-	struct timeval now, *before;
+	ktime_t now, before;
 	int is_sdu = 0;
 	long diff;
 	unsigned long flags;
@@ -348,11 +348,10 @@  static void do_tx(struct work_struct *work)
 		list_del(&t->list);
 		is_sdu = 0;
 	} else if (!tx->stop_sdu_tx && !list_empty(&tx->sdu_list)) {
-		do_gettimeofday(&now);
-		before = &tx->sdu_stamp;
+		now = ktime_get();
+		before = tx->sdu_stamp;

-		diff = (now.tv_sec - before->tv_sec) * 1000000 +
-			(now.tv_usec - before->tv_usec);
+		diff = ktime_to_ns(ktime_sub(now, before));
 		if (diff >= 0 && diff < TX_INTERVAL) {
 			schedule_work(&sdev->ws);
 			spin_unlock_irqrestore(&tx->lock, flags);
diff --git a/drivers/staging/gdm72xx/gdm_sdio.h b/drivers/staging/gdm72xx/gdm_sdio.h
index 77ad9d6..aa7dad2 100644
--- a/drivers/staging/gdm72xx/gdm_sdio.h
+++ b/drivers/staging/gdm72xx/gdm_sdio.h
@@ -15,7 +15,7 @@ 
 #define __GDM72XX_GDM_SDIO_H__

 #include <linux/types.h>
-#include <linux/time.h>
+#include <linux/ktime.h>

 #define MAX_NR_SDU_BUF  64

@@ -32,7 +32,7 @@  struct tx_cxt {
 	struct list_head	free_list;
 	struct list_head	sdu_list;
 	struct list_head	hci_list;
-	struct timeval		sdu_stamp;
+	ktime_t			sdu_stamp;
 	u8			*sdu_buf;
 	spinlock_t		lock;
 	int			can_send;