Skip to content

Commit 1f33c41

Browse files
JoePerchesrostedt
authored andcommitted
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>
1 parent f114040 commit 1f33c41

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

Documentation/filesystems/seq_file.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,19 @@ output must be passed to the seq_file code. Some utility functions have
180180
been defined which make this task easy.
181181

182182
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.
188184

189185
For straight character output, the following functions may be used:
190186

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);
194190

195191
The first two output a single character and a string, just like one would
196192
expect. seq_escape() is like seq_puts(), except that any character in s
197193
which is in the string esc will be represented in octal form in the output.
198194

199-
There is also a pair of functions for printing filenames:
195+
There are also a pair of functions for printing filenames:
200196

201197
int seq_path(struct seq_file *m, struct path *path, char *esc);
202198
int seq_path_root(struct seq_file *m, struct path *path,
@@ -209,6 +205,14 @@ root is desired, it can be used with seq_path_root(). Note that, if it
209205
turns out that path cannot be reached from root, the value of root will be
210206
changed in seq_file_root() to a root which *does* work.
211207

208+
A function producing complicated output may want to check
209+
bool seq_has_overflowed(struct seq_file *m);
210+
and avoid further seq_<output> calls if true is returned.
211+
212+
A true return from seq_has_overflowed means that the seq_file buffer will
213+
be discarded and the seq_show function will attempt to allocate a larger
214+
buffer and retry printing.
215+
212216

213217
Making it all work
214218

fs/seq_file.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@
1616
#include <asm/uaccess.h>
1717
#include <asm/page.h>
1818

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-
3019
static void seq_set_overflow(struct seq_file *m)
3120
{
3221
m->count = m->size;
@@ -124,7 +113,7 @@ static int traverse(struct seq_file *m, loff_t offset)
124113
error = 0;
125114
m->count = 0;
126115
}
127-
if (seq_overflow(m))
116+
if (seq_has_overflowed(m))
128117
goto Eoverflow;
129118
if (pos + m->count > offset) {
130119
m->from = offset - pos;
@@ -267,7 +256,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
267256
break;
268257
}
269258
err = m->op->show(m, p);
270-
if (seq_overflow(m) || err) {
259+
if (seq_has_overflowed(m) || err) {
271260
m->count = offs;
272261
if (likely(err <= 0))
273262
break;

include/linux/seq_file.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ struct seq_operations {
4242

4343
#define SEQ_SKIP 1
4444

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+
4560
/**
4661
* seq_get_buf - get buffer to write arbitrary data to
4762
* @m: the seq_file handle

0 commit comments

Comments
 (0)