Skip to contentSkip to conversation

net: ipv4: Fix truncated timestamp returned by inet_current_timestamp()

PATCH RESEND In review Deepa Dinamani 2 participants 2 messages Mar 22, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 net: ipv4: Fix truncated timestamp returned by inet_current_timestamp()

The millisecond timestamps returned by the function is converted to network byte order by making a call to htons(). htons() only returns __be16 while __be32 is required here.

This was identified by the sparse warning from the buildbot:
net/ipv4/af_inet.c:1405:16: sparse: incorrect type in return
expression (different base types)
net/ipv4/af_inet.c:1405:16: expected restricted __be32 net/ipv4/af_inet.c:1405:16: got restricted __be16 [usertype] <noident>

Change the function to use htonl() to return the correct __be32 type instead so that the millisecond value doesn't get truncated.

Cc "David S. Miller" <[email protected]>
Cc Alexey Kuznetsov <[email protected]>
Cc Hideaki YOSHIFUJI <[email protected]>
Cc James Morris <[email protected]>
Cc Patrick McHardy <[email protected]>
Cc Arnd Bergmann <[email protected]>
Fixes 822c868532ca ("net: ipv4: Convert IP network timestamps to be y2038 safe")

---
Fixed the y2038 list email address.

 net/ipv4/af_inet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/af_inet.c +1 -1
index 0cc923f..5fab7e3 100644
@@ -1402,7 +1402,7 @@ __be32 inet_current_timestamp(void)
 	msecs += (u32)ts.tv_nsec / NSEC_PER_MSEC;
 
 	/* Convert to network byte order. */
-	return htons(msecs);
+	return htonl(msecs);
 }
 EXPORT_SYMBOL(inet_current_timestamp);
 
Signature · 1 line
1.9.1
maintainer
#1 lore raw

From: Deepa Dinamani <[email protected]>
Date: Mon, 21 Mar 2016 18:21:26 -0700

Quoted 13 lines

The millisecond timestamps returned by the function is converted to network byte order by making a call to htons(). htons() only returns __be16 while __be32 is required here.

This was identified by the sparse warning from the buildbot:
net/ipv4/af_inet.c:1405:16: sparse: incorrect type in return
expression (different base types)
net/ipv4/af_inet.c:1405:16: expected restricted __be32 net/ipv4/af_inet.c:1405:16: got restricted __be16 [usertype] <noident>

Change the function to use htonl() to return the correct __be32 type instead so that the millisecond value doesn't get truncated.

Quoted 9 lines
Cc "David S. Miller" <[email protected]>
Cc Alexey Kuznetsov <[email protected]>
Cc Hideaki YOSHIFUJI <[email protected]>
Cc James Morris <[email protected]>
Cc Patrick McHardy <[email protected]>
Cc Arnd Bergmann <[email protected]>
Fixes 822c868532ca ("net: ipv4: Convert IP network timestamps to be y2038 safe")

Applied and queued up for -stable.