[<prev] [next>] [day] [month] [year] [list]
Message-ID: <158331970925.28353.877143831315554725.tip-bot2@tip-bot2>
Date: Wed, 04 Mar 2020 11:01:49 -0000
From: "tip-bot2 for Arnaldo Carvalho de Melo" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: Jiri Olsa <jolsa@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Namhyung Kim <namhyung@...nel.org>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
x86 <x86@...nel.org>, LKML <linux-kernel@...r.kernel.org>
Subject: [tip: perf/urgent] perf env: Do not return pointers to local variables
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: ebcb9464a2ae3a547e97de476575c82ece0e93e2
Gitweb: https://git.kernel.org/tip/ebcb9464a2ae3a547e97de476575c82ece0e93e2
Author: Arnaldo Carvalho de Melo <acme@...hat.com>
AuthorDate: Mon, 02 Mar 2020 11:23:03 -03:00
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitterDate: Mon, 02 Mar 2020 11:23:03 -03:00
perf env: Do not return pointers to local variables
It is possible to return a pointer to a local variable when looking up
the architecture name for the running system and no normalization is
done on that value, i.e. we may end up returning the uts.machine local
variable.
While this doesn't happen on most arches, as normalization takes place,
lets fix this by making that a static variable and optimize it a bit by
not always running uname(), only the first time.
Noticed in fedora rawhide running with:
[perfbuilder@...f49d6e6e4 ~]$ gcc --version
gcc (GCC) 10.0.1 20200216 (Red Hat 10.0.1-0.8)
Reported-by: Jiri Olsa <jolsa@...nel.org>
Cc: Adrian Hunter <adrian.hunter@...el.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/perf/util/env.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 6242a92..4154f94 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -343,11 +343,11 @@ static const char *normalize_arch(char *arch)
const char *perf_env__arch(struct perf_env *env)
{
- struct utsname uts;
char *arch_name;
if (!env || !env->arch) { /* Assume local operation */
- if (uname(&uts) < 0)
+ static struct utsname uts = { .machine[0] = '\0', };
+ if (uts.machine[0] == '\0' && uname(&uts) < 0)
return NULL;
arch_name = uts.machine;
} else
Powered by blists - more mailing lists