All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung.kim@lge.com>,
	LKML <linux-kernel@vger.kernel.org>, Jiri Olsa <jolsa@redhat.com>
Subject: Re: [PATCH 1/4] tools lib traceevent: Add state member to struct trace_seq
Date: Fri, 03 Jan 2014 16:05:50 +0900	[thread overview]
Message-ID: <87eh4pfstt.fsf@sejong.aot.lge.com> (raw)
In-Reply-To: <1387445666-7821-1-git-send-email-namhyung@kernel.org> (Namhyung Kim's message of "Thu, 19 Dec 2013 18:34:23 +0900")

Ping!

On Thu, 19 Dec 2013 18:34:23 +0900, Namhyung Kim wrote:
> From: Namhyung Kim <namhyung.kim@lge.com>
>
> The trace_seq->state is for tracking errors during the use of
> trace_seq APIs and getting rid of die() in it.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/lib/traceevent/event-parse.h |  7 +++++++
>  tools/lib/traceevent/trace-seq.c   | 41 ++++++++++++++++++++++++++++++++++----
>  2 files changed, 44 insertions(+), 4 deletions(-)
>
> 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..976ad2a146b3 100644
> --- a/tools/lib/traceevent/trace-seq.c
> +++ b/tools/lib/traceevent/trace-seq.c
> @@ -32,8 +32,8 @@
>  #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 ((s)->buffer == TRACE_SEQ_POISON)				\
> +		(s)->state = TRACE_SEQ__BUFFER_POISONED;		\
>  } while (0)
>  
>  /**
> @@ -46,6 +46,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;
>  }
>  
>  /**
> @@ -81,7 +82,7 @@ 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");
> +		s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
>  }
>  
>  /**
> @@ -108,6 +109,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 +148,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 +181,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 +202,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 +220,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 +230,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;
>  }

  parent reply	other threads:[~2014-01-03  7:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-19  9:34 [PATCH 1/4] tools lib traceevent: Add state member to struct trace_seq Namhyung Kim
2013-12-19  9:34 ` [PATCH 2/4] tools lib traceevent: Check return value of realloc() Namhyung Kim
2013-12-19  9:34 ` [PATCH 3/4] tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init() Namhyung Kim
2013-12-19  9:34 ` [PATCH 4/4] tools lib traceevent: Get rid of die() finally!! Namhyung Kim
2014-01-03  7:05 ` Namhyung Kim [this message]
2014-01-03 13:24 ` [PATCH 1/4] tools lib traceevent: Add state member to struct trace_seq Jiri Olsa
2014-01-06  7:44   ` Namhyung Kim
2014-01-06 14:38     ` Jiri Olsa
2014-01-06 14:45       ` Steven Rostedt
2014-01-07  2:48         ` Namhyung Kim

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=87eh4pfstt.fsf@sejong.aot.lge.com \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=rostedt@goodmis.org \
    /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.