Skip to contentSkip to conversation

staging: android/vsoc: stop using 'timespec'

PATCH In review Arnd Bergmann 3 participants 3 messages Jun 18, 2018 – Jun 22, 2018 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: android/vsoc: stop using 'timespec'

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

---
 drivers/staging/android/vsoc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/staging/android/vsoc.c +5 -6
index 806beda1040b..22571abcaa4e 100644
@@ -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);
Signature · 1 line
2.9.0
Tested-by on v1 1/1
#1 lore raw
Quoted 5 lines · Arnd Bergmann

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

Quoted 39 lines
---
 drivers/staging/android/vsoc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/staging/android/vsoc.c +5 -7
index 806beda1040b..22571abcaa4e 100644
@@ -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

Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

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

Thanks!

Quoted 39 lines
---
 drivers/staging/android/vsoc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/staging/android/vsoc.c +5 -7
index 806beda1040b..22571abcaa4e 100644
@@ -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