Skip to contentSkip to conversation

dummy_hcd: replace timeval with timespec64

PATCH Superseded WEN Pingbo 3 participants 6 messages Sep 17, 2015 – Sep 18, 2015 1 message not in the archive USB

lore
Share & tools
lore

WEN Pingbo

author
#1 lore raw

PATCH v2 1/1 dummy_hcd: replace timeval with timespec64

In reply to a message not in the archive

The millisecond of the last second will be normal if tv_sec is overflowed. But for y2038 consistency and demonstration purpose, and avoiding further risks, we need to remove 'timeval' in this driver, to avoid similair problems.

V2 Updates:
- using monotonic time here by replacing getnstimeofday() with ktime_get_ts64(), to avoid leap second issues. The frame time in USB is always 1ms, no matter what speed, so ktime_get_ts64() have enough resolution to cover this.
- using NSEC_PER_MSEC instead of hard code.

---
 drivers/usb/gadget/udc/dummy_hcd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/dummy_hcd.c +3 -3
index 1379ad4..6d1ed35 100644
@@ -833,10 +833,10 @@ static const struct usb_ep_ops dummy_ep_ops = {
 /* there are both host and device side versions of this call ... */
 static int dummy_g_get_frame(struct usb_gadget *_gadget)
 {
-	struct timeval	tv;
+	struct timespec64 tv;
 
-	do_gettimeofday(&tv);
-	return tv.tv_usec / 1000;
+	ktime_get_ts64(&tv);
+	return tv.tv_nsec / NSEC_PER_MSEC;
 }
 
 static int dummy_wakeup(struct usb_gadget *_gadget)
Signature · 1 line
1.9.1
author
#2 lore raw

add Alan Stern

Quoted 41 lines · WEN Pingbo

The millisecond of the last second will be normal if tv_sec is overflowed. But for y2038 consistency and demonstration purpose, and avoiding further risks, we need to remove 'timeval' in this driver, to avoid similair problems.

V2 Updates:
- using monotonic time here by replacing getnstimeofday() with ktime_get_ts64(), to avoid leap second issues. The frame time in USB is always 1ms, no matter what speed, so ktime_get_ts64() have enough resolution to cover this.
- using NSEC_PER_MSEC instead of hard code.

---
 drivers/usb/gadget/udc/dummy_hcd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/dummy_hcd.c +3 -3
index 1379ad4..6d1ed35 100644
@@ -833,10 +833,10 @@ static const struct usb_ep_ops dummy_ep_ops = {
 /* there are both host and device side versions of this call ... */
 static int dummy_g_get_frame(struct usb_gadget *_gadget)
 {
-	struct timeval	tv;
+	struct timespec64 tv;
 
-	do_gettimeofday(&tv);
-	return tv.tv_usec / 1000;
+	ktime_get_ts64(&tv);
+	return tv.tv_nsec / NSEC_PER_MSEC;
 }
 
 static int dummy_wakeup(struct usb_gadget *_gadget)
Reviewed-by on v2 1/1
#3 lore raw
In reply to WEN Pingbo
Quoted 12 lines · On Thursday 17 September 2015 11:09:49 WEN Pingbo wrote:

The millisecond of the last second will be normal if tv_sec is overflowed. But for y2038 consistency and demonstration purpose, and avoiding further risks, we need to remove 'timeval' in this driver, to avoid similair problems.

V2 Updates:
- using monotonic time here by replacing getnstimeofday() with ktime_get_ts64(), to avoid leap second issues. The frame time in USB is always 1ms, no matter what speed, so ktime_get_ts64() have enough resolution to cover this.
- using NSEC_PER_MSEC instead of hard code.

Quoted 7 lines

The patch looks good to me now,

Regarding the changelog, I notice you have a duplicate Signed-off-by line, one of the two should be removed. Also, The "V2 update" portion should be split into the part that you want in the changelog, without the '-' bullet points (in this case, the explanation for monontonic time), and the purely informational part that makes sense for the review but not for the git history (what changes were done against previous versions of the patch), which should go below the '---' line under the Signed-off-by chain, so it gets removed when imported to git.

If Felipe decides to do these changes himself when he applies the patch, that's fine, otherwise please send the patch again as 'V3' tomorrow.

Arnd

#5 lore raw
In reply to WEN Pingbo

drivers/usb/gadget/udc/dummy_hcd.c static const struct usb_ep_ops dummy_ep_ops = { · line 836

Quoted 7 lines · WEN Pingbo

+++ b/drivers/usb/gadget/udc/dummy_hcd.c

drivers/usb/gadget/udc/dummy_hcd.c +1 -1
@@ -833,10 +833,10 @@ static const struct usb_ep_ops dummy_ep_ops = {
 /* there are both host and device side versions of this call ... */
 static int dummy_g_get_frame(struct usb_gadget *_gadget)
 {
-	struct timeval	tv;
+	struct timespec64 tv;

tv is very often used for timeval structs.

I suggest also changing the variable name, for example to ts, to avoid some possible confusion.

//Peter

author
#6 lore raw
Quoted 11 lines · Peter Stuge

drivers/usb/gadget/udc/dummy_hcd.c static const struct usb_ep_ops dummy_ep_ops = { · line 836

Quoted 7 lines · WEN Pingbo

+++ b/drivers/usb/gadget/udc/dummy_hcd.c

drivers/usb/gadget/udc/dummy_hcd.c +1 -1
@@ -833,10 +833,10 @@ static const struct usb_ep_ops dummy_ep_ops = {
 /* there are both host and device side versions of this call ... */
 static int dummy_g_get_frame(struct usb_gadget *_gadget)
 {
-	struct timeval	tv;
+	struct timespec64 tv;

tv is very often used for timeval structs.

Quoted 3 lines

I suggest also changing the variable name, for example to ts, to avoid some possible confusion.

Hi Peter,

Thanks for pointing it out, I will fix it in next version.

Pingbo

author
#4 lore raw

PATCH v3 1/1 dummy_hcd: replace timeval with timespec64

In reply to Arnd Bergmann

The millisecond of the last second will be normal if tv_sec is overflowed. But for y2038 consistency and demonstration purpose, and avoiding further risks, we need to remove 'timeval' in this driver, to avoid similair problems.

---

V3 Updates:
- using ts64 variable name to avoid confusion

V2 Updates:
- using monotonic time here by replacing getnstimeofday() with ktime_get_ts64(), to avoid leap second issues. The frame time in USB is always 1ms, no matter what speed, so ktime_get_ts64() have enough resolution to cover this.
- using NSEC_PER_MSEC instead of hard code.

 drivers/usb/gadget/udc/dummy_hcd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/dummy_hcd.c +3 -3
index 1379ad4..2ac9a13 100644
@@ -833,10 +833,10 @@ static const struct usb_ep_ops dummy_ep_ops = {
 /* there are both host and device side versions of this call ... */
 static int dummy_g_get_frame(struct usb_gadget *_gadget)
 {
-	struct timeval	tv;
+	struct timespec64 ts64;
 
-	do_gettimeofday(&tv);
-	return tv.tv_usec / 1000;
+	ktime_get_ts64(&ts64);
+	return ts64.tv_nsec / NSEC_PER_MSEC;
 }
 
 static int dummy_wakeup(struct usb_gadget *_gadget)
Signature · 1 line
1.9.1