From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Al Viro <viro@zeniv.linux.org.uk>, Joe Perches <joe@perches.com>
Subject: [RFA][PATCH 1/8] seq_file: Rename seq_overflow() to seq_has_overflowed() and make public
Date: Wed, 29 Oct 2014 17:56:03 -0400 [thread overview]
Message-ID: <20141029220107.333126455@goodmis.org> (raw)
In-Reply-To: 20141029215602.535533597@goodmis.org
[-- Attachment #1: 0001-seq_file-Rename-seq_overflow-to-seq_has_overflowed-a.patch --]
[-- Type: text/plain, Size: 5197 bytes --]
From: Joe Perches <joe@perches.com>
[ REQUEST FOR ACKS ]
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>
---
Documentation/filesystems/seq_file.txt | 22 +++++++++++++---------
fs/seq_file.c | 15 ++-------------
include/linux/seq_file.h | 15 +++++++++++++++
3 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/Documentation/filesystems/seq_file.txt b/Documentation/filesystems/seq_file.txt
index 8ea3e90ace07..79b4037a86e6 100644
--- a/Documentation/filesystems/seq_file.txt
+++ b/Documentation/filesystems/seq_file.txt
@@ -180,23 +180,19 @@ output must be passed to the seq_file code. Some utility functions have
been defined which make this task easy.
Most code will simply use seq_printf(), which works pretty much like
-printk(), but which requires the seq_file pointer as an argument. It is
-common to ignore the return value from seq_printf(), but a function
-producing complicated output may want to check that value and quit if
-something non-zero is returned; an error return means that the seq_file
-buffer has been filled and further output will be discarded.
+printk(), but which requires the seq_file pointer as an argument.
For straight character output, the following functions may be used:
- int seq_putc(struct seq_file *m, char c);
- int seq_puts(struct seq_file *m, const char *s);
- int seq_escape(struct seq_file *m, const char *s, const char *esc);
+ seq_putc(struct seq_file *m, char c);
+ seq_puts(struct seq_file *m, const char *s);
+ seq_escape(struct seq_file *m, const char *s, const char *esc);
The first two output a single character and a string, just like one would
expect. seq_escape() is like seq_puts(), except that any character in s
which is in the string esc will be represented in octal form in the output.
-There is also a pair of functions for printing filenames:
+There are also a pair of functions for printing filenames:
int seq_path(struct seq_file *m, struct path *path, char *esc);
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
turns out that path cannot be reached from root, the value of root will be
changed in seq_file_root() to a root which *does* work.
+A function producing complicated output may want to check
+ bool seq_has_overflowed(struct seq_file *m);
+and avoid further seq_<output> calls if true is returned.
+
+A true return from seq_has_overflowed means that the seq_file buffer is full
+and further output will be discarded. The seq_show function will attempt
+to allocate a larger buffer and retry printing.
+
Making it all work
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 3857b720cb1b..353948ba1c5b 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -16,17 +16,6 @@
#include <asm/uaccess.h>
#include <asm/page.h>
-
-/*
- * seq_files have a buffer which can may overflow. When this happens a larger
- * buffer is reallocated and all the data will be printed again.
- * The overflow state is true when m->count == m->size.
- */
-static bool seq_overflow(struct seq_file *m)
-{
- return m->count == m->size;
-}
-
static void seq_set_overflow(struct seq_file *m)
{
m->count = m->size;
@@ -124,7 +113,7 @@ static int traverse(struct seq_file *m, loff_t offset)
error = 0;
m->count = 0;
}
- if (seq_overflow(m))
+ if (seq_has_overflowed(m))
goto Eoverflow;
if (pos + m->count > offset) {
m->from = offset - pos;
@@ -267,7 +256,7 @@ Fill:
break;
}
err = m->op->show(m, p);
- if (seq_overflow(m) || err) {
+ if (seq_has_overflowed(m) || err) {
m->count = offs;
if (likely(err <= 0))
break;
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 52e0097f61f0..07c98e1998c3 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -43,6 +43,21 @@ struct seq_operations {
#define SEQ_SKIP 1
/**
+ * seq_has_overflowed - check if the buffer associated to seq_file has filled
+ * @m: the seq_file handle
+ *
+ * seq_files have a buffer which may overflow. When this happens a larger
+ * buffer is reallocated and all the data will be printed again.
+ * The overflow state is true when m->count == m->size.
+ *
+ * Returns true if the buffer received more than it can hold.
+ */
+static inline bool seq_has_overflowed(struct seq_file *m)
+{
+ return m->count == m->size;
+}
+
+/**
* seq_get_buf - get buffer to write arbitrary data to
* @m: the seq_file handle
* @bufp: the beginning of the buffer is stored here
--
2.1.1
next prev parent reply other threads:[~2014-10-29 22:02 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-29 21:56 [RFA][PATCH 0/8] seq_file: Remove return checks of seq_printf() Steven Rostedt
2014-10-29 21:56 ` Steven Rostedt [this message]
2014-10-29 22:08 ` [RFA][PATCH 1/8] seq_file: Rename seq_overflow() to seq_has_overflowed() and make public Joe Perches
2014-10-29 23:42 ` Steven Rostedt
2014-10-29 23:53 ` Joe Perches
2014-10-30 0:10 ` Steven Rostedt
2014-10-30 0:26 ` Joe Perches
2014-10-30 0:20 ` Steven Rostedt
2014-10-30 0:27 ` Steven Rostedt
2014-10-30 4:39 ` Joe Perches
2014-10-29 21:56 ` [RFA][PATCH 2/8] netfilter: Remove return values for print_conntrack callbacks Steven Rostedt
2014-10-29 22:16 ` Florian Westphal
2014-10-29 23:53 ` Steven Rostedt
2014-10-30 1:06 ` Steven Rostedt
2014-11-04 13:05 ` Steven Rostedt
2014-11-04 14:11 ` Steven Rostedt
2014-11-04 14:22 ` Pablo Neira Ayuso
2014-11-04 14:31 ` Steven Rostedt
2014-11-04 14:46 ` Joe Perches
2014-11-04 14:52 ` Steven Rostedt
2014-11-04 14:46 ` Pablo Neira Ayuso
2014-11-04 14:48 ` Steven Rostedt
2014-11-04 19:59 ` Steven Rostedt
2014-10-29 21:56 ` [RFA][PATCH 3/8] netfilter: Convert print_tuple functions to return void Steven Rostedt
2014-11-04 13:07 ` Steven Rostedt
2014-11-04 14:50 ` Steven Rostedt
2014-10-29 21:56 ` [RFA][PATCH 4/8] netfilter: Remove checks of seq_printf() return values Steven Rostedt
2014-11-04 13:08 ` Steven Rostedt
2014-10-29 21:56 ` [Cluster-devel] [RFA][PATCH 5/8] dlm: Remove seq_printf() return checks and use seq_has_overflowed() Steven Rostedt
2014-10-29 21:56 ` Steven Rostedt
2014-11-04 13:08 ` [Cluster-devel] " Steven Rostedt
2014-11-04 13:08 ` Steven Rostedt
2014-11-04 19:57 ` [Cluster-devel] " David Teigland
2014-11-04 19:57 ` David Teigland
2014-10-29 21:56 ` [Cluster-devel] [RFA][PATCH 6/8] dlm: Use seq_puts() instead of seq_printf() for constant strings Steven Rostedt
2014-10-29 21:56 ` Steven Rostedt
2014-11-04 13:09 ` [Cluster-devel] " Steven Rostedt
2014-11-04 13:09 ` Steven Rostedt
2014-10-29 21:56 ` [RFA][PATCH 7/8] fs: Convert show_fdinfo functions to void Steven Rostedt
2014-10-29 21:56 ` [RFA][PATCH 8/8] debugfs: Have debugfs_print_regs32() return void Steven Rostedt
2014-10-29 22:03 ` Greg Kroah-Hartman
2014-10-29 23:37 ` Steven Rostedt
2014-11-04 13:04 ` [RFA][PATCH 0/8] seq_file: Remove return checks of seq_printf() Steven Rostedt
2014-11-05 17:50 ` Al Viro
2014-11-05 18:14 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141029220107.333126455@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.