diff mbox

[3/4] net: ipv4: tcp_probe: Replace timespec with timespec64

Message ID 1456384031-29244-4-git-send-email-deepa.kernel@gmail.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Deepa Dinamani Feb. 25, 2016, 7:07 a.m. UTC
TCP probe log timestamps use struct timespec which is
not y2038 safe. Even though timespec might be good enough here
as it is used to represent delta time, the plan is to get rid
of all uses of timespec in the kernel.
Replace with struct timespec64 which is y2038 safe.

Prints still use unsigned long format and type.
This is because long is 64 bit on 64 bit systems and 32 bit on
32 bit systems. Hence, time64_t(64 bit signed number) does not
have a specifier that matches on both architectures.

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Cc: James Morris <jmorris@namei.org>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/tcp_probe.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Arnd Bergmann Feb. 25, 2016, 3:01 p.m. UTC | #1
On Wednesday 24 February 2016 23:07:10 Deepa Dinamani wrote:
> TCP probe log timestamps use struct timespec which is
> not y2038 safe. Even though timespec might be good enough here
> as it is used to represent delta time, the plan is to get rid
> of all uses of timespec in the kernel.
> Replace with struct timespec64 which is y2038 safe.
> 
> Prints still use unsigned long format and type.
> This is because long is 64 bit on 64 bit systems and 32 bit on
> 32 bit systems. Hence, time64_t(64 bit signed number) does not
> have a specifier that matches on both architectures.

Actually time64_t is always 'long long', but tv_sec is time_t 
(long) instead of time64_t on 64-bit architectures.

Using a %ll format string and a cast to s64 would work as well,
but as you say above, it's not important here.

> Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>

Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Deepa Dinamani Feb. 27, 2016, 2:56 a.m. UTC | #2
On Thu, Feb 25, 2016 at 8:31 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Wednesday 24 February 2016 23:07:10 Deepa Dinamani wrote:
>> TCP probe log timestamps use struct timespec which is
>> not y2038 safe. Even though timespec might be good enough here
>> as it is used to represent delta time, the plan is to get rid
>> of all uses of timespec in the kernel.
>> Replace with struct timespec64 which is y2038 safe.
>>
>> Prints still use unsigned long format and type.
>> This is because long is 64 bit on 64 bit systems and 32 bit on
>> 32 bit systems. Hence, time64_t(64 bit signed number) does not
>> have a specifier that matches on both architectures.
>
> Actually time64_t is always 'long long', but tv_sec is time_t
> (long) instead of time64_t on 64-bit architectures.
>
> Using a %ll format string and a cast to s64 would work as well,
> but as you say above, it's not important here.

You are right. A cast to u64 would work as well.
I missed that the size of long long on 64 bit architectures according
to all current
data models is equivalent to long.

I will leave the prints to be in long format.
But, will reword the commit text in v2.

Thanks,
-Deepa
diff mbox

Patch

diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
index ebf5ff5..f6c50af 100644
--- a/net/ipv4/tcp_probe.c
+++ b/net/ipv4/tcp_probe.c
@@ -187,13 +187,13 @@  static int tcpprobe_sprint(char *tbuf, int n)
 {
 	const struct tcp_log *p
 		= tcp_probe.log + tcp_probe.tail;
-	struct timespec tv
-		= ktime_to_timespec(ktime_sub(p->tstamp, tcp_probe.start));
+	struct timespec64 ts
+		= ktime_to_timespec64(ktime_sub(p->tstamp, tcp_probe.start));
 
 	return scnprintf(tbuf, n,
 			"%lu.%09lu %pISpc %pISpc %d %#x %#x %u %u %u %u %u\n",
-			(unsigned long)tv.tv_sec,
-			(unsigned long)tv.tv_nsec,
+			(unsigned long)ts.tv_sec,
+			(unsigned long)ts.tv_nsec,
 			&p->src, &p->dst, p->length, p->snd_nxt, p->snd_una,
 			p->snd_cwnd, p->ssthresh, p->snd_wnd, p->srtt, p->rcv_wnd);
 }