All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Kim Phillips <kim.phillips@arm.com>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 06/23] tools: Adopt __printf from kernel sources
Date: Mon, 19 Jun 2017 22:54:42 -0300	[thread overview]
Message-ID: <20170620015459.29381-7-acme@kernel.org> (raw)
In-Reply-To: <20170620015459.29381-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

To have a more compact way to ask the compiler to perform printf like
vargargs validation.

v2: Fixed up build on arm, squashing a patch by Kim Phillips, thanks!

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-dopkqmmuqs04cxzql0024nnu@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/include/linux/compiler-gcc.h              |  2 ++
 tools/perf/arch/arm/util/cs-etm.c               |  4 ++--
 tools/perf/util/cache.h                         |  3 ++-
 tools/perf/util/debug.h                         | 11 ++++++-----
 tools/perf/util/intel-pt-decoder/intel-pt-log.h |  4 ++--
 tools/perf/util/probe-event.h                   |  4 ++--
 tools/perf/util/strbuf.h                        |  4 ++--
 tools/perf/util/util.h                          | 12 +++---------
 8 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h
index a3deb74cb070..f531b258ff94 100644
--- a/tools/include/linux/compiler-gcc.h
+++ b/tools/include/linux/compiler-gcc.h
@@ -21,3 +21,5 @@
 #define __must_be_array(a)	BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
 
 #define __noreturn	__attribute__((noreturn))
+
+#define __printf(a, b)	__attribute__((format(printf, a, b)))
diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 29361d9b635a..02a649bfec3c 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -17,6 +17,7 @@
 
 #include <api/fs/fs.h>
 #include <linux/bitops.h>
+#include <linux/compiler.h>
 #include <linux/coresight-pmu.h>
 #include <linux/kernel.h>
 #include <linux/log2.h>
@@ -583,8 +584,7 @@ static FILE *cs_device__open_file(const char *name)
 
 }
 
-static __attribute__((format(printf, 2, 3)))
-int cs_device__print_file(const char *name, const char *fmt, ...)
+static int __printf(2, 3) cs_device__print_file(const char *name, const char *fmt, ...)
 {
 	va_list args;
 	FILE *file;
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 0328f297a748..0175765c05b9 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -5,6 +5,7 @@
 #include <subcmd/pager.h>
 #include "../ui/ui.h"
 
+#include <linux/compiler.h>
 #include <linux/string.h>
 
 #define CMD_EXEC_PATH "--exec-path"
@@ -24,6 +25,6 @@ static inline int is_absolute_path(const char *path)
 	return path[0] == '/';
 }
 
-char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+char *mkpath(const char *fmt, ...) __printf(1, 2);
 
 #endif /* __PERF_CACHE_H */
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h
index 8a23ea1a71c7..c818bdb1c1ab 100644
--- a/tools/perf/util/debug.h
+++ b/tools/perf/util/debug.h
@@ -4,6 +4,7 @@
 
 #include <stdbool.h>
 #include <string.h>
+#include <linux/compiler.h>
 #include "event.h"
 #include "../ui/helpline.h"
 #include "../ui/progress.h"
@@ -40,16 +41,16 @@ extern int debug_data_convert;
 
 #define STRERR_BUFSIZE	128	/* For the buffer size of str_error_r */
 
-int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
+int dump_printf(const char *fmt, ...) __printf(1, 2);
 void trace_event(union perf_event *event);
 
-int ui__error(const char *format, ...) __attribute__((format(printf, 1, 2)));
-int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
+int ui__error(const char *format, ...) __printf(1, 2);
+int ui__warning(const char *format, ...) __printf(1, 2);
 
 void pr_stat(const char *fmt, ...);
 
-int eprintf(int level, int var, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
-int eprintf_time(int level, int var, u64 t, const char *fmt, ...) __attribute__((format(printf, 4, 5)));
+int eprintf(int level, int var, const char *fmt, ...) __printf(3, 4);
+int eprintf_time(int level, int var, u64 t, const char *fmt, ...) __printf(4, 5);
 int veprintf(int level, int var, const char *fmt, va_list args);
 
 int perf_debug_option(const char *str);
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-log.h b/tools/perf/util/intel-pt-decoder/intel-pt-log.h
index debe751dc3d6..45b64f93f358 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-log.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-log.h
@@ -16,6 +16,7 @@
 #ifndef INCLUDE__INTEL_PT_LOG_H__
 #define INCLUDE__INTEL_PT_LOG_H__
 
+#include <linux/compiler.h>
 #include <stdint.h>
 #include <inttypes.h>
 
@@ -34,8 +35,7 @@ void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip);
 void __intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn,
 				 uint64_t ip);
 
-__attribute__((format(printf, 1, 2)))
-void __intel_pt_log(const char *fmt, ...);
+void __intel_pt_log(const char *fmt, ...) __printf(1, 2);
 
 #define intel_pt_log(fmt, ...) \
 	do { \
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 373842656fb6..5812947418dd 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -1,6 +1,7 @@
 #ifndef _PROBE_EVENT_H
 #define _PROBE_EVENT_H
 
+#include <linux/compiler.h>
 #include <stdbool.h>
 #include "intlist.h"
 
@@ -171,8 +172,7 @@ void arch__fix_tev_from_maps(struct perf_probe_event *pev,
 			     struct symbol *sym);
 
 /* If there is no space to write, returns -E2BIG. */
-int e_snprintf(char *str, size_t size, const char *format, ...)
-	__attribute__((format(printf, 3, 4)));
+int e_snprintf(char *str, size_t size, const char *format, ...) __printf(3, 4);
 
 /* Maximum index number of event-name postfix */
 #define MAX_EVENT_INDEX	1024
diff --git a/tools/perf/util/strbuf.h b/tools/perf/util/strbuf.h
index 318424ea561d..802d743378af 100644
--- a/tools/perf/util/strbuf.h
+++ b/tools/perf/util/strbuf.h
@@ -42,6 +42,7 @@
 #include <stdarg.h>
 #include <stddef.h>
 #include <string.h>
+#include <linux/compiler.h>
 #include <sys/types.h>
 
 extern char strbuf_slopbuf[];
@@ -85,8 +86,7 @@ static inline int strbuf_addstr(struct strbuf *sb, const char *s) {
 	return strbuf_add(sb, s, strlen(s));
 }
 
-__attribute__((format(printf,2,3)))
-int strbuf_addf(struct strbuf *sb, const char *fmt, ...);
+int strbuf_addf(struct strbuf *sb, const char *fmt, ...) __printf(2, 3);
 
 /* XXX: if read fails, any partial read is undone */
 ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint);
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 024b108dbbf6..21c6db173bcc 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -14,17 +14,11 @@
 #include <linux/compiler.h>
 #include <linux/types.h>
 
-#ifndef __GNUC__
-#ifndef __attribute__
-#define __attribute__(x)
-#endif
-#endif
-
 /* General helper functions */
 void usage(const char *err) __noreturn;
-void die(const char *err, ...) __noreturn __attribute__((format (printf, 1, 2)));
-int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
-void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
+void die(const char *err, ...) __noreturn __printf(1, 2);
+int error(const char *err, ...) __printf(1, 2);
+void warning(const char *err, ...) __printf(1, 2);
 
 void set_warning_routine(void (*routine)(const char *err, va_list params));
 
-- 
2.9.4

  parent reply	other threads:[~2017-06-20  2:02 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-20  1:54 [GIT PULL 00/23] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-06-20  1:54 ` Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 01/23] perf report: Remove unnecessary check in annotate_browser_write() Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 02/23] perf annotate browser: Display titles in left frame Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 03/23] perf config: Invert an if statement to reduce nesting in cmd_config() Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 04/23] perf script: Allow adding and removing fields Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 05/23] tools: Adopt __noreturn from kernel sources Arnaldo Carvalho de Melo
2017-06-20  1:54 ` Arnaldo Carvalho de Melo [this message]
2017-06-20  1:54 ` [PATCH 07/23] tools: Adopt __scanf " Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 08/23] perf tools: Use __maybe_unused consistently Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 09/23] tools: Adopt noinline from kernel sources Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 10/23] tools: Adopt __packed " Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 11/23] tools: Adopt __aligned " Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 12/23] perf coresight: Remove superfluous check before use Arnaldo Carvalho de Melo
2017-06-20  1:54   ` Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 13/23] perf intel-pt/bts: Remove unused SAMPLE_SIZE defines and bts priv array Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 14/23] perf annotate: Return arch from symbol__disassemble() and save it in browser Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 15/23] perf test llvm: Avoid error when PROFILE_ALL_BRANCHES is set Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 16/23] perf script: Support -F brstack,dso and brstacksym,dso Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 17/23] perf script: Support -F brstackoff,dso Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 18/23] perf ftrace: Show error message when fails to set ftrace files Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 19/23] perf ftrace: Move setup_pager before opening trace_pipe Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 20/23] perf ftrace: Add option for function filtering Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 21/23] perf ftrace: Add -D option for depth filter Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 22/23] perf config: Check error cases of {show_spec, set}_config() Arnaldo Carvalho de Melo
2017-06-20  1:54 ` [PATCH 23/23] perf config: Refactor the code using 'ret' variable in cmd_config() Arnaldo Carvalho de Melo
2017-06-20  8:50 ` [GIT PULL 00/23] perf/core improvements and fixes Ingo Molnar
2017-06-20  8:50   ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170620015459.29381-7-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kim.phillips@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.