diff mbox series

[3/8,media] solo6x10: use ktime_get_ts64() for time sync

Message ID 20171127132027.1734806-3-arnd@arndb.de
State Accepted
Commit 6c542426b610c14acff0e815e5fe513abdbb9a16
Headers show
Series None | expand

Commit Message

Arnd Bergmann Nov. 27, 2017, 1:19 p.m. UTC
solo6x10 correctly deals with time stamps and will never
suffer from overflows, but it uses the deprecated 'struct timespec'
type and 'ktime_get_ts()' interface to read the monotonic clock.

This changes it to use ktime_get_ts64() instead, so we can
eventually remove ktime_get_ts().

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

---
 drivers/media/pci/solo6x10/solo6x10-core.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

-- 
2.9.0

Comments

Ismael Luceno Nov. 27, 2017, 8:45 p.m. UTC | #1
On 27/Nov/2017 14:19, Arnd Bergmann wrote:
> solo6x10 correctly deals with time stamps and will never

> suffer from overflows, but it uses the deprecated 'struct timespec'

> type and 'ktime_get_ts()' interface to read the monotonic clock.

> 

> This changes it to use ktime_get_ts64() instead, so we can

> eventually remove ktime_get_ts().

> 

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

> ---

>  drivers/media/pci/solo6x10/solo6x10-core.c | 17 +++++++++--------

>  1 file changed, 9 insertions(+), 8 deletions(-)

> 

> diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c

> index ca0873e47bea..19ffd2ed3cc7 100644

> --- a/drivers/media/pci/solo6x10/solo6x10-core.c

> +++ b/drivers/media/pci/solo6x10/solo6x10-core.c

> @@ -47,18 +47,19 @@ MODULE_PARM_DESC(full_eeprom, "Allow access to full 128B EEPROM (dangerous)");

>  

>  static void solo_set_time(struct solo_dev *solo_dev)

>  {

> -	struct timespec ts;

> +	struct timespec64 ts;

>  

> -	ktime_get_ts(&ts);

> +	ktime_get_ts64(&ts);

>  

> -	solo_reg_write(solo_dev, SOLO_TIMER_SEC, ts.tv_sec);

> -	solo_reg_write(solo_dev, SOLO_TIMER_USEC, ts.tv_nsec / NSEC_PER_USEC);

> +	/* no overflow because we use monotonic timestamps */

> +	solo_reg_write(solo_dev, SOLO_TIMER_SEC, (u32)ts.tv_sec);

> +	solo_reg_write(solo_dev, SOLO_TIMER_USEC, (u32)ts.tv_nsec / NSEC_PER_USEC);

>  }

>  

>  static void solo_timer_sync(struct solo_dev *solo_dev)

>  {

>  	u32 sec, usec;

> -	struct timespec ts;

> +	struct timespec64 ts;

>  	long diff;

>  

>  	if (solo_dev->type != SOLO_DEV_6110)

> @@ -72,11 +73,11 @@ static void solo_timer_sync(struct solo_dev *solo_dev)

>  	sec = solo_reg_read(solo_dev, SOLO_TIMER_SEC);

>  	usec = solo_reg_read(solo_dev, SOLO_TIMER_USEC);

>  

> -	ktime_get_ts(&ts);

> +	ktime_get_ts64(&ts);

>  

> -	diff = (long)ts.tv_sec - (long)sec;

> +	diff = (s32)ts.tv_sec - (s32)sec;

>  	diff = (diff * 1000000)

> -		+ ((long)(ts.tv_nsec / NSEC_PER_USEC) - (long)usec);

> +		+ ((s32)(ts.tv_nsec / NSEC_PER_USEC) - (s32)usec);

>  

>  	if (diff > 1000 || diff < -1000) {

>  		solo_set_time(solo_dev);

> -- 

> 2.9.0

> 


Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
diff mbox series

Patch

diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
index ca0873e47bea..19ffd2ed3cc7 100644
--- a/drivers/media/pci/solo6x10/solo6x10-core.c
+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
@@ -47,18 +47,19 @@  MODULE_PARM_DESC(full_eeprom, "Allow access to full 128B EEPROM (dangerous)");
 
 static void solo_set_time(struct solo_dev *solo_dev)
 {
-	struct timespec ts;
+	struct timespec64 ts;
 
-	ktime_get_ts(&ts);
+	ktime_get_ts64(&ts);
 
-	solo_reg_write(solo_dev, SOLO_TIMER_SEC, ts.tv_sec);
-	solo_reg_write(solo_dev, SOLO_TIMER_USEC, ts.tv_nsec / NSEC_PER_USEC);
+	/* no overflow because we use monotonic timestamps */
+	solo_reg_write(solo_dev, SOLO_TIMER_SEC, (u32)ts.tv_sec);
+	solo_reg_write(solo_dev, SOLO_TIMER_USEC, (u32)ts.tv_nsec / NSEC_PER_USEC);
 }
 
 static void solo_timer_sync(struct solo_dev *solo_dev)
 {
 	u32 sec, usec;
-	struct timespec ts;
+	struct timespec64 ts;
 	long diff;
 
 	if (solo_dev->type != SOLO_DEV_6110)
@@ -72,11 +73,11 @@  static void solo_timer_sync(struct solo_dev *solo_dev)
 	sec = solo_reg_read(solo_dev, SOLO_TIMER_SEC);
 	usec = solo_reg_read(solo_dev, SOLO_TIMER_USEC);
 
-	ktime_get_ts(&ts);
+	ktime_get_ts64(&ts);
 
-	diff = (long)ts.tv_sec - (long)sec;
+	diff = (s32)ts.tv_sec - (s32)sec;
 	diff = (diff * 1000000)
-		+ ((long)(ts.tv_nsec / NSEC_PER_USEC) - (long)usec);
+		+ ((s32)(ts.tv_nsec / NSEC_PER_USEC) - (s32)usec);
 
 	if (diff > 1000 || diff < -1000) {
 		solo_set_time(solo_dev);