public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3)
@ 2014-01-09 14:00 Namhyung Kim
  2014-01-09 14:00 ` [PATCH 1/8] tools include: Move perf's linux/compiler.h to a generic place Namhyung Kim
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Namhyung Kim @ 2014-01-09 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Jiri Olsa, Frederic Weisbecker, Ingo Molnar, LKML, Namhyung Kim

Hello,

* changes in v3)
 - move related header files to tools/include/ (Arnaldo)
 - add WARN_ONCE() when a trace_seq misused (Jiri)
 - add ack's from Jiri

You can also get this on the 'libtraceevent/die-removal-v6' branch in my tree

  git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Any comments are welcome, thanks
Namhyung


Namhyung Kim (8):
  tools include: Move perf's linux/compiler.h to a generic place
  tools include: Define likely/unlikely in linux/compiler.h
  tools include: Move perf's bug.h to a generic place
  tools include: Include <linux/compiler.h> from asm/bug.h
  tools lib traceevent: Add state member to struct trace_seq
  tools lib traceevent: Check return value of realloc()
  tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init()
  tools lib traceevent: Get rid of die() finally!!

 tools/include/asm/bug.h                  |   25 +++++++++++++
 tools/include/linux/compiler.h           |   38 ++++++++++++++++++++
 tools/lib/traceevent/Makefile            |    2 +-
 tools/lib/traceevent/event-parse.h       |    7 ++++
 tools/lib/traceevent/event-utils.h       |    4 ---
 tools/lib/traceevent/parse-utils.c       |   44 -----------------------
 tools/lib/traceevent/trace-seq.c         |   58 ++++++++++++++++++++++++++----
 tools/perf/Makefile.perf                 |    4 +--
 tools/perf/config/Makefile               |    1 +
 tools/perf/util/include/asm/bug.h        |   22 ------------
 tools/perf/util/include/linux/compiler.h |   30 ----------------
 11 files changed, 125 insertions(+), 110 deletions(-)
 create mode 100644 tools/include/asm/bug.h
 create mode 100644 tools/include/linux/compiler.h
 delete mode 100644 tools/perf/util/include/asm/bug.h
 delete mode 100644 tools/perf/util/include/linux/compiler.h

-- 
1.7.9.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/8] tools include: Move perf's linux/compiler.h to a generic place
  2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
@ 2014-01-09 14:00 ` Namhyung Kim
  2014-01-14 16:40   ` [tip:perf/core] tools include: Move perf's linux/ compiler.h " tip-bot for Namhyung Kim
  2014-01-09 14:00 ` [PATCH 2/8] tools include: Define likely/unlikely in linux/compiler.h Namhyung Kim
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Namhyung Kim @ 2014-01-09 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Jiri Olsa, Frederic Weisbecker, Ingo Molnar, LKML, Namhyung Kim

So that it can be shared with others like libtraceevent.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/include/linux/compiler.h           |   30 ++++++++++++++++++++++++++++++
 tools/perf/Makefile.perf                 |    2 +-
 tools/perf/config/Makefile               |    1 +
 tools/perf/util/include/linux/compiler.h |   30 ------------------------------
 4 files changed, 32 insertions(+), 31 deletions(-)
 create mode 100644 tools/include/linux/compiler.h
 delete mode 100644 tools/perf/util/include/linux/compiler.h

diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
new file mode 100644
index 000000000000..0135ccf2a00c
--- /dev/null
+++ b/tools/include/linux/compiler.h
@@ -0,0 +1,30 @@
+#ifndef _TOOLS_LINUX_COMPILER_H_
+#define _TOOLS_LINUX_COMPILER_H_
+
+#ifndef __always_inline
+# define __always_inline	inline __attribute__((always_inline))
+#endif
+
+#define __user
+
+#ifndef __attribute_const__
+# define __attribute_const__
+#endif
+
+#ifndef __maybe_unused
+# define __maybe_unused		__attribute__((unused))
+#endif
+
+#ifndef __packed
+# define __packed		__attribute__((__packed__))
+#endif
+
+#ifndef __force
+# define __force
+#endif
+
+#ifndef __weak
+# define __weak			__attribute__((weak))
+#endif
+
+#endif /* _TOOLS_LINUX_COMPILER_H */
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 3638b0bd20dc..6be06767da7b 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -211,7 +211,7 @@ LIB_H += ../../include/linux/hash.h
 LIB_H += ../../include/linux/stringify.h
 LIB_H += util/include/linux/bitmap.h
 LIB_H += util/include/linux/bitops.h
-LIB_H += util/include/linux/compiler.h
+LIB_H += ../include/linux/compiler.h
 LIB_H += util/include/linux/const.h
 LIB_H += util/include/linux/ctype.h
 LIB_H += util/include/linux/kernel.h
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index f2bc659d20af..600d39781d11 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -224,6 +224,7 @@ endif
 
 CFLAGS += -I$(src-perf)/util/include
 CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
+CFLAGS += -I$(srctree)/tools/include/
 CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
 CFLAGS += -I$(srctree)/arch/$(ARCH)/include
 CFLAGS += -I$(srctree)/include/uapi
diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
deleted file mode 100644
index b003ad7200b2..000000000000
--- a/tools/perf/util/include/linux/compiler.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef _PERF_LINUX_COMPILER_H_
-#define _PERF_LINUX_COMPILER_H_
-
-#ifndef __always_inline
-# define __always_inline	inline __attribute__((always_inline))
-#endif
-
-#define __user
-
-#ifndef __attribute_const__
-# define __attribute_const__
-#endif
-
-#ifndef __maybe_unused
-# define __maybe_unused		__attribute__((unused))
-#endif
-
-#ifndef __packed
-# define __packed		__attribute__((__packed__))
-#endif
-
-#ifndef __force
-# define __force
-#endif
-
-#ifndef __weak
-# define __weak			__attribute__((weak))
-#endif
-
-#endif
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/8] tools include: Define likely/unlikely in linux/compiler.h
  2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
  2014-01-09 14:00 ` [PATCH 1/8] tools include: Move perf's linux/compiler.h to a generic place Namhyung Kim
@ 2014-01-09 14:00 ` Namhyung Kim
  2014-01-14 16:40   ` [tip:perf/core] tools include: Define likely/unlikely in linux/ compiler.h tip-bot for Namhyung Kim
  2014-01-09 14:00 ` [PATCH 3/8] tools include: Move perf's bug.h to a generic place Namhyung Kim
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Namhyung Kim @ 2014-01-09 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Jiri Olsa, Frederic Weisbecker, Ingo Molnar, LKML, Namhyung Kim

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/include/linux/compiler.h |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index 0135ccf2a00c..fbc6665c6d53 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -27,4 +27,12 @@
 # define __weak			__attribute__((weak))
 #endif
 
+#ifndef likely
+# define likely(x)		__builtin_expect(!!(x), 1)
+#endif
+
+#ifndef unlikely
+# define unlikely(x)		__builtin_expect(!!(x), 0)
+#endif
+
 #endif /* _TOOLS_LINUX_COMPILER_H */
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/8] tools include: Move perf's bug.h to a generic place
  2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
  2014-01-09 14:00 ` [PATCH 1/8] tools include: Move perf's linux/compiler.h to a generic place Namhyung Kim
  2014-01-09 14:00 ` [PATCH 2/8] tools include: Define likely/unlikely in linux/compiler.h Namhyung Kim
@ 2014-01-09 14:00 ` Namhyung Kim
  2014-01-14 16:40   ` [tip:perf/core] tools include: Move perf' s " tip-bot for Namhyung Kim
  2014-01-09 14:00 ` [PATCH 4/8] tools include: Include <linux/compiler.h> from asm/bug.h Namhyung Kim
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Namhyung Kim @ 2014-01-09 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Jiri Olsa, Frederic Weisbecker, Ingo Molnar, LKML, Namhyung Kim

So that it can be shared with others like libtraceevent.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/include/asm/bug.h           |   23 +++++++++++++++++++++++
 tools/perf/Makefile.perf          |    2 +-
 tools/perf/util/include/asm/bug.h |   22 ----------------------
 3 files changed, 24 insertions(+), 23 deletions(-)
 create mode 100644 tools/include/asm/bug.h
 delete mode 100644 tools/perf/util/include/asm/bug.h

diff --git a/tools/include/asm/bug.h b/tools/include/asm/bug.h
new file mode 100644
index 000000000000..eca78df7b8f2
--- /dev/null
+++ b/tools/include/asm/bug.h
@@ -0,0 +1,23 @@
+#ifndef _TOOLS_ASM_BUG_H
+#define _TOOLS_ASM_BUG_H
+
+#define __WARN_printf(arg...)	do { fprintf(stderr, arg); } while (0)
+
+#define WARN(condition, format...) ({		\
+	int __ret_warn_on = !!(condition);	\
+	if (unlikely(__ret_warn_on))		\
+		__WARN_printf(format);		\
+	unlikely(__ret_warn_on);		\
+})
+
+#define WARN_ONCE(condition, format...)	({	\
+	static int __warned;			\
+	int __ret_warn_once = !!(condition);	\
+						\
+	if (unlikely(__ret_warn_once))		\
+		if (WARN(!__warned, format)) 	\
+			__warned = 1;		\
+	unlikely(__ret_warn_once);		\
+})
+
+#endif /* _TOOLS_ASM_BUG_H */
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 6be06767da7b..87d7726cee2d 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -226,7 +226,7 @@ LIB_H += util/include/linux/string.h
 LIB_H += util/include/linux/types.h
 LIB_H += util/include/linux/linkage.h
 LIB_H += util/include/asm/asm-offsets.h
-LIB_H += util/include/asm/bug.h
+LIB_H += ../include/asm/bug.h
 LIB_H += util/include/asm/byteorder.h
 LIB_H += util/include/asm/hweight.h
 LIB_H += util/include/asm/swab.h
diff --git a/tools/perf/util/include/asm/bug.h b/tools/perf/util/include/asm/bug.h
deleted file mode 100644
index 7fcc6810adc2..000000000000
--- a/tools/perf/util/include/asm/bug.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef _PERF_ASM_GENERIC_BUG_H
-#define _PERF_ASM_GENERIC_BUG_H
-
-#define __WARN_printf(arg...)	do { fprintf(stderr, arg); } while (0)
-
-#define WARN(condition, format...) ({		\
-	int __ret_warn_on = !!(condition);	\
-	if (unlikely(__ret_warn_on))		\
-		__WARN_printf(format);		\
-	unlikely(__ret_warn_on);		\
-})
-
-#define WARN_ONCE(condition, format...)	({	\
-	static int __warned;			\
-	int __ret_warn_once = !!(condition);	\
-						\
-	if (unlikely(__ret_warn_once))		\
-		if (WARN(!__warned, format)) 	\
-			__warned = 1;		\
-	unlikely(__ret_warn_once);		\
-})
-#endif
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/8] tools include: Include <linux/compiler.h> from asm/bug.h
  2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
                   ` (2 preceding siblings ...)
  2014-01-09 14:00 ` [PATCH 3/8] tools include: Move perf's bug.h to a generic place Namhyung Kim
@ 2014-01-09 14:00 ` Namhyung Kim
  2014-01-14 16:41   ` [tip:perf/core] " tip-bot for Namhyung Kim
  2014-01-09 14:00 ` [PATCH 5/8] tools lib traceevent: Add state member to struct trace_seq Namhyung Kim
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Namhyung Kim @ 2014-01-09 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Jiri Olsa, Frederic Weisbecker, Ingo Molnar, LKML, Namhyung Kim

Since it uses unlikely() macro inside WARN()

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/include/asm/bug.h |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/include/asm/bug.h b/tools/include/asm/bug.h
index eca78df7b8f2..9e5f4846967f 100644
--- a/tools/include/asm/bug.h
+++ b/tools/include/asm/bug.h
@@ -1,6 +1,8 @@
 #ifndef _TOOLS_ASM_BUG_H
 #define _TOOLS_ASM_BUG_H
 
+#include <linux/compiler.h>
+
 #define __WARN_printf(arg...)	do { fprintf(stderr, arg); } while (0)
 
 #define WARN(condition, format...) ({		\
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/8] tools lib traceevent: Add state member to struct trace_seq
  2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
                   ` (3 preceding siblings ...)
  2014-01-09 14:00 ` [PATCH 4/8] tools include: Include <linux/compiler.h> from asm/bug.h Namhyung Kim
@ 2014-01-09 14:00 ` Namhyung Kim
  2014-01-09 14:00 ` [PATCH 6/8] tools lib traceevent: Check return value of realloc() Namhyung Kim
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Namhyung Kim @ 2014-01-09 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Jiri Olsa, Frederic Weisbecker, Ingo Molnar, LKML, Namhyung Kim

The trace_seq->state is for tracking errors during the use of
trace_seq APIs and getting rid of die() in it.

Acked-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/Makefile      |    2 +-
 tools/lib/traceevent/event-parse.h |    7 ++++++
 tools/lib/traceevent/trace-seq.c   |   46 ++++++++++++++++++++++++++++++++----
 3 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile
index f778d48ac609..56d52a33a3df 100644
--- a/tools/lib/traceevent/Makefile
+++ b/tools/lib/traceevent/Makefile
@@ -136,7 +136,7 @@ export Q VERBOSE
 
 EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
 
-INCLUDES = -I. $(CONFIG_INCLUDES)
+INCLUDES = -I. -I $(srctree)/../../include $(CONFIG_INCLUDES)
 
 # Set compile option CFLAGS if not set elsewhere
 CFLAGS ?= -g -Wall
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index cf5db9013f2c..3c890cb28db7 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -58,6 +58,12 @@ struct pevent_record {
 #endif
 };
 
+enum trace_seq_fail {
+	TRACE_SEQ__GOOD,
+	TRACE_SEQ__BUFFER_POISONED,
+	TRACE_SEQ__MEM_ALLOC_FAILED,
+};
+
 /*
  * Trace sequences are used to allow a function to call several other functions
  * to create a string of data to use (up to a max of PAGE_SIZE).
@@ -68,6 +74,7 @@ struct trace_seq {
 	unsigned int		buffer_size;
 	unsigned int		len;
 	unsigned int		readpos;
+	enum trace_seq_fail	state;
 };
 
 void trace_seq_init(struct trace_seq *s);
diff --git a/tools/lib/traceevent/trace-seq.c b/tools/lib/traceevent/trace-seq.c
index d7f2e68bc5b9..7f24e8989401 100644
--- a/tools/lib/traceevent/trace-seq.c
+++ b/tools/lib/traceevent/trace-seq.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <stdarg.h>
 
+#include <asm/bug.h>
 #include "event-parse.h"
 #include "event-utils.h"
 
@@ -32,8 +33,9 @@
 #define TRACE_SEQ_POISON	((void *)0xdeadbeef)
 #define TRACE_SEQ_CHECK(s)						\
 do {									\
-	if ((s)->buffer == TRACE_SEQ_POISON)			\
-		die("Usage of trace_seq after it was destroyed");	\
+	if (WARN_ONCE((s)->buffer == TRACE_SEQ_POISON,			\
+		      "Usage of trace_seq after it was destroyed"))	\
+		(s)->state = TRACE_SEQ__BUFFER_POISONED;		\
 } while (0)
 
 /**
@@ -46,6 +48,7 @@ void trace_seq_init(struct trace_seq *s)
 	s->readpos = 0;
 	s->buffer_size = TRACE_SEQ_BUF_SIZE;
 	s->buffer = malloc_or_die(s->buffer_size);
+	s->state = TRACE_SEQ__GOOD;
 }
 
 /**
@@ -80,8 +83,9 @@ static void expand_buffer(struct trace_seq *s)
 {
 	s->buffer_size += TRACE_SEQ_BUF_SIZE;
 	s->buffer = realloc(s->buffer, s->buffer_size);
-	if (!s->buffer)
-		die("Can't allocate trace_seq buffer memory");
+	if (WARN_ONCE(!s->buffer,
+		      "Can't allocate trace_seq buffer memory"))
+		s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
 }
 
 /**
@@ -108,6 +112,9 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
 	TRACE_SEQ_CHECK(s);
 
  try_again:
+	if (s->state != TRACE_SEQ__GOOD)
+		return 0;
+
 	len = (s->buffer_size - 1) - s->len;
 
 	va_start(ap, fmt);
@@ -144,6 +151,9 @@ trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
 	TRACE_SEQ_CHECK(s);
 
  try_again:
+	if (s->state != TRACE_SEQ__GOOD)
+		return 0;
+
 	len = (s->buffer_size - 1) - s->len;
 
 	ret = vsnprintf(s->buffer + s->len, len, fmt, args);
@@ -174,11 +184,17 @@ int trace_seq_puts(struct trace_seq *s, const char *str)
 
 	TRACE_SEQ_CHECK(s);
 
+	if (s->state != TRACE_SEQ__GOOD)
+		return 0;
+
 	len = strlen(str);
 
 	while (len > ((s->buffer_size - 1) - s->len))
 		expand_buffer(s);
 
+	if (s->state != TRACE_SEQ__GOOD)
+		return 0;
+
 	memcpy(s->buffer + s->len, str, len);
 	s->len += len;
 
@@ -189,9 +205,15 @@ int trace_seq_putc(struct trace_seq *s, unsigned char c)
 {
 	TRACE_SEQ_CHECK(s);
 
+	if (s->state != TRACE_SEQ__GOOD)
+		return 0;
+
 	while (s->len >= (s->buffer_size - 1))
 		expand_buffer(s);
 
+	if (s->state != TRACE_SEQ__GOOD)
+		return 0;
+
 	s->buffer[s->len++] = c;
 
 	return 1;
@@ -201,6 +223,9 @@ void trace_seq_terminate(struct trace_seq *s)
 {
 	TRACE_SEQ_CHECK(s);
 
+	if (s->state != TRACE_SEQ__GOOD)
+		return;
+
 	/* There's always one character left on the buffer */
 	s->buffer[s->len] = 0;
 }
@@ -208,5 +233,16 @@ void trace_seq_terminate(struct trace_seq *s)
 int trace_seq_do_printf(struct trace_seq *s)
 {
 	TRACE_SEQ_CHECK(s);
-	return printf("%.*s", s->len, s->buffer);
+
+	switch (s->state) {
+	case TRACE_SEQ__GOOD:
+		return printf("%.*s", s->len, s->buffer);
+	case TRACE_SEQ__BUFFER_POISONED:
+		puts("Usage of trace_seq after it was destroyed");
+		break;
+	case TRACE_SEQ__MEM_ALLOC_FAILED:
+		puts("Can't allocate trace_seq buffer memory");
+		break;
+	}
+	return -1;
 }
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 6/8] tools lib traceevent: Check return value of realloc()
  2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
                   ` (4 preceding siblings ...)
  2014-01-09 14:00 ` [PATCH 5/8] tools lib traceevent: Add state member to struct trace_seq Namhyung Kim
@ 2014-01-09 14:00 ` Namhyung Kim
  2014-01-09 14:00 ` [PATCH 7/8] tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init() Namhyung Kim
  2014-01-09 14:00 ` [PATCH 8/8] tools lib traceevent: Get rid of die() finally!! Namhyung Kim
  7 siblings, 0 replies; 13+ messages in thread
From: Namhyung Kim @ 2014-01-09 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Jiri Olsa, Frederic Weisbecker, Ingo Molnar, LKML, Namhyung Kim

If realloc() fails, it'll leak the buffer.  Also increate buffer size
only if the allocation succeeded.

Acked-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/trace-seq.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/lib/traceevent/trace-seq.c b/tools/lib/traceevent/trace-seq.c
index 7f24e8989401..941d35d2cf87 100644
--- a/tools/lib/traceevent/trace-seq.c
+++ b/tools/lib/traceevent/trace-seq.c
@@ -81,11 +81,16 @@ void trace_seq_destroy(struct trace_seq *s)
 
 static void expand_buffer(struct trace_seq *s)
 {
-	s->buffer_size += TRACE_SEQ_BUF_SIZE;
-	s->buffer = realloc(s->buffer, s->buffer_size);
-	if (WARN_ONCE(!s->buffer,
-		      "Can't allocate trace_seq buffer memory"))
+	char *buf;
+
+	buf = realloc(s->buffer, s->buffer_size + TRACE_SEQ_BUF_SIZE);
+	if (WARN_ONCE(!buf, "Can't allocate trace_seq buffer memory")) {
 		s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
+		return;
+	}
+
+	s->buffer = buf;
+	s->buffer_size += TRACE_SEQ_BUF_SIZE;
 }
 
 /**
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 7/8] tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init()
  2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
                   ` (5 preceding siblings ...)
  2014-01-09 14:00 ` [PATCH 6/8] tools lib traceevent: Check return value of realloc() Namhyung Kim
@ 2014-01-09 14:00 ` Namhyung Kim
  2014-01-09 14:00 ` [PATCH 8/8] tools lib traceevent: Get rid of die() finally!! Namhyung Kim
  7 siblings, 0 replies; 13+ messages in thread
From: Namhyung Kim @ 2014-01-09 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Jiri Olsa, Frederic Weisbecker, Ingo Molnar, LKML, Namhyung Kim

Use plain malloc() and check its return value.

Acked-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/trace-seq.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/lib/traceevent/trace-seq.c b/tools/lib/traceevent/trace-seq.c
index 941d35d2cf87..339a0ffa21d5 100644
--- a/tools/lib/traceevent/trace-seq.c
+++ b/tools/lib/traceevent/trace-seq.c
@@ -47,8 +47,11 @@ void trace_seq_init(struct trace_seq *s)
 	s->len = 0;
 	s->readpos = 0;
 	s->buffer_size = TRACE_SEQ_BUF_SIZE;
-	s->buffer = malloc_or_die(s->buffer_size);
-	s->state = TRACE_SEQ__GOOD;
+	s->buffer = malloc(s->buffer_size);
+	if (s->buffer != NULL)
+		s->state = TRACE_SEQ__GOOD;
+	else
+		s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
 }
 
 /**
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 8/8] tools lib traceevent: Get rid of die() finally!!
  2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
                   ` (6 preceding siblings ...)
  2014-01-09 14:00 ` [PATCH 7/8] tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init() Namhyung Kim
@ 2014-01-09 14:00 ` Namhyung Kim
  7 siblings, 0 replies; 13+ messages in thread
From: Namhyung Kim @ 2014-01-09 14:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Steven Rostedt
  Cc: Jiri Olsa, Frederic Weisbecker, Ingo Molnar, LKML, Namhyung Kim

Now all of its users were gone. :)

Acked-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/lib/traceevent/event-utils.h |    4 ----
 tools/lib/traceevent/parse-utils.c |   44 ------------------------------------
 2 files changed, 48 deletions(-)

diff --git a/tools/lib/traceevent/event-utils.h b/tools/lib/traceevent/event-utils.h
index e76c9acb92cd..d1dc2170e402 100644
--- a/tools/lib/traceevent/event-utils.h
+++ b/tools/lib/traceevent/event-utils.h
@@ -23,18 +23,14 @@
 #include <ctype.h>
 
 /* Can be overridden */
-void die(const char *fmt, ...);
-void *malloc_or_die(unsigned int size);
 void warning(const char *fmt, ...);
 void pr_stat(const char *fmt, ...);
 void vpr_stat(const char *fmt, va_list ap);
 
 /* Always available */
-void __die(const char *fmt, ...);
 void __warning(const char *fmt, ...);
 void __pr_stat(const char *fmt, ...);
 
-void __vdie(const char *fmt, ...);
 void __vwarning(const char *fmt, ...);
 void __vpr_stat(const char *fmt, ...);
 
diff --git a/tools/lib/traceevent/parse-utils.c b/tools/lib/traceevent/parse-utils.c
index bba701cf10e6..eda07fa31dca 100644
--- a/tools/lib/traceevent/parse-utils.c
+++ b/tools/lib/traceevent/parse-utils.c
@@ -25,40 +25,6 @@
 
 #define __weak __attribute__((weak))
 
-void __vdie(const char *fmt, va_list ap)
-{
-	int ret = errno;
-
-	if (errno)
-		perror("trace-cmd");
-	else
-		ret = -1;
-
-	fprintf(stderr, "  ");
-	vfprintf(stderr, fmt, ap);
-
-	fprintf(stderr, "\n");
-	exit(ret);
-}
-
-void __die(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	__vdie(fmt, ap);
-	va_end(ap);
-}
-
-void __weak die(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	__vdie(fmt, ap);
-	va_end(ap);
-}
-
 void __vwarning(const char *fmt, va_list ap)
 {
 	if (errno)
@@ -117,13 +83,3 @@ void __weak pr_stat(const char *fmt, ...)
 	__vpr_stat(fmt, ap);
 	va_end(ap);
 }
-
-void __weak *malloc_or_die(unsigned int size)
-{
-	void *data;
-
-	data = malloc(size);
-	if (!data)
-		die("malloc");
-	return data;
-}
-- 
1.7.9.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:perf/core] tools include: Move perf's linux/ compiler.h to a generic place
  2014-01-09 14:00 ` [PATCH 1/8] tools include: Move perf's linux/compiler.h to a generic place Namhyung Kim
@ 2014-01-14 16:40   ` tip-bot for Namhyung Kim
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Namhyung Kim @ 2014-01-14 16:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, namhyung.kim, namhyung, jolsa,
	fweisbec, rostedt, tglx, bp

Commit-ID:  8a625c1f61f3dd5e4ea4b5b642650416aa101ce5
Gitweb:     http://git.kernel.org/tip/8a625c1f61f3dd5e4ea4b5b642650416aa101ce5
Author:     Namhyung Kim <namhyung@kernel.org>
AuthorDate: Thu, 9 Jan 2014 23:00:52 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 13 Jan 2014 10:06:25 -0300

tools include: Move perf's linux/compiler.h to a generic place

So that it can be shared with others like libtraceevent.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Borislav Petkov <bp@suse.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1389276059-8829-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/{perf/util => }/include/linux/compiler.h | 6 +++---
 tools/perf/Makefile.perf                       | 2 +-
 tools/perf/config/Makefile                     | 1 +
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/include/linux/compiler.h b/tools/include/linux/compiler.h
similarity index 80%
rename from tools/perf/util/include/linux/compiler.h
rename to tools/include/linux/compiler.h
index b003ad7..0135ccf 100644
--- a/tools/perf/util/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -1,5 +1,5 @@
-#ifndef _PERF_LINUX_COMPILER_H_
-#define _PERF_LINUX_COMPILER_H_
+#ifndef _TOOLS_LINUX_COMPILER_H_
+#define _TOOLS_LINUX_COMPILER_H_
 
 #ifndef __always_inline
 # define __always_inline	inline __attribute__((always_inline))
@@ -27,4 +27,4 @@
 # define __weak			__attribute__((weak))
 #endif
 
-#endif
+#endif /* _TOOLS_LINUX_COMPILER_H */
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 3638b0b..6be0676 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -211,7 +211,7 @@ LIB_H += ../../include/linux/hash.h
 LIB_H += ../../include/linux/stringify.h
 LIB_H += util/include/linux/bitmap.h
 LIB_H += util/include/linux/bitops.h
-LIB_H += util/include/linux/compiler.h
+LIB_H += ../include/linux/compiler.h
 LIB_H += util/include/linux/const.h
 LIB_H += util/include/linux/ctype.h
 LIB_H += util/include/linux/kernel.h
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 5d15b43..01dd43d 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -232,6 +232,7 @@ endif
 
 CFLAGS += -I$(src-perf)/util/include
 CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
+CFLAGS += -I$(srctree)/tools/include/
 CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
 CFLAGS += -I$(srctree)/arch/$(ARCH)/include
 CFLAGS += -I$(srctree)/include/uapi

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:perf/core] tools include: Define likely/unlikely in linux/ compiler.h
  2014-01-09 14:00 ` [PATCH 2/8] tools include: Define likely/unlikely in linux/compiler.h Namhyung Kim
@ 2014-01-14 16:40   ` tip-bot for Namhyung Kim
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Namhyung Kim @ 2014-01-14 16:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, namhyung.kim, namhyung, jolsa,
	fweisbec, rostedt, tglx

Commit-ID:  835d44b9041e578e3e553a57dfffc7003605c93b
Gitweb:     http://git.kernel.org/tip/835d44b9041e578e3e553a57dfffc7003605c93b
Author:     Namhyung Kim <namhyung@kernel.org>
AuthorDate: Thu, 9 Jan 2014 23:00:53 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 13 Jan 2014 10:06:26 -0300

tools include: Define likely/unlikely in linux/compiler.h

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1389276059-8829-3-git-send-email-namhyung@kernel.org
[ Added the new header to tools/perf/MANIFEST ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/include/linux/compiler.h | 8 ++++++++
 tools/perf/MANIFEST            | 1 +
 2 files changed, 9 insertions(+)

diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index 0135ccf..fbc6665 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -27,4 +27,12 @@
 # define __weak			__attribute__((weak))
 #endif
 
+#ifndef likely
+# define likely(x)		__builtin_expect(!!(x), 1)
+#endif
+
+#ifndef unlikely
+# define unlikely(x)		__builtin_expect(!!(x), 0)
+#endif
+
 #endif /* _TOOLS_LINUX_COMPILER_H */
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 3170a7f..285f28f 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -4,6 +4,7 @@ tools/lib/traceevent
 tools/lib/lk
 tools/lib/symbol/kallsyms.c
 tools/lib/symbol/kallsyms.h
+tools/include/linux/compiler.h
 include/linux/const.h
 include/linux/perf_event.h
 include/linux/rbtree.h

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:perf/core] tools include: Move perf' s bug.h to a generic place
  2014-01-09 14:00 ` [PATCH 3/8] tools include: Move perf's bug.h to a generic place Namhyung Kim
@ 2014-01-14 16:40   ` tip-bot for Namhyung Kim
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Namhyung Kim @ 2014-01-14 16:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, namhyung.kim, namhyung, jolsa,
	fweisbec, rostedt, tglx

Commit-ID:  02dfc8d775f0709ab494d4b2cce12c8429ff7530
Gitweb:     http://git.kernel.org/tip/02dfc8d775f0709ab494d4b2cce12c8429ff7530
Author:     Namhyung Kim <namhyung@kernel.org>
AuthorDate: Thu, 9 Jan 2014 23:00:54 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 13 Jan 2014 10:06:26 -0300

tools include: Move perf's bug.h to a generic place

So that it can be shared with others like libtraceevent.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1389276059-8829-4-git-send-email-namhyung@kernel.org
[ Added the new header to tools/perf/MANIFEST ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/{perf/util => }/include/asm/bug.h | 7 ++++---
 tools/perf/MANIFEST                     | 1 +
 tools/perf/Makefile.perf                | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/include/asm/bug.h b/tools/include/asm/bug.h
similarity index 85%
rename from tools/perf/util/include/asm/bug.h
rename to tools/include/asm/bug.h
index 7fcc681..eca78df 100644
--- a/tools/perf/util/include/asm/bug.h
+++ b/tools/include/asm/bug.h
@@ -1,5 +1,5 @@
-#ifndef _PERF_ASM_GENERIC_BUG_H
-#define _PERF_ASM_GENERIC_BUG_H
+#ifndef _TOOLS_ASM_BUG_H
+#define _TOOLS_ASM_BUG_H
 
 #define __WARN_printf(arg...)	do { fprintf(stderr, arg); } while (0)
 
@@ -19,4 +19,5 @@
 			__warned = 1;		\
 	unlikely(__ret_warn_once);		\
 })
-#endif
+
+#endif /* _TOOLS_ASM_BUG_H */
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 285f28f..4e53535 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -4,6 +4,7 @@ tools/lib/traceevent
 tools/lib/lk
 tools/lib/symbol/kallsyms.c
 tools/lib/symbol/kallsyms.h
+tools/include/asm/bug.h
 tools/include/linux/compiler.h
 include/linux/const.h
 include/linux/perf_event.h
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 6be0676..87d7726 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -226,7 +226,7 @@ LIB_H += util/include/linux/string.h
 LIB_H += util/include/linux/types.h
 LIB_H += util/include/linux/linkage.h
 LIB_H += util/include/asm/asm-offsets.h
-LIB_H += util/include/asm/bug.h
+LIB_H += ../include/asm/bug.h
 LIB_H += util/include/asm/byteorder.h
 LIB_H += util/include/asm/hweight.h
 LIB_H += util/include/asm/swab.h

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [tip:perf/core] tools include: Include <linux/compiler.h> from asm/bug.h
  2014-01-09 14:00 ` [PATCH 4/8] tools include: Include <linux/compiler.h> from asm/bug.h Namhyung Kim
@ 2014-01-14 16:41   ` tip-bot for Namhyung Kim
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Namhyung Kim @ 2014-01-14 16:41 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, namhyung.kim, namhyung, jolsa,
	fweisbec, rostedt, tglx

Commit-ID:  741a0c59032faeddac80a6237f3d7846231a3740
Gitweb:     http://git.kernel.org/tip/741a0c59032faeddac80a6237f3d7846231a3740
Author:     Namhyung Kim <namhyung@kernel.org>
AuthorDate: Thu, 9 Jan 2014 23:00:55 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 13 Jan 2014 10:14:13 -0300

tools include: Include <linux/compiler.h> from asm/bug.h

Since it uses unlikely() macro inside WARN()

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1389276059-8829-5-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/include/asm/bug.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/include/asm/bug.h b/tools/include/asm/bug.h
index eca78df..9e5f484 100644
--- a/tools/include/asm/bug.h
+++ b/tools/include/asm/bug.h
@@ -1,6 +1,8 @@
 #ifndef _TOOLS_ASM_BUG_H
 #define _TOOLS_ASM_BUG_H
 
+#include <linux/compiler.h>
+
 #define __WARN_printf(arg...)	do { fprintf(stderr, arg); } while (0)
 
 #define WARN(condition, format...) ({		\

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-01-14 16:41 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-09 14:00 [PATCHSET 0/8] tools lib traceevent: Get rid of *die finally!! (v3) Namhyung Kim
2014-01-09 14:00 ` [PATCH 1/8] tools include: Move perf's linux/compiler.h to a generic place Namhyung Kim
2014-01-14 16:40   ` [tip:perf/core] tools include: Move perf's linux/ compiler.h " tip-bot for Namhyung Kim
2014-01-09 14:00 ` [PATCH 2/8] tools include: Define likely/unlikely in linux/compiler.h Namhyung Kim
2014-01-14 16:40   ` [tip:perf/core] tools include: Define likely/unlikely in linux/ compiler.h tip-bot for Namhyung Kim
2014-01-09 14:00 ` [PATCH 3/8] tools include: Move perf's bug.h to a generic place Namhyung Kim
2014-01-14 16:40   ` [tip:perf/core] tools include: Move perf' s " tip-bot for Namhyung Kim
2014-01-09 14:00 ` [PATCH 4/8] tools include: Include <linux/compiler.h> from asm/bug.h Namhyung Kim
2014-01-14 16:41   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-01-09 14:00 ` [PATCH 5/8] tools lib traceevent: Add state member to struct trace_seq Namhyung Kim
2014-01-09 14:00 ` [PATCH 6/8] tools lib traceevent: Check return value of realloc() Namhyung Kim
2014-01-09 14:00 ` [PATCH 7/8] tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init() Namhyung Kim
2014-01-09 14:00 ` [PATCH 8/8] tools lib traceevent: Get rid of die() finally!! Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox