linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: android/vsoc: stop using 'timespec'
@ 2018-06-18 15:09 Arnd Bergmann
  2018-06-21 22:04 ` Alistair Strachan
  2018-06-22  8:51 ` Martijn Coenen
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2018-06-18 15:09 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos, Martijn Coenen
  Cc: y2038, Riley Andrews, Arnd Bergmann, Nathan Chancellor,
	Alistair Strachan, devel, linux-kernel

The timespec structure suffers from the y2038 overflow and should not
be used. This changes handle_vsoc_cond_wait() to use ktime_t directly.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/staging/android/vsoc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/android/vsoc.c b/drivers/staging/android/vsoc.c
index 806beda1040b..22571abcaa4e 100644
--- a/drivers/staging/android/vsoc.c
+++ b/drivers/staging/android/vsoc.c
@@ -405,7 +405,7 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg)
 	int ret = 0;
 	struct vsoc_device_region *region_p = vsoc_region_from_filep(filp);
 	atomic_t *address = NULL;
-	struct timespec ts;
+	ktime_t wake_time;
 
 	/* Ensure that the offset is aligned */
 	if (arg->offset & (sizeof(uint32_t) - 1))
@@ -433,14 +433,13 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg)
 		 * We do things this way to flatten differences between 32 bit
 		 * and 64 bit timespecs.
 		 */
-		ts.tv_sec = arg->wake_time_sec;
-		ts.tv_nsec = arg->wake_time_nsec;
-
-		if (!timespec_valid(&ts))
+		if (arg->wake_time_nsec >= NSEC_PER_SEC)
 			return -EINVAL;
+		wake_time = ktime_set(arg->wake_time_sec, arg->wake_time_nsec);
+
 		hrtimer_init_on_stack(&to->timer, CLOCK_MONOTONIC,
 				      HRTIMER_MODE_ABS);
-		hrtimer_set_expires_range_ns(&to->timer, timespec_to_ktime(ts),
+		hrtimer_set_expires_range_ns(&to->timer, wake_time,
 					     current->timer_slack_ns);
 
 		hrtimer_init_sleeper(to, current);
-- 
2.9.0


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

* Re: [PATCH] staging: android/vsoc: stop using 'timespec'
  2018-06-18 15:09 [PATCH] staging: android/vsoc: stop using 'timespec' Arnd Bergmann
@ 2018-06-21 22:04 ` Alistair Strachan
  2018-06-22  8:51 ` Martijn Coenen
  1 sibling, 0 replies; 3+ messages in thread
From: Alistair Strachan @ 2018-06-21 22:04 UTC (permalink / raw)
  To: arnd
  Cc: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
	Martijn Coenen, y2038, riandrews, natechancellor, devel,
	linux-kernel

On Mon, Jun 18, 2018 at 8:09 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> The timespec structure suffers from the y2038 overflow and should not
> be used. This changes handle_vsoc_cond_wait() to use ktime_t directly.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Tested-by: Alistair Strachan <astrachan@google.com>

> ---
>  drivers/staging/android/vsoc.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/android/vsoc.c b/drivers/staging/android/vsoc.c
> index 806beda1040b..22571abcaa4e 100644
> --- a/drivers/staging/android/vsoc.c
> +++ b/drivers/staging/android/vsoc.c
> @@ -405,7 +405,7 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg)
>         int ret = 0;
>         struct vsoc_device_region *region_p = vsoc_region_from_filep(filp);
>         atomic_t *address = NULL;
> -       struct timespec ts;
> +       ktime_t wake_time;
>
>         /* Ensure that the offset is aligned */
>         if (arg->offset & (sizeof(uint32_t) - 1))
> @@ -433,14 +433,13 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg)
>                  * We do things this way to flatten differences between 32 bit
>                  * and 64 bit timespecs.
>                  */
> -               ts.tv_sec = arg->wake_time_sec;
> -               ts.tv_nsec = arg->wake_time_nsec;
> -
> -               if (!timespec_valid(&ts))
> +               if (arg->wake_time_nsec >= NSEC_PER_SEC)
>                         return -EINVAL;
> +               wake_time = ktime_set(arg->wake_time_sec, arg->wake_time_nsec);
> +
>                 hrtimer_init_on_stack(&to->timer, CLOCK_MONOTONIC,
>                                       HRTIMER_MODE_ABS);
> -               hrtimer_set_expires_range_ns(&to->timer, timespec_to_ktime(ts),
> +               hrtimer_set_expires_range_ns(&to->timer, wake_time,
>                                              current->timer_slack_ns);
>
>                 hrtimer_init_sleeper(to, current);
> --
> 2.9.0
>

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

* Re: [PATCH] staging: android/vsoc: stop using 'timespec'
  2018-06-18 15:09 [PATCH] staging: android/vsoc: stop using 'timespec' Arnd Bergmann
  2018-06-21 22:04 ` Alistair Strachan
@ 2018-06-22  8:51 ` Martijn Coenen
  1 sibling, 0 replies; 3+ messages in thread
From: Martijn Coenen @ 2018-06-22  8:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos, y2038,
	Riley Andrews, Nathan Chancellor, Alistair Strachan,
	open list:ANDROID DRIVERS, LKML

On Mon, Jun 18, 2018 at 5:09 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> The timespec structure suffers from the y2038 overflow and should not
> be used. This changes handle_vsoc_cond_wait() to use ktime_t directly.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Martijn Coenen <maco@android.com>

Thanks!

> ---
>  drivers/staging/android/vsoc.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/android/vsoc.c b/drivers/staging/android/vsoc.c
> index 806beda1040b..22571abcaa4e 100644
> --- a/drivers/staging/android/vsoc.c
> +++ b/drivers/staging/android/vsoc.c
> @@ -405,7 +405,7 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg)
>         int ret = 0;
>         struct vsoc_device_region *region_p = vsoc_region_from_filep(filp);
>         atomic_t *address = NULL;
> -       struct timespec ts;
> +       ktime_t wake_time;
>
>         /* Ensure that the offset is aligned */
>         if (arg->offset & (sizeof(uint32_t) - 1))
> @@ -433,14 +433,13 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg)
>                  * We do things this way to flatten differences between 32 bit
>                  * and 64 bit timespecs.
>                  */
> -               ts.tv_sec = arg->wake_time_sec;
> -               ts.tv_nsec = arg->wake_time_nsec;
> -
> -               if (!timespec_valid(&ts))
> +               if (arg->wake_time_nsec >= NSEC_PER_SEC)
>                         return -EINVAL;
> +               wake_time = ktime_set(arg->wake_time_sec, arg->wake_time_nsec);
> +
>                 hrtimer_init_on_stack(&to->timer, CLOCK_MONOTONIC,
>                                       HRTIMER_MODE_ABS);
> -               hrtimer_set_expires_range_ns(&to->timer, timespec_to_ktime(ts),
> +               hrtimer_set_expires_range_ns(&to->timer, wake_time,
>                                              current->timer_slack_ns);
>
>                 hrtimer_init_sleeper(to, current);
> --
> 2.9.0
>

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

end of thread, other threads:[~2018-06-22  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-18 15:09 [PATCH] staging: android/vsoc: stop using 'timespec' Arnd Bergmann
2018-06-21 22:04 ` Alistair Strachan
2018-06-22  8:51 ` Martijn Coenen

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).