Commit 6798a8ca authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

fs/seq_file: convert int seq_vprint/seq_printf/etc... returns to void

The seq_<foo> function return values were frequently misused.

See: commit 1f33c41c ("seq_file: Rename seq_overflow() to
     seq_has_overflowed() and make public")

All uses of these return values have been removed, so convert the
return types to void.

Miscellanea:

o Move seq_put_decimal_<type> and seq_escape prototypes closer the
  other seq_vprintf prototypes
o Reorder seq_putc and seq_puts to return early on overflow
o Add argument names to seq_vprintf and seq_printf
o Update the seq_escape kernel-doc
o Convert a couple of leading spaces to tabs in seq_escape
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Joerg Roedel <jroedel@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c9946c42
...@@ -135,8 +135,9 @@ __dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num) ...@@ -135,8 +135,9 @@ __dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num)
static ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr, static ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr,
struct seq_file *s) struct seq_file *s)
{ {
return seq_printf(s, "%08x %08x %01x\n", cr->cam, cr->ram, seq_printf(s, "%08x %08x %01x\n", cr->cam, cr->ram,
(cr->cam & MMU_CAM_P) ? 1 : 0); (cr->cam & MMU_CAM_P) ? 1 : 0);
return 0;
} }
static size_t omap_dump_tlb_entries(struct omap_iommu *obj, struct seq_file *s) static size_t omap_dump_tlb_entries(struct omap_iommu *obj, struct seq_file *s)
......
...@@ -142,7 +142,8 @@ static int nsfs_show_path(struct seq_file *seq, struct dentry *dentry) ...@@ -142,7 +142,8 @@ static int nsfs_show_path(struct seq_file *seq, struct dentry *dentry)
struct inode *inode = d_inode(dentry); struct inode *inode = d_inode(dentry);
const struct proc_ns_operations *ns_ops = dentry->d_fsdata; const struct proc_ns_operations *ns_ops = dentry->d_fsdata;
return seq_printf(seq, "%s:[%lu]", ns_ops->name, inode->i_ino); seq_printf(seq, "%s:[%lu]", ns_ops->name, inode->i_ino);
return 0;
} }
static const struct super_operations nsfs_ops = { static const struct super_operations nsfs_ops = {
......
...@@ -372,16 +372,16 @@ EXPORT_SYMBOL(seq_release); ...@@ -372,16 +372,16 @@ EXPORT_SYMBOL(seq_release);
* @esc: set of characters that need escaping * @esc: set of characters that need escaping
* *
* Puts string into buffer, replacing each occurrence of character from * Puts string into buffer, replacing each occurrence of character from
* @esc with usual octal escape. Returns 0 in case of success, -1 - in * @esc with usual octal escape.
* case of overflow. * Use seq_has_overflowed() to check for errors.
*/ */
int seq_escape(struct seq_file *m, const char *s, const char *esc) void seq_escape(struct seq_file *m, const char *s, const char *esc)
{ {
char *end = m->buf + m->size; char *end = m->buf + m->size;
char *p; char *p;
char c; char c;
for (p = m->buf + m->count; (c = *s) != '\0' && p < end; s++) { for (p = m->buf + m->count; (c = *s) != '\0' && p < end; s++) {
if (!strchr(esc, c)) { if (!strchr(esc, c)) {
*p++ = c; *p++ = c;
continue; continue;
...@@ -394,14 +394,13 @@ int seq_escape(struct seq_file *m, const char *s, const char *esc) ...@@ -394,14 +394,13 @@ int seq_escape(struct seq_file *m, const char *s, const char *esc)
continue; continue;
} }
seq_set_overflow(m); seq_set_overflow(m);
return -1; return;
} }
m->count = p - m->buf; m->count = p - m->buf;
return 0;
} }
EXPORT_SYMBOL(seq_escape); EXPORT_SYMBOL(seq_escape);
int seq_vprintf(struct seq_file *m, const char *f, va_list args) void seq_vprintf(struct seq_file *m, const char *f, va_list args)
{ {
int len; int len;
...@@ -409,24 +408,20 @@ int seq_vprintf(struct seq_file *m, const char *f, va_list args) ...@@ -409,24 +408,20 @@ int seq_vprintf(struct seq_file *m, const char *f, va_list args)
len = vsnprintf(m->buf + m->count, m->size - m->count, f, args); len = vsnprintf(m->buf + m->count, m->size - m->count, f, args);
if (m->count + len < m->size) { if (m->count + len < m->size) {
m->count += len; m->count += len;
return 0; return;
} }
} }
seq_set_overflow(m); seq_set_overflow(m);
return -1;
} }
EXPORT_SYMBOL(seq_vprintf); EXPORT_SYMBOL(seq_vprintf);
int seq_printf(struct seq_file *m, const char *f, ...) void seq_printf(struct seq_file *m, const char *f, ...)
{ {
int ret;
va_list args; va_list args;
va_start(args, f); va_start(args, f);
ret = seq_vprintf(m, f, args); seq_vprintf(m, f, args);
va_end(args); va_end(args);
return ret;
} }
EXPORT_SYMBOL(seq_printf); EXPORT_SYMBOL(seq_printf);
...@@ -664,26 +659,25 @@ int seq_open_private(struct file *filp, const struct seq_operations *ops, ...@@ -664,26 +659,25 @@ int seq_open_private(struct file *filp, const struct seq_operations *ops,
} }
EXPORT_SYMBOL(seq_open_private); EXPORT_SYMBOL(seq_open_private);
int seq_putc(struct seq_file *m, char c) void seq_putc(struct seq_file *m, char c)
{ {
if (m->count < m->size) { if (m->count >= m->size)
m->buf[m->count++] = c; return;
return 0;
} m->buf[m->count++] = c;
return -1;
} }
EXPORT_SYMBOL(seq_putc); EXPORT_SYMBOL(seq_putc);
int seq_puts(struct seq_file *m, const char *s) void seq_puts(struct seq_file *m, const char *s)
{ {
int len = strlen(s); int len = strlen(s);
if (m->count + len < m->size) {
memcpy(m->buf + m->count, s, len); if (m->count + len >= m->size) {
m->count += len; seq_set_overflow(m);
return 0; return;
} }
seq_set_overflow(m); memcpy(m->buf + m->count, s, len);
return -1; m->count += len;
} }
EXPORT_SYMBOL(seq_puts); EXPORT_SYMBOL(seq_puts);
...@@ -694,8 +688,8 @@ EXPORT_SYMBOL(seq_puts); ...@@ -694,8 +688,8 @@ EXPORT_SYMBOL(seq_puts);
* This routine is very quick when you show lots of numbers. * This routine is very quick when you show lots of numbers.
* In usual cases, it will be better to use seq_printf(). It's easier to read. * In usual cases, it will be better to use seq_printf(). It's easier to read.
*/ */
int seq_put_decimal_ull(struct seq_file *m, char delimiter, void seq_put_decimal_ull(struct seq_file *m, char delimiter,
unsigned long long num) unsigned long long num)
{ {
int len; int len;
...@@ -707,35 +701,33 @@ int seq_put_decimal_ull(struct seq_file *m, char delimiter, ...@@ -707,35 +701,33 @@ int seq_put_decimal_ull(struct seq_file *m, char delimiter,
if (num < 10) { if (num < 10) {
m->buf[m->count++] = num + '0'; m->buf[m->count++] = num + '0';
return 0; return;
} }
len = num_to_str(m->buf + m->count, m->size - m->count, num); len = num_to_str(m->buf + m->count, m->size - m->count, num);
if (!len) if (!len)
goto overflow; goto overflow;
m->count += len; m->count += len;
return 0; return;
overflow: overflow:
seq_set_overflow(m); seq_set_overflow(m);
return -1;
} }
EXPORT_SYMBOL(seq_put_decimal_ull); EXPORT_SYMBOL(seq_put_decimal_ull);
int seq_put_decimal_ll(struct seq_file *m, char delimiter, void seq_put_decimal_ll(struct seq_file *m, char delimiter, long long num)
long long num)
{ {
if (num < 0) { if (num < 0) {
if (m->count + 3 >= m->size) { if (m->count + 3 >= m->size) {
seq_set_overflow(m); seq_set_overflow(m);
return -1; return;
} }
if (delimiter) if (delimiter)
m->buf[m->count++] = delimiter; m->buf[m->count++] = delimiter;
num = -num; num = -num;
delimiter = '-'; delimiter = '-';
} }
return seq_put_decimal_ull(m, delimiter, num); seq_put_decimal_ull(m, delimiter, num);
} }
EXPORT_SYMBOL(seq_put_decimal_ll); EXPORT_SYMBOL(seq_put_decimal_ll);
......
...@@ -114,13 +114,18 @@ int seq_open(struct file *, const struct seq_operations *); ...@@ -114,13 +114,18 @@ int seq_open(struct file *, const struct seq_operations *);
ssize_t seq_read(struct file *, char __user *, size_t, loff_t *); ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
loff_t seq_lseek(struct file *, loff_t, int); loff_t seq_lseek(struct file *, loff_t, int);
int seq_release(struct inode *, struct file *); int seq_release(struct inode *, struct file *);
int seq_escape(struct seq_file *, const char *, const char *);
int seq_putc(struct seq_file *m, char c);
int seq_puts(struct seq_file *m, const char *s);
int seq_write(struct seq_file *seq, const void *data, size_t len); int seq_write(struct seq_file *seq, const void *data, size_t len);
__printf(2, 3) int seq_printf(struct seq_file *, const char *, ...); __printf(2, 0)
__printf(2, 0) int seq_vprintf(struct seq_file *, const char *, va_list args); void seq_vprintf(struct seq_file *m, const char *fmt, va_list args);
__printf(2, 3)
void seq_printf(struct seq_file *m, const char *fmt, ...);
void seq_putc(struct seq_file *m, char c);
void seq_puts(struct seq_file *m, const char *s);
void seq_put_decimal_ull(struct seq_file *m, char delimiter,
unsigned long long num);
void seq_put_decimal_ll(struct seq_file *m, char delimiter, long long num);
void seq_escape(struct seq_file *m, const char *s, const char *esc);
void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
int rowsize, int groupsize, const void *buf, size_t len, int rowsize, int groupsize, const void *buf, size_t len,
...@@ -138,10 +143,6 @@ int single_release(struct inode *, struct file *); ...@@ -138,10 +143,6 @@ int single_release(struct inode *, struct file *);
void *__seq_open_private(struct file *, const struct seq_operations *, int); void *__seq_open_private(struct file *, const struct seq_operations *, int);
int seq_open_private(struct file *, const struct seq_operations *, int); int seq_open_private(struct file *, const struct seq_operations *, int);
int seq_release_private(struct inode *, struct file *); int seq_release_private(struct inode *, struct file *);
int seq_put_decimal_ull(struct seq_file *m, char delimiter,
unsigned long long num);
int seq_put_decimal_ll(struct seq_file *m, char delimiter,
long long num);
static inline struct user_namespace *seq_user_ns(struct seq_file *seq) static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment