mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang Long <long.wanglong@huawei.com>
To: <rostedt@goodmis.org>, <jkosina@suse.cz>, <pmladek@suse.cz>,
	<gregkh@linuxfoundation.org>
Cc: <stable@vger.kernel.org>, <wanglong@laoqinren.net>,
	<peifeiyue@huawei.com>, <linux-kernel@vger.kernel.org>,
	<paulmck@linux.vnet.ibm.com>, <dzickus@redhat.com>,
	<x86@kernel.org>, <long.wanglong@huawei.com>,
	<morgan.wang@huawei.com>, <sasha.levin@oracle.com>
Subject: [PATCH v2 02/17] tracing: Convert seq_buf_path() to be like seq_path()
Date: Tue, 19 May 2015 09:08:47 +0000	[thread overview]
Message-ID: <1432026542-123571-3-git-send-email-long.wanglong@huawei.com> (raw)
In-Reply-To: <1432026542-123571-1-git-send-email-long.wanglong@huawei.com>

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

commit dd23180aacf4b27d48f40b27249f1e58c8df03be upstream.

Rewrite seq_buf_path() like it is done in seq_path() and allow
it to accept any escape character instead of just "\n".

Making seq_buf_path() like seq_path() will help prevent problems
when converting seq_file to use the seq_buf logic.

Link: http://lkml.kernel.org/r/20141104160222.048795666@goodmis.org
Link: http://lkml.kernel.org/r/20141114011412.338523371@goodmis.org

Tested-by: Jiri Kosina <jkosina@suse.cz>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Reviewed-by: Petr Mladek <pmladek@suse.cz>
[wanglong: backport to 3.10 stable
- only backport seq_buf related
]
Signed-off-by: Wang Long <long.wanglong@huawei.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 include/linux/seq_buf.h |  2 +-
 kernel/trace/seq_buf.c  | 28 ++++++++++++++++------------
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
index 4f7a96a..3877068 100644
--- a/include/linux/seq_buf.h
+++ b/include/linux/seq_buf.h
@@ -73,7 +73,7 @@ extern int seq_buf_putc(struct seq_buf *s, unsigned char c);
 extern int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len);
 extern int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
 			      unsigned int len);
-extern int seq_buf_path(struct seq_buf *s, const struct path *path);
+extern int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc);
 
 extern int seq_buf_bitmask(struct seq_buf *s, const unsigned long *maskp,
 			   int nmaskbits);
diff --git a/kernel/trace/seq_buf.c b/kernel/trace/seq_buf.c
index e9a7861..7dac34d 100644
--- a/kernel/trace/seq_buf.c
+++ b/kernel/trace/seq_buf.c
@@ -272,28 +272,32 @@ int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
  * seq_buf_path - copy a path into the sequence buffer
  * @s: seq_buf descriptor
  * @path: path to write into the sequence buffer.
+ * @esc: set of characters to escape in the output
  *
  * Write a path name into the sequence buffer.
  *
- * Returns zero on success, -1 on overflow
+ * Returns the number of written bytes on success, -1 on overflow
  */
-int seq_buf_path(struct seq_buf *s, const struct path *path)
+int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc)
 {
-	unsigned int len = seq_buf_buffer_left(s);
-	unsigned char *p;
+	char *buf = s->buffer + s->len;
+	size_t size = seq_buf_buffer_left(s);
+	int res = -1;
 
 	WARN_ON(s->size == 0);
 
-	p = d_path(path, s->buffer + s->len, len);
-	if (!IS_ERR(p)) {
-		p = mangle_path(s->buffer + s->len, p, "\n");
-		if (p) {
-			s->len = p - s->buffer;
-			return 0;
+	if (size) {
+		char *p = d_path(path, buf, size);
+		if (!IS_ERR(p)) {
+			char *end = mangle_path(buf, p, esc);
+			if (end)
+				res = end - buf;
 		}
 	}
-	seq_buf_set_overflow(s);
-	return -1;
+	if (res > 0)
+		s->len += res;
+
+	return res;
 }
 
 /**
-- 
1.8.3.4


  parent reply	other threads:[~2015-05-19  9:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-19  9:08 [PATCH v2 00/17] [request for stable 3.10 inclusion] x86/nmi: Print all cpu stacks from NMI safely Wang Long
2015-05-19  9:08 ` [PATCH v2 01/17] tracing: Create seq_buf layer in trace_seq Wang Long
2015-05-19  9:08 ` Wang Long [this message]
2015-05-19  9:08 ` [PATCH v2 03/17] tracing: Convert seq_buf fields to be like seq_file fields Wang Long
2015-05-19  9:08 ` [PATCH v2 04/17] tracing: Add a seq_buf_clear() helper and clear len and readpos in init Wang Long
2015-05-19  9:08 ` [PATCH v2 05/17] seq_buf: Create seq_buf_used() to find out how much was written Wang Long
2015-05-19  9:08 ` [PATCH v2 06/17] tracing: Use trace_seq_used() and seq_buf_used() instead of len Wang Long
2015-05-19  9:08 ` [PATCH v2 07/17] seq_buf: Add seq_buf_can_fit() helper function Wang Long
2015-05-19  9:08 ` [PATCH v2 08/17] tracing: Have seq_buf use full buffer Wang Long
2015-05-19  9:08 ` [PATCH v2 09/17] tracing: Add seq_buf_get_buf() and seq_buf_commit() helper functions Wang Long
2015-05-19  9:08 ` [PATCH v2 10/17] seq-buf: Make seq_buf_bprintf() conditional on CONFIG_BINARY_PRINTF Wang Long
2015-05-19  9:08 ` [PATCH v2 11/17] seq_buf: Move the seq_buf code to lib/ Wang Long
2015-05-19  9:08 ` [PATCH v2 12/17] seq_buf: Fix seq_buf_vprintf() truncation Wang Long
2015-05-19  9:08 ` [PATCH v2 13/17] seq_buf: Fix seq_buf_bprintf() truncation Wang Long
2015-05-19  9:08 ` [PATCH v2 14/17] printk: Add per_cpu printk func to allow printk to be diverted Wang Long
2015-05-19  9:09 ` [PATCH v2 15/17] printk/percpu: Define printk_func when printk is not defined Wang Long
2015-05-19  9:09 ` [PATCH v2 16/17] x86/nmi: Perform a safe NMI stack trace on all CPUs Wang Long
2015-05-19  9:09 ` [PATCH v2 17/17] x86/nmi: Fix use of unallocated cpumask_var_t Wang Long
2015-05-19 12:57 ` [PATCH v2 00/17] [request for stable 3.10 inclusion] x86/nmi: Print all cpu stacks from NMI safely Petr Mladek
2015-05-20 13:22   ` Petr Mladek
2015-05-21  1:38     ` long.wanglong
2015-06-29 23:56       ` Greg KH

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=1432026542-123571-3-git-send-email-long.wanglong@huawei.com \
    --to=long.wanglong@huawei.com \
    --cc=dzickus@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=morgan.wang@huawei.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peifeiyue@huawei.com \
    --cc=pmladek@suse.cz \
    --cc=rostedt@goodmis.org \
    --cc=sasha.levin@oracle.com \
    --cc=stable@vger.kernel.org \
    --cc=wanglong@laoqinren.net \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®