Messages in this thread Patch in this message | | | Date | Thu, 20 Dec 2018 12:36:21 -0500 | From | Steven Rostedt <> | Subject | [PATCH] perf: Use strcmp() for "ftrace:function" check |
| |
As strncmp(str, "const", sizeof("const") is exactly the same as strcmp(str, "const") use that instead, otherwise it is confusing.
The test if the event name is "ftrace:function" in perf_evsel__set_sample_id() is rather strange as it makes an unnecessary macro of FUNCTION_EVENT to equal "ftrace:function" and uses that twice so that it can do the sizeof(). But since sizeof("const") includes the nul terminator ('\0') of the string "const" that compare is the same as using strcmp().
With strcmp() there's no need to use the string twice, and that also means the FUNCTION_EVENT macro is not needed.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> --- diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d37bb1566cd9..58a452d77951 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -215,12 +215,7 @@ void perf_evsel__set_sample_id(struct perf_evsel *evsel, */ bool perf_evsel__is_function_event(struct perf_evsel *evsel) { -#define FUNCTION_EVENT "ftrace:function" - - return evsel->name && - !strncmp(FUNCTION_EVENT, evsel->name, sizeof(FUNCTION_EVENT)); - -#undef FUNCTION_EVENT + return evsel->name && !strcmp("ftrace:function", evsel->name); } void perf_evsel__init(struct perf_evsel *evsel,
| |