summaryrefslogtreecommitdiff
path: root/kernel/trace/trace_seq.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/trace/trace_seq.c')
-rw-r--r--kernel/trace/trace_seq.c111
1 files changed, 57 insertions, 54 deletions
diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
index 9c90b3a7dce2..48c08f29c342 100644
--- a/kernel/trace/trace_seq.c
+++ b/kernel/trace/trace_seq.c
@@ -25,11 +25,9 @@
*/
#include <linux/uaccess.h>
#include <linux/seq_file.h>
+#include <linux/string.h>
#include <linux/trace_seq.h>
-/* How much buffer is left on the trace_seq? */
-#define TRACE_SEQ_BUF_LEFT(s) seq_buf_buffer_left(&(s)->seq)
-
/*
* trace_seq should work with being initialized with 0s.
*/
@@ -54,7 +52,7 @@ int trace_print_seq(struct seq_file *m, struct trace_seq *s)
__trace_seq_init(s);
- ret = seq_buf_print_seq(m, &s->seq);
+ ret = seq_write(m, s->seq.buf, printbuf_written(&s->seq));
/*
* Only reset this buffer if we successfully wrote to the
@@ -80,7 +78,7 @@ int trace_print_seq(struct seq_file *m, struct trace_seq *s)
*/
void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
{
- unsigned int save_len = s->seq.len;
+ unsigned int save_pos = s->seq.pos;
va_list ap;
if (s->full)
@@ -89,12 +87,12 @@ void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
__trace_seq_init(s);
va_start(ap, fmt);
- seq_buf_vprintf(&s->seq, fmt, ap);
+ prt_vprintf(&s->seq, fmt, ap);
va_end(ap);
/* If we can't write it all, don't bother writing anything */
- if (unlikely(seq_buf_has_overflowed(&s->seq))) {
- s->seq.len = save_len;
+ if (unlikely(printbuf_overflowed(&s->seq))) {
+ s->seq.pos = save_pos;
s->full = 1;
}
}
@@ -111,17 +109,17 @@ EXPORT_SYMBOL_GPL(trace_seq_printf);
void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
int nmaskbits)
{
- unsigned int save_len = s->seq.len;
+ unsigned int save_pos = s->seq.pos;
if (s->full)
return;
__trace_seq_init(s);
- seq_buf_printf(&s->seq, "%*pb", nmaskbits, maskp);
+ prt_printf(&s->seq, "%*pb", nmaskbits, maskp);
- if (unlikely(seq_buf_has_overflowed(&s->seq))) {
- s->seq.len = save_len;
+ if (unlikely(printbuf_overflowed(&s->seq))) {
+ s->seq.pos = save_pos;
s->full = 1;
}
}
@@ -140,18 +138,18 @@ EXPORT_SYMBOL_GPL(trace_seq_bitmask);
*/
void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
{
- unsigned int save_len = s->seq.len;
+ unsigned int save_pos = s->seq.pos;
if (s->full)
return;
__trace_seq_init(s);
- seq_buf_vprintf(&s->seq, fmt, args);
+ prt_vprintf(&s->seq, fmt, args);
/* If we can't write it all, don't bother writing anything */
- if (unlikely(seq_buf_has_overflowed(&s->seq))) {
- s->seq.len = save_len;
+ if (unlikely(printbuf_overflowed(&s->seq))) {
+ s->seq.pos = save_pos;
s->full = 1;
}
}
@@ -174,18 +172,18 @@ EXPORT_SYMBOL_GPL(trace_seq_vprintf);
*/
void trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
{
- unsigned int save_len = s->seq.len;
+ unsigned int save_pos = s->seq.pos;
if (s->full)
return;
__trace_seq_init(s);
- seq_buf_bprintf(&s->seq, fmt, binary);
+ prt_bstrprintf(&s->seq, fmt, binary);
/* If we can't write it all, don't bother writing anything */
- if (unlikely(seq_buf_has_overflowed(&s->seq))) {
- s->seq.len = save_len;
+ if (unlikely(!printbuf_overflowed(&s->seq))) {
+ s->seq.pos = save_pos;
s->full = 1;
return;
}
@@ -211,12 +209,12 @@ void trace_seq_puts(struct trace_seq *s, const char *str)
__trace_seq_init(s);
- if (len > TRACE_SEQ_BUF_LEFT(s)) {
+ if (len > printbuf_remaining(&s->seq)) {
s->full = 1;
return;
}
- seq_buf_putmem(&s->seq, str, len);
+ prt_bytes(&s->seq, str, len);
}
EXPORT_SYMBOL_GPL(trace_seq_puts);
@@ -237,12 +235,12 @@ void trace_seq_putc(struct trace_seq *s, unsigned char c)
__trace_seq_init(s);
- if (TRACE_SEQ_BUF_LEFT(s) < 1) {
+ if (!printbuf_remaining(&s->seq)) {
s->full = 1;
return;
}
- seq_buf_putc(&s->seq, c);
+ prt_char(&s->seq, c);
}
EXPORT_SYMBOL_GPL(trace_seq_putc);
@@ -263,12 +261,12 @@ void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
__trace_seq_init(s);
- if (len > TRACE_SEQ_BUF_LEFT(s)) {
+ if (len > printbuf_remaining(&s->seq)) {
s->full = 1;
return;
}
- seq_buf_putmem(&s->seq, mem, len);
+ prt_bytes(&s->seq, mem, len);
}
EXPORT_SYMBOL_GPL(trace_seq_putmem);
@@ -285,24 +283,17 @@ EXPORT_SYMBOL_GPL(trace_seq_putmem);
void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
unsigned int len)
{
- unsigned int save_len = s->seq.len;
+ unsigned int save_pos = s->seq.pos;
if (s->full)
return;
__trace_seq_init(s);
- /* Each byte is represented by two chars */
- if (len * 2 > TRACE_SEQ_BUF_LEFT(s)) {
- s->full = 1;
- return;
- }
+ prt_hex_bytes(&s->seq, mem, len, 8, ' ');
- /* The added spaces can still cause an overflow */
- seq_buf_putmem_hex(&s->seq, mem, len);
-
- if (unlikely(seq_buf_has_overflowed(&s->seq))) {
- s->seq.len = save_len;
+ if (unlikely(printbuf_overflowed(&s->seq))) {
+ s->seq.pos = save_pos;
s->full = 1;
return;
}
@@ -323,22 +314,22 @@ EXPORT_SYMBOL_GPL(trace_seq_putmem_hex);
*/
int trace_seq_path(struct trace_seq *s, const struct path *path)
{
- unsigned int save_len = s->seq.len;
+ unsigned int save_pos = s->seq.pos;
if (s->full)
return 0;
__trace_seq_init(s);
- if (TRACE_SEQ_BUF_LEFT(s) < 1) {
+ if (printbuf_remaining(&s->seq) < 1) {
s->full = 1;
return 0;
}
- seq_buf_path(&s->seq, path, "\n");
+ prt_path(&s->seq, path, "\n");
- if (unlikely(seq_buf_has_overflowed(&s->seq))) {
- s->seq.len = save_len;
+ if (unlikely(printbuf_overflowed(&s->seq))) {
+ s->seq.pos = save_pos;
s->full = 1;
return 0;
}
@@ -369,8 +360,25 @@ EXPORT_SYMBOL_GPL(trace_seq_path);
*/
int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, int cnt)
{
+ int ret, len;
+
__trace_seq_init(s);
- return seq_buf_to_user(&s->seq, ubuf, cnt);
+
+ len = printbuf_written(&s->seq);
+ if (len <= s->readpos)
+ return -EBUSY;
+
+ len -= s->readpos;
+ if (cnt > len)
+ cnt = len;
+ ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
+ if (ret == cnt)
+ return -EFAULT;
+
+ cnt -= ret;
+
+ s->readpos += cnt;
+ return cnt;
}
EXPORT_SYMBOL_GPL(trace_seq_to_user);
@@ -378,24 +386,19 @@ int trace_seq_hex_dump(struct trace_seq *s, const char *prefix_str,
int prefix_type, int rowsize, int groupsize,
const void *buf, size_t len, bool ascii)
{
- unsigned int save_len = s->seq.len;
+ unsigned int save_pos = s->seq.pos;
if (s->full)
return 0;
__trace_seq_init(s);
- if (TRACE_SEQ_BUF_LEFT(s) < 1) {
- s->full = 1;
- return 0;
- }
-
- seq_buf_hex_dump(&(s->seq), prefix_str,
- prefix_type, rowsize, groupsize,
- buf, len, ascii);
+ prt_hex_dump(&s->seq, buf, len,
+ prefix_str, prefix_type,
+ rowsize, groupsize, ascii);
- if (unlikely(seq_buf_has_overflowed(&s->seq))) {
- s->seq.len = save_len;
+ if (unlikely(printbuf_overflowed(&s->seq))) {
+ s->seq.pos = save_pos;
s->full = 1;
return 0;
}