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

seq_file: Rename seq_overflow() to seq_has_overflowed() and make public

The return values of seq_printf/puts/putc are frequently misused.

Start down a path to remove all the return value uses of these
functions.

Move the seq_overflow() to a global inlined function called
seq_has_overflowed() that can be used by the users of seq_file() calls.

Update the documentation to not show return types for seq_printf
et al. Add a description of seq_has_overflowed().

Link: http://lkml.kernel.org/p/848ac7e3d1c31cddf638a8526fa3c59fa6fdeb8a.1412031505.git.joe@perches.com

Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Joe Perches <joe@perches.com>
[ Reworked the original patch from Joe ]
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

authored by

Joe Perches and committed by
Steven Rostedt
1f33c41c f114040e

+30 -22
+13 -9
Documentation/filesystems/seq_file.txt
··· 180 180 been defined which make this task easy. 181 181 182 182 Most code will simply use seq_printf(), which works pretty much like 183 - printk(), but which requires the seq_file pointer as an argument. It is 184 - common to ignore the return value from seq_printf(), but a function 185 - producing complicated output may want to check that value and quit if 186 - something non-zero is returned; an error return means that the seq_file 187 - buffer has been filled and further output will be discarded. 183 + printk(), but which requires the seq_file pointer as an argument. 188 184 189 185 For straight character output, the following functions may be used: 190 186 191 - int seq_putc(struct seq_file *m, char c); 192 - int seq_puts(struct seq_file *m, const char *s); 193 - int seq_escape(struct seq_file *m, const char *s, const char *esc); 187 + seq_putc(struct seq_file *m, char c); 188 + seq_puts(struct seq_file *m, const char *s); 189 + seq_escape(struct seq_file *m, const char *s, const char *esc); 194 190 195 191 The first two output a single character and a string, just like one would 196 192 expect. seq_escape() is like seq_puts(), except that any character in s 197 193 which is in the string esc will be represented in octal form in the output. 198 194 199 - There is also a pair of functions for printing filenames: 195 + There are also a pair of functions for printing filenames: 200 196 201 197 int seq_path(struct seq_file *m, struct path *path, char *esc); 202 198 int seq_path_root(struct seq_file *m, struct path *path, ··· 204 208 root is desired, it can be used with seq_path_root(). Note that, if it 205 209 turns out that path cannot be reached from root, the value of root will be 206 210 changed in seq_file_root() to a root which *does* work. 211 + 212 + A function producing complicated output may want to check 213 + bool seq_has_overflowed(struct seq_file *m); 214 + and avoid further seq_<output> calls if true is returned. 215 + 216 + A true return from seq_has_overflowed means that the seq_file buffer will 217 + be discarded and the seq_show function will attempt to allocate a larger 218 + buffer and retry printing. 207 219 208 220 209 221 Making it all work
+2 -13
fs/seq_file.c
··· 16 16 #include <asm/uaccess.h> 17 17 #include <asm/page.h> 18 18 19 - 20 - /* 21 - * seq_files have a buffer which can may overflow. When this happens a larger 22 - * buffer is reallocated and all the data will be printed again. 23 - * The overflow state is true when m->count == m->size. 24 - */ 25 - static bool seq_overflow(struct seq_file *m) 26 - { 27 - return m->count == m->size; 28 - } 29 - 30 19 static void seq_set_overflow(struct seq_file *m) 31 20 { 32 21 m->count = m->size; ··· 113 124 error = 0; 114 125 m->count = 0; 115 126 } 116 - if (seq_overflow(m)) 127 + if (seq_has_overflowed(m)) 117 128 goto Eoverflow; 118 129 if (pos + m->count > offset) { 119 130 m->from = offset - pos; ··· 256 267 break; 257 268 } 258 269 err = m->op->show(m, p); 259 - if (seq_overflow(m) || err) { 270 + if (seq_has_overflowed(m) || err) { 260 271 m->count = offs; 261 272 if (likely(err <= 0)) 262 273 break;
+15
include/linux/seq_file.h
··· 43 43 #define SEQ_SKIP 1 44 44 45 45 /** 46 + * seq_has_overflowed - check if the buffer has overflowed 47 + * @m: the seq_file handle 48 + * 49 + * seq_files have a buffer which may overflow. When this happens a larger 50 + * buffer is reallocated and all the data will be printed again. 51 + * The overflow state is true when m->count == m->size. 52 + * 53 + * Returns true if the buffer received more than it can hold. 54 + */ 55 + static inline bool seq_has_overflowed(struct seq_file *m) 56 + { 57 + return m->count == m->size; 58 + } 59 + 60 + /** 46 61 * seq_get_buf - get buffer to write arbitrary data to 47 62 * @m: the seq_file handle 48 63 * @bufp: the beginning of the buffer is stored here