Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

seq_buf: Create seq_buf_used() to find out how much was written

Add a helper function seq_buf_used() that replaces the SEQ_BUF_USED()
private macro to let callers have a method to know how much of the
seq_buf was written to.

Link: http://lkml.kernel.org/r/20141114011412.170377300@goodmis.org
Link: http://lkml.kernel.org/r/20141114011413.321654244@goodmis.org

Reviewed-by: Petr Mladek <pmladek@suse.cz>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

+7 -4
+6
include/linux/seq_buf.h
··· 64 64 return (s->size - 1) - s->len; 65 65 } 66 66 67 + /* How much buffer was written? */ 68 + static inline unsigned int seq_buf_used(struct seq_buf *s) 69 + { 70 + return min(s->len, s->size); 71 + } 72 + 67 73 extern __printf(2, 3) 68 74 int seq_buf_printf(struct seq_buf *s, const char *fmt, ...); 69 75 extern __printf(2, 0)
+1 -4
kernel/trace/seq_buf.c
··· 16 16 #include <linux/seq_file.h> 17 17 #include <linux/seq_buf.h> 18 18 19 - /* How much buffer is written? */ 20 - #define SEQ_BUF_USED(s) min((s)->len, (s)->size - 1) 21 - 22 19 /** 23 20 * seq_buf_print_seq - move the contents of seq_buf into a seq_file 24 21 * @m: the seq_file descriptor that is the destination ··· 25 28 */ 26 29 int seq_buf_print_seq(struct seq_file *m, struct seq_buf *s) 27 30 { 28 - unsigned int len = SEQ_BUF_USED(s); 31 + unsigned int len = seq_buf_used(s); 29 32 30 33 return seq_write(m, s->buffer, len); 31 34 }