linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iw: Fix timestamp output on 32-bit architectures
@ 2021-03-18 22:46 Toke Høiland-Jørgensen
  0 siblings, 0 replies; only message in thread
From: Toke Høiland-Jørgensen @ 2021-03-18 22:46 UTC (permalink / raw)
  To: linux-wireless; +Cc: Toke Høiland-Jørgensen

On 32-bit architectures, time_t is 32-bit which causes overflows in the
arithmetic involving tv_sec, leading to invalid output. Fix this by
explicitly adding ULL suffixes to the constants used in those calculations.

Fixes: 3708f614dfdd ("iw: Print current time in station info dump")
Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
---
 station.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/station.c b/station.c
index bddea51815ee..002cf13526cc 100644
--- a/station.c
+++ b/station.c
@@ -337,7 +337,7 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 	unsigned long long now_ms;
 
 	gettimeofday(&now, NULL);
-	now_ms = now.tv_sec * 1000;
+	now_ms = now.tv_sec * 1000ULL;
 	now_ms += (now.tv_usec / 1000);
 
 	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
@@ -601,7 +601,7 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
 		unsigned long long assoc_at_ms;
 
 		clock_gettime(CLOCK_BOOTTIME, &now_ts);
-		boot_ns = now_ts.tv_sec * 1000000000;
+		boot_ns = now_ts.tv_sec * 1000000000ULL;
 		boot_ns += now_ts.tv_nsec;
 
 		bt = (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-18 22:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 22:46 [PATCH] iw: Fix timestamp output on 32-bit architectures Toke Høiland-Jørgensen

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