linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Staging: media: lirc: Replace timeval with ktime_t
@ 2015-05-22 15:58 Ksenija Stanojevic
  2015-05-22 19:52 ` [Y2038] " Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Ksenija Stanojevic @ 2015-05-22 15:58 UTC (permalink / raw)
  To: gregkh
  Cc: jarod, mchehab, linux-media, devel, linux-kernel, y2038,
	Ksenija Stanojevic

'struct timeval last_tv' is used to get the time of last signal change
and 'struct timeval last_intr_tv' is used to get the time of last UART
interrupt.
32-bit systems using 'struct timeval' will break in the year 2038, so we
have to replace that code with more appropriate types.
Here struct timeval is replaced with ktime_t.

Signed-off-by: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
---
 drivers/staging/media/lirc/lirc_sir.c | 75 ++++++++++++++---------------------
 1 file changed, 30 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/media/lirc/lirc_sir.c b/drivers/staging/media/lirc/lirc_sir.c
index 29087f6..4f326e9 100644
--- a/drivers/staging/media/lirc/lirc_sir.c
+++ b/drivers/staging/media/lirc/lirc_sir.c
@@ -44,7 +44,7 @@
 #include <linux/ioport.h>
 #include <linux/kernel.h>
 #include <linux/serial_reg.h>
-#include <linux/time.h>
+#include <linux/ktime.h>
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/wait.h>
@@ -127,9 +127,9 @@ static int threshold = 3;
 static DEFINE_SPINLOCK(timer_lock);
 static struct timer_list timerlist;
 /* time of last signal change detected */
-static struct timeval last_tv = {0, 0};
+static ktime_t last;
 /* time of last UART data ready interrupt */
-static struct timeval last_intr_tv = {0, 0};
+static ktime_t last_intr_time;
 static int last_value;
 
 static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
@@ -400,20 +400,6 @@ static void drop_chrdev(void)
 }
 
 /* SECTION: Hardware */
-static long delta(struct timeval *tv1, struct timeval *tv2)
-{
-	unsigned long deltv;
-
-	deltv = tv2->tv_sec - tv1->tv_sec;
-	if (deltv > 15)
-		deltv = 0xFFFFFF;
-	else
-		deltv = deltv*1000000 +
-			tv2->tv_usec -
-			tv1->tv_usec;
-	return deltv;
-}
-
 static void sir_timeout(unsigned long data)
 {
 	/*
@@ -432,12 +418,14 @@ static void sir_timeout(unsigned long data)
 		/* clear unread bits in UART and restart */
 		outb(UART_FCR_CLEAR_RCVR, io + UART_FCR);
 		/* determine 'virtual' pulse end: */
-		pulse_end = delta(&last_tv, &last_intr_tv);
+		pulse_end = min_t(unsigned long,
+				  ktime_us_delta(last, last_intr_time),
+				  PULSE_MASK);
 		dev_dbg(driver.dev, "timeout add %d for %lu usec\n",
 				    last_value, pulse_end);
 		add_read_queue(last_value, pulse_end);
 		last_value = 0;
-		last_tv = last_intr_tv;
+		last = last_intr_time;
 	}
 	spin_unlock_irqrestore(&timer_lock, flags);
 }
@@ -445,9 +433,9 @@ static void sir_timeout(unsigned long data)
 static irqreturn_t sir_interrupt(int irq, void *dev_id)
 {
 	unsigned char data;
-	struct timeval curr_tv;
-	static unsigned long deltv;
-	unsigned long deltintrtv;
+	ktime_t curr_time;
+	static unsigned long delt;
+	unsigned long deltintr;
 	unsigned long flags;
 	int iir, lsr;
 
@@ -471,49 +459,46 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id)
 			do {
 				del_timer(&timerlist);
 				data = inb(io + UART_RX);
-				do_gettimeofday(&curr_tv);
-				deltv = delta(&last_tv, &curr_tv);
-				deltintrtv = delta(&last_intr_tv, &curr_tv);
+				curr_time = ktime_get();
+				delt = min_t(unsigned long,
+					     ktime_us_delta(last, curr_time),
+					     PULSE_MASK);
+				deltintr = min_t(unsigned long,
+						 ktime_us_delta(last_intr_time,
+								curr_time),
+						 PULSE_MASK);
 				dev_dbg(driver.dev, "t %lu, d %d\n",
-						    deltintrtv, (int)data);
+						    deltintr, (int)data);
 				/*
 				 * if nothing came in last X cycles,
 				 * it was gap
 				 */
-				if (deltintrtv > TIME_CONST * threshold) {
+				if (deltintr > TIME_CONST * threshold) {
 					if (last_value) {
 						dev_dbg(driver.dev, "GAP\n");
 						/* simulate signal change */
 						add_read_queue(last_value,
-							       deltv -
-							       deltintrtv);
+							       delt -
+							       deltintr);
 						last_value = 0;
-						last_tv.tv_sec =
-							last_intr_tv.tv_sec;
-						last_tv.tv_usec =
-							last_intr_tv.tv_usec;
-						deltv = deltintrtv;
+						last = last_intr_time;
+						delt = deltintr;
 					}
 				}
 				data = 1;
 				if (data ^ last_value) {
 					/*
-					 * deltintrtv > 2*TIME_CONST, remember?
+					 * deltintr > 2*TIME_CONST, remember?
 					 * the other case is timeout
 					 */
 					add_read_queue(last_value,
-						       deltv-TIME_CONST);
+						       delt-TIME_CONST);
 					last_value = data;
-					last_tv = curr_tv;
-					if (last_tv.tv_usec >= TIME_CONST) {
-						last_tv.tv_usec -= TIME_CONST;
-					} else {
-						last_tv.tv_sec--;
-						last_tv.tv_usec += 1000000 -
-							TIME_CONST;
-					}
+					last = curr_time;
+					last = ktime_sub_us(last,
+							    TIME_CONST);
 				}
-				last_intr_tv = curr_tv;
+				last_intr_time = curr_time;
 				if (data) {
 					/*
 					 * start timer for end of
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Y2038] [PATCH] Staging: media: lirc: Replace timeval with ktime_t
  2015-05-22 15:58 [PATCH] Staging: media: lirc: Replace timeval with ktime_t Ksenija Stanojevic
@ 2015-05-22 19:52 ` Arnd Bergmann
  2015-06-08 19:37   ` Ksenija Stanojević
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2015-05-22 19:52 UTC (permalink / raw)
  To: y2038
  Cc: Ksenija Stanojevic, gregkh, devel, mchehab, jarod, linux-kernel,
	linux-media

On Friday 22 May 2015 17:58:42 Ksenija Stanojevic wrote:
> 'struct timeval last_tv' is used to get the time of last signal change
> and 'struct timeval last_intr_tv' is used to get the time of last UART
> interrupt.
> 32-bit systems using 'struct timeval' will break in the year 2038, so we
> have to replace that code with more appropriate types.
> Here struct timeval is replaced with ktime_t.
> 
> Signed-off-by: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
> 

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Y2038] [PATCH] Staging: media: lirc: Replace timeval with ktime_t
  2015-05-22 19:52 ` [Y2038] " Arnd Bergmann
@ 2015-06-08 19:37   ` Ksenija Stanojević
  2015-06-08 20:12     ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Ksenija Stanojević @ 2015-06-08 19:37 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: y2038, Greg KH, devel, mchehab, jarod, linux-kernel, linux-media

Hi Greg,

It's been over two weeks that I've sent this patch.  Have you missed it?

Thanks,
Ksenija

On Fri, May 22, 2015 at 9:52 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Friday 22 May 2015 17:58:42 Ksenija Stanojevic wrote:
>> 'struct timeval last_tv' is used to get the time of last signal change
>> and 'struct timeval last_intr_tv' is used to get the time of last UART
>> interrupt.
>> 32-bit systems using 'struct timeval' will break in the year 2038, so we
>> have to replace that code with more appropriate types.
>> Here struct timeval is replaced with ktime_t.
>>
>> Signed-off-by: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
>>
>
> Reviewed-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Y2038] [PATCH] Staging: media: lirc: Replace timeval with ktime_t
  2015-06-08 19:37   ` Ksenija Stanojević
@ 2015-06-08 20:12     ` Greg KH
  2015-06-09 16:15       ` Ksenija Stanojević
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2015-06-08 20:12 UTC (permalink / raw)
  To: Ksenija Stanojević
  Cc: Arnd Bergmann, y2038, devel, mchehab, jarod, linux-kernel, linux-media

On Mon, Jun 08, 2015 at 09:37:24PM +0200, Ksenija Stanojević wrote:
> Hi Greg,
> 
> It's been over two weeks that I've sent this patch.  Have you missed it?

Not at all, please look at the output of
	$ ./scripts/get_maintainer.pl --file drivers/staging/media/lirc/lirc_sir.c

To see why I ignored this.

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Y2038] [PATCH] Staging: media: lirc: Replace timeval with ktime_t
  2015-06-08 20:12     ` Greg KH
@ 2015-06-09 16:15       ` Ksenija Stanojević
  2015-06-09 16:25         ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Ksenija Stanojević @ 2015-06-09 16:15 UTC (permalink / raw)
  To: Greg KH
  Cc: Arnd Bergmann, y2038, devel, mchehab, jarod, linux-kernel, linux-media

On Mon, Jun 8, 2015 at 10:12 PM, Greg KH <gregkh@linuxfoundation.org> wrote:
> On Mon, Jun 08, 2015 at 09:37:24PM +0200, Ksenija Stanojević wrote:
>> Hi Greg,
>>
>> It's been over two weeks that I've sent this patch.  Have you missed it?
>
> Not at all, please look at the output of
>         $ ./scripts/get_maintainer.pl --file drivers/staging/media/lirc/lirc_sir.c
>

Ok. I used:
 ./scripts/get_maintainer.pl --nokeywords --nogit --nogit-fallback
--norolestats --file

I'll use instead ./scripts/get_maintainer.pl --file and send a v2.

> To see why I ignored this.
>
> greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Y2038] [PATCH] Staging: media: lirc: Replace timeval with ktime_t
  2015-06-09 16:15       ` Ksenija Stanojević
@ 2015-06-09 16:25         ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2015-06-09 16:25 UTC (permalink / raw)
  To: Ksenija Stanojević
  Cc: Greg KH, devel, Arnd Bergmann, mchehab, y2038, jarod,
	linux-kernel, linux-media

On Tue, Jun 09, 2015 at 06:15:50PM +0200, Ksenija Stanojević wrote:
> On Mon, Jun 8, 2015 at 10:12 PM, Greg KH <gregkh@linuxfoundation.org> wrote:
> > On Mon, Jun 08, 2015 at 09:37:24PM +0200, Ksenija Stanojević wrote:
> >> Hi Greg,
> >>
> >> It's been over two weeks that I've sent this patch.  Have you missed it?
> >
> > Not at all, please look at the output of
> >         $ ./scripts/get_maintainer.pl --file drivers/staging/media/lirc/lirc_sir.c
> >
> 
> Ok. I used:
>  ./scripts/get_maintainer.pl --nokeywords --nogit --nogit-fallback
> --norolestats --file

That command works fine.

> 
> I'll use instead ./scripts/get_maintainer.pl --file and send a v2.

No need.  You sent it to linux-media@vger.kernel.org and Mauro the first
time.  Just be patient.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-06-09 16:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-22 15:58 [PATCH] Staging: media: lirc: Replace timeval with ktime_t Ksenija Stanojevic
2015-05-22 19:52 ` [Y2038] " Arnd Bergmann
2015-06-08 19:37   ` Ksenija Stanojević
2015-06-08 20:12     ` Greg KH
2015-06-09 16:15       ` Ksenija Stanojević
2015-06-09 16:25         ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).