Skip to contentSkip to conversation

net: hamradio: baycom_ser_fdx: Replace timeval with timespec64

PATCH In review Amitoj Kaur Chawla 2 participants 2 messages Oct 28, 2015 – Nov 4, 2015 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: hamradio: baycom_ser_fdx: Replace timeval with timespec64

32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately.

This patch replaces struct timeval with struct timespec64.

The patch also changes the code to use ktime_get_real_ts64() which returns a 'struct timespec64' instead of do_gettimeofday() which returns a 'struct timeval'

---
 drivers/net/hamradio/baycom_ser_fdx.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/hamradio/baycom_ser_fdx.c +7 -5
index 636b65c..e250ec4 100644
@@ -71,6 +71,7 @@
 
 /*****************************************************************************/
 
+#include <linux/time64.h>
 #include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/ioport.h>
@@ -228,14 +229,15 @@ static inline unsigned int hweight8(unsigned int w)
 
 /* --------------------------------------------------------------------- */
 
-static __inline__ void ser12_rx(struct net_device *dev, struct baycom_state *bc, struct timeval *tv, unsigned char curs)
+static __inline__ void ser12_rx(struct net_device *dev, struct baycom_state *bc, struct timespec64 *ts, unsigned char curs)
 {
 	int timediff;
 	int bdus8 = bc->baud_us >> 3;
 	int bdus4 = bc->baud_us >> 2;
 	int bdus2 = bc->baud_us >> 1;
 
-	timediff = 1000000 + tv->tv_usec - bc->modem.ser12.pll_time;
+	timediff = 1000000 + (ts->tv_nsec / NSEC_PER_USEC) -
+						bc->modem.ser12.pll_time;
 	while (timediff >= 500000)
 		timediff -= 1000000;
 	while (timediff >= bdus2) {
@@ -287,7 +289,7 @@ static irqreturn_t ser12_interrupt(int irq, void *dev_id)
 {
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct baycom_state *bc = netdev_priv(dev);
-	struct timeval tv;
+	struct timespec64 ts;
 	unsigned char iir, msr;
 	unsigned int txcount = 0;
 
@@ -297,7 +299,7 @@ static irqreturn_t ser12_interrupt(int irq, void *dev_id)
 	if ((iir = inb(IIR(dev->base_addr))) & 1) 	
 		return IRQ_NONE;
 	/* get current time */
-	do_gettimeofday(&tv);
+	ktime_get_real_ts64(&ts);
 	msr = inb(MSR(dev->base_addr));
 	/* delta DCD */
 	if ((msr & 8) && bc->opt_dcd)
@@ -340,7 +342,7 @@ static irqreturn_t ser12_interrupt(int irq, void *dev_id)
 		}
 		iir = inb(IIR(dev->base_addr));
 	} while (!(iir & 1));
-	ser12_rx(dev, bc, &tv, msr & 0x10); /* CTS */
+	ser12_rx(dev, bc, &ts, msr & 0x10); /* CTS */
 	if (bc->modem.ptt && txcount) {
 		if (bc->modem.ser12.txshreg <= 1) {
 			bc->modem.ser12.txshreg = 0x10000 | hdlcdrv_getbits(&bc->hdrv);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 8 lines · On Thursday 29 October 2015 01:22:02 Amitoj Kaur Chawla wrote:

32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately.

This patch replaces struct timeval with struct timespec64.

The patch also changes the code to use ktime_get_real_ts64() which returns a 'struct timespec64' instead of do_gettimeofday() which returns a 'struct timeval'

The patch looks correct to me, but I'd suggest using monotonic time to make the driver more robust against 'settimeofday' calls. It would also be helpful to clarify in the description that the driver has no y2038 problem as it only uses the microsecond portion of timeval, not the seconds.

Arnd