Commit 9a311550 authored by Ian Rogers's avatar Ian Rogers Committed by Wentao Guan
Browse files

perf time-utils: Fix 32-bit nsec parsing

stable inclusion
from stable-v6.6.54
commit 3ba5a2e91c706bd55a34ccc1a0db4b0e4d0d2054
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAZ3K2

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=3ba5a2e91c706bd55a34ccc1a0db4b0e4d0d2054



--------------------------------

[ Upstream commit 38e2648a81204c9fc5b4c87a8ffce93a6ed91b65 ]

The "time utils" test fails in 32-bit builds:
  ...
  parse_nsec_time("18446744073.709551615")
  Failed. ptime 4294967295709551615 expected 18446744073709551615
  ...

Switch strtoul to strtoull as an unsigned long in 32-bit build isn't
64-bits.

Fixes: c284d669 ("perf tools: Move parse_nsec_time to time-utils.c")
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: David Ahern <dsa@cumulusnetworks.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Junhao He <hejunhao3@huawei.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yang Jihong <yangjihong@bytedance.com>
Link: https://lore.kernel.org/r/20240831070415.506194-3-irogers@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
(cherry picked from commit 3ba5a2e91c706bd55a34ccc1a0db4b0e4d0d2054)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent d63cc1d9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ int parse_nsec_time(const char *str, u64 *ptime)
	u64 time_sec, time_nsec;
	char *end;

	time_sec = strtoul(str, &end, 10);
	time_sec = strtoull(str, &end, 10);
	if (*end != '.' && *end != '\0')
		return -1;

@@ -38,7 +38,7 @@ int parse_nsec_time(const char *str, u64 *ptime)
		for (i = strlen(nsec_buf); i < 9; i++)
			nsec_buf[i] = '0';

		time_nsec = strtoul(nsec_buf, &end, 10);
		time_nsec = strtoull(nsec_buf, &end, 10);
		if (*end != '\0')
			return -1;
	} else