tools: Adopt __printf from kernel sources

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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 6c346643
...@@ -21,3 +21,5 @@ ...@@ -21,3 +21,5 @@
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
#define __noreturn __attribute__((noreturn)) #define __noreturn __attribute__((noreturn))
#define __printf(a, b) __attribute__((format(printf, a, b)))
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <api/fs/fs.h> #include <api/fs/fs.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/compiler.h>
#include <linux/coresight-pmu.h> #include <linux/coresight-pmu.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/log2.h> #include <linux/log2.h>
...@@ -583,8 +584,7 @@ static FILE *cs_device__open_file(const char *name) ...@@ -583,8 +584,7 @@ static FILE *cs_device__open_file(const char *name)
} }
static __attribute__((format(printf, 2, 3))) static int __printf(2, 3) cs_device__print_file(const char *name, const char *fmt, ...)
int cs_device__print_file(const char *name, const char *fmt, ...)
{ {
va_list args; va_list args;
FILE *file; FILE *file;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <subcmd/pager.h> #include <subcmd/pager.h>
#include "../ui/ui.h" #include "../ui/ui.h"
#include <linux/compiler.h>
#include <linux/string.h> #include <linux/string.h>
#define CMD_EXEC_PATH "--exec-path" #define CMD_EXEC_PATH "--exec-path"
...@@ -24,6 +25,6 @@ static inline int is_absolute_path(const char *path) ...@@ -24,6 +25,6 @@ static inline int is_absolute_path(const char *path)
return path[0] == '/'; 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 */ #endif /* __PERF_CACHE_H */
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <linux/compiler.h>
#include "event.h" #include "event.h"
#include "../ui/helpline.h" #include "../ui/helpline.h"
#include "../ui/progress.h" #include "../ui/progress.h"
...@@ -40,16 +41,16 @@ extern int debug_data_convert; ...@@ -40,16 +41,16 @@ extern int debug_data_convert;
#define STRERR_BUFSIZE 128 /* For the buffer size of str_error_r */ #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); void trace_event(union perf_event *event);
int ui__error(const char *format, ...) __attribute__((format(printf, 1, 2))); int ui__error(const char *format, ...) __printf(1, 2);
int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2))); int ui__warning(const char *format, ...) __printf(1, 2);
void pr_stat(const char *fmt, ...); void pr_stat(const char *fmt, ...);
int eprintf(int level, int var, const char *fmt, ...) __attribute__((format(printf, 3, 4))); int eprintf(int level, int var, const char *fmt, ...) __printf(3, 4);
int eprintf_time(int level, int var, u64 t, const char *fmt, ...) __attribute__((format(printf, 4, 5))); 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 veprintf(int level, int var, const char *fmt, va_list args);
int perf_debug_option(const char *str); int perf_debug_option(const char *str);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#ifndef INCLUDE__INTEL_PT_LOG_H__ #ifndef INCLUDE__INTEL_PT_LOG_H__
#define INCLUDE__INTEL_PT_LOG_H__ #define INCLUDE__INTEL_PT_LOG_H__
#include <linux/compiler.h>
#include <stdint.h> #include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
...@@ -34,8 +35,7 @@ void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip); ...@@ -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, void __intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn,
uint64_t ip); uint64_t ip);
__attribute__((format(printf, 1, 2))) void __intel_pt_log(const char *fmt, ...) __printf(1, 2);
void __intel_pt_log(const char *fmt, ...);
#define intel_pt_log(fmt, ...) \ #define intel_pt_log(fmt, ...) \
do { \ do { \
......
#ifndef _PROBE_EVENT_H #ifndef _PROBE_EVENT_H
#define _PROBE_EVENT_H #define _PROBE_EVENT_H
#include <linux/compiler.h>
#include <stdbool.h> #include <stdbool.h>
#include "intlist.h" #include "intlist.h"
...@@ -171,8 +172,7 @@ void arch__fix_tev_from_maps(struct perf_probe_event *pev, ...@@ -171,8 +172,7 @@ void arch__fix_tev_from_maps(struct perf_probe_event *pev,
struct symbol *sym); struct symbol *sym);
/* If there is no space to write, returns -E2BIG. */ /* If there is no space to write, returns -E2BIG. */
int e_snprintf(char *str, size_t size, const char *format, ...) int e_snprintf(char *str, size_t size, const char *format, ...) __printf(3, 4);
__attribute__((format(printf, 3, 4)));
/* Maximum index number of event-name postfix */ /* Maximum index number of event-name postfix */
#define MAX_EVENT_INDEX 1024 #define MAX_EVENT_INDEX 1024
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <linux/compiler.h>
#include <sys/types.h> #include <sys/types.h>
extern char strbuf_slopbuf[]; extern char strbuf_slopbuf[];
...@@ -85,8 +86,7 @@ static inline int strbuf_addstr(struct strbuf *sb, const char *s) { ...@@ -85,8 +86,7 @@ static inline int strbuf_addstr(struct strbuf *sb, const char *s) {
return strbuf_add(sb, s, strlen(s)); return strbuf_add(sb, s, strlen(s));
} }
__attribute__((format(printf,2,3))) int strbuf_addf(struct strbuf *sb, const char *fmt, ...) __printf(2, 3);
int strbuf_addf(struct strbuf *sb, const char *fmt, ...);
/* XXX: if read fails, any partial read is undone */ /* XXX: if read fails, any partial read is undone */
ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint); ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint);
......
...@@ -14,17 +14,11 @@ ...@@ -14,17 +14,11 @@
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/types.h> #include <linux/types.h>
#ifndef __GNUC__
#ifndef __attribute__
#define __attribute__(x)
#endif
#endif
/* General helper functions */ /* General helper functions */
void usage(const char *err) __noreturn; void usage(const char *err) __noreturn;
void die(const char *err, ...) __noreturn __attribute__((format (printf, 1, 2))); void die(const char *err, ...) __noreturn __printf(1, 2);
int error(const char *err, ...) __attribute__((format (printf, 1, 2))); int error(const char *err, ...) __printf(1, 2);
void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); void warning(const char *err, ...) __printf(1, 2);
void set_warning_routine(void (*routine)(const char *err, va_list params)); void set_warning_routine(void (*routine)(const char *err, va_list params));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment