aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/trace_seq.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/trace_seq.h')
-rw-r--r--include/linux/trace_seq.h30
1 files changed, 23 insertions, 7 deletions
diff --git a/include/linux/trace_seq.h b/include/linux/trace_seq.h
index db8a73224f1a..cfaf5a1d4bad 100644
--- a/include/linux/trace_seq.h
+++ b/include/linux/trace_seq.h
@@ -1,7 +1,7 @@
1#ifndef _LINUX_TRACE_SEQ_H 1#ifndef _LINUX_TRACE_SEQ_H
2#define _LINUX_TRACE_SEQ_H 2#define _LINUX_TRACE_SEQ_H
3 3
4#include <linux/fs.h> 4#include <linux/seq_buf.h>
5 5
6#include <asm/page.h> 6#include <asm/page.h>
7 7
@@ -12,20 +12,36 @@
12 12
13struct trace_seq { 13struct trace_seq {
14 unsigned char buffer[PAGE_SIZE]; 14 unsigned char buffer[PAGE_SIZE];
15 unsigned int len; 15 struct seq_buf seq;
16 unsigned int readpos;
17 int full; 16 int full;
18}; 17};
19 18
20static inline void 19static inline void
21trace_seq_init(struct trace_seq *s) 20trace_seq_init(struct trace_seq *s)
22{ 21{
23 s->len = 0; 22 seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
24 s->readpos = 0;
25 s->full = 0; 23 s->full = 0;
26} 24}
27 25
28/** 26/**
27 * trace_seq_used - amount of actual data written to buffer
28 * @s: trace sequence descriptor
29 *
30 * Returns the amount of data written to the buffer.
31 *
32 * IMPORTANT!
33 *
34 * Use this instead of @s->seq.len if you need to pass the amount
35 * of data from the buffer to another buffer (userspace, or what not).
36 * The @s->seq.len on overflow is bigger than the buffer size and
37 * using it can cause access to undefined memory.
38 */
39static inline int trace_seq_used(struct trace_seq *s)
40{
41 return seq_buf_used(&s->seq);
42}
43
44/**
29 * trace_seq_buffer_ptr - return pointer to next location in buffer 45 * trace_seq_buffer_ptr - return pointer to next location in buffer
30 * @s: trace sequence descriptor 46 * @s: trace sequence descriptor
31 * 47 *
@@ -37,7 +53,7 @@ trace_seq_init(struct trace_seq *s)
37static inline unsigned char * 53static inline unsigned char *
38trace_seq_buffer_ptr(struct trace_seq *s) 54trace_seq_buffer_ptr(struct trace_seq *s)
39{ 55{
40 return s->buffer + s->len; 56 return s->buffer + seq_buf_used(&s->seq);
41} 57}
42 58
43/** 59/**
@@ -49,7 +65,7 @@ trace_seq_buffer_ptr(struct trace_seq *s)
49 */ 65 */
50static inline bool trace_seq_has_overflowed(struct trace_seq *s) 66static inline bool trace_seq_has_overflowed(struct trace_seq *s)
51{ 67{
52 return s->full || s->len > PAGE_SIZE - 1; 68 return s->full || seq_buf_has_overflowed(&s->seq);
53} 69}
54 70
55/* 71/*