Skip to content

Commit 6798a8c

Browse files
JoePerchestorvalds
authored andcommitted
fs/seq_file: convert int seq_vprint/seq_printf/etc... returns to void
The seq_<foo> function return values were frequently misused. See: commit 1f33c41 ("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: Joe 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c9946c4 commit 6798a8c

File tree

4 files changed

+45
-50
lines changed

4 files changed

+45
-50
lines changed

drivers/iommu/omap-iommu-debug.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ __dump_tlb_entries(struct omap_iommu *obj, struct cr_regs *crs, int num)
135135
static ssize_t iotlb_dump_cr(struct omap_iommu *obj, struct cr_regs *cr,
136136
struct seq_file *s)
137137
{
138-
return seq_printf(s, "%08x %08x %01x\n", cr->cam, cr->ram,
138+
seq_printf(s, "%08x %08x %01x\n", cr->cam, cr->ram,
139139
(cr->cam & MMU_CAM_P) ? 1 : 0);
140+
return 0;
140141
}
141142

142143
static size_t omap_dump_tlb_entries(struct omap_iommu *obj, struct seq_file *s)

fs/nsfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ static int nsfs_show_path(struct seq_file *seq, struct dentry *dentry)
142142
struct inode *inode = d_inode(dentry);
143143
const struct proc_ns_operations *ns_ops = dentry->d_fsdata;
144144

145-
return seq_printf(seq, "%s:[%lu]", ns_ops->name, inode->i_ino);
145+
seq_printf(seq, "%s:[%lu]", ns_ops->name, inode->i_ino);
146+
return 0;
146147
}
147148

148149
static const struct super_operations nsfs_ops = {

fs/seq_file.c

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,16 @@ EXPORT_SYMBOL(seq_release);
372372
* @esc: set of characters that need escaping
373373
*
374374
* Puts string into buffer, replacing each occurrence of character from
375-
* @esc with usual octal escape. Returns 0 in case of success, -1 - in
376-
* case of overflow.
375+
* @esc with usual octal escape.
376+
* Use seq_has_overflowed() to check for errors.
377377
*/
378-
int seq_escape(struct seq_file *m, const char *s, const char *esc)
378+
void seq_escape(struct seq_file *m, const char *s, const char *esc)
379379
{
380380
char *end = m->buf + m->size;
381-
char *p;
381+
char *p;
382382
char c;
383383

384-
for (p = m->buf + m->count; (c = *s) != '\0' && p < end; s++) {
384+
for (p = m->buf + m->count; (c = *s) != '\0' && p < end; s++) {
385385
if (!strchr(esc, c)) {
386386
*p++ = c;
387387
continue;
@@ -394,39 +394,34 @@ int seq_escape(struct seq_file *m, const char *s, const char *esc)
394394
continue;
395395
}
396396
seq_set_overflow(m);
397-
return -1;
398-
}
397+
return;
398+
}
399399
m->count = p - m->buf;
400-
return 0;
401400
}
402401
EXPORT_SYMBOL(seq_escape);
403402

404-
int seq_vprintf(struct seq_file *m, const char *f, va_list args)
403+
void seq_vprintf(struct seq_file *m, const char *f, va_list args)
405404
{
406405
int len;
407406

408407
if (m->count < m->size) {
409408
len = vsnprintf(m->buf + m->count, m->size - m->count, f, args);
410409
if (m->count + len < m->size) {
411410
m->count += len;
412-
return 0;
411+
return;
413412
}
414413
}
415414
seq_set_overflow(m);
416-
return -1;
417415
}
418416
EXPORT_SYMBOL(seq_vprintf);
419417

420-
int seq_printf(struct seq_file *m, const char *f, ...)
418+
void seq_printf(struct seq_file *m, const char *f, ...)
421419
{
422-
int ret;
423420
va_list args;
424421

425422
va_start(args, f);
426-
ret = seq_vprintf(m, f, args);
423+
seq_vprintf(m, f, args);
427424
va_end(args);
428-
429-
return ret;
430425
}
431426
EXPORT_SYMBOL(seq_printf);
432427

@@ -664,26 +659,25 @@ int seq_open_private(struct file *filp, const struct seq_operations *ops,
664659
}
665660
EXPORT_SYMBOL(seq_open_private);
666661

667-
int seq_putc(struct seq_file *m, char c)
662+
void seq_putc(struct seq_file *m, char c)
668663
{
669-
if (m->count < m->size) {
670-
m->buf[m->count++] = c;
671-
return 0;
672-
}
673-
return -1;
664+
if (m->count >= m->size)
665+
return;
666+
667+
m->buf[m->count++] = c;
674668
}
675669
EXPORT_SYMBOL(seq_putc);
676670

677-
int seq_puts(struct seq_file *m, const char *s)
671+
void seq_puts(struct seq_file *m, const char *s)
678672
{
679673
int len = strlen(s);
680-
if (m->count + len < m->size) {
681-
memcpy(m->buf + m->count, s, len);
682-
m->count += len;
683-
return 0;
674+
675+
if (m->count + len >= m->size) {
676+
seq_set_overflow(m);
677+
return;
684678
}
685-
seq_set_overflow(m);
686-
return -1;
679+
memcpy(m->buf + m->count, s, len);
680+
m->count += len;
687681
}
688682
EXPORT_SYMBOL(seq_puts);
689683

@@ -694,8 +688,8 @@ EXPORT_SYMBOL(seq_puts);
694688
* This routine is very quick when you show lots of numbers.
695689
* In usual cases, it will be better to use seq_printf(). It's easier to read.
696690
*/
697-
int seq_put_decimal_ull(struct seq_file *m, char delimiter,
698-
unsigned long long num)
691+
void seq_put_decimal_ull(struct seq_file *m, char delimiter,
692+
unsigned long long num)
699693
{
700694
int len;
701695

@@ -707,35 +701,33 @@ int seq_put_decimal_ull(struct seq_file *m, char delimiter,
707701

708702
if (num < 10) {
709703
m->buf[m->count++] = num + '0';
710-
return 0;
704+
return;
711705
}
712706

713707
len = num_to_str(m->buf + m->count, m->size - m->count, num);
714708
if (!len)
715709
goto overflow;
716710
m->count += len;
717-
return 0;
711+
return;
712+
718713
overflow:
719714
seq_set_overflow(m);
720-
return -1;
721715
}
722716
EXPORT_SYMBOL(seq_put_decimal_ull);
723717

724-
int seq_put_decimal_ll(struct seq_file *m, char delimiter,
725-
long long num)
718+
void seq_put_decimal_ll(struct seq_file *m, char delimiter, long long num)
726719
{
727720
if (num < 0) {
728721
if (m->count + 3 >= m->size) {
729722
seq_set_overflow(m);
730-
return -1;
723+
return;
731724
}
732725
if (delimiter)
733726
m->buf[m->count++] = delimiter;
734727
num = -num;
735728
delimiter = '-';
736729
}
737-
return seq_put_decimal_ull(m, delimiter, num);
738-
730+
seq_put_decimal_ull(m, delimiter, num);
739731
}
740732
EXPORT_SYMBOL(seq_put_decimal_ll);
741733

include/linux/seq_file.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,18 @@ int seq_open(struct file *, const struct seq_operations *);
114114
ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
115115
loff_t seq_lseek(struct file *, loff_t, int);
116116
int seq_release(struct inode *, struct file *);
117-
int seq_escape(struct seq_file *, const char *, const char *);
118-
int seq_putc(struct seq_file *m, char c);
119-
int seq_puts(struct seq_file *m, const char *s);
120117
int seq_write(struct seq_file *seq, const void *data, size_t len);
121118

122-
__printf(2, 3) int seq_printf(struct seq_file *, const char *, ...);
123-
__printf(2, 0) int seq_vprintf(struct seq_file *, const char *, va_list args);
119+
__printf(2, 0)
120+
void seq_vprintf(struct seq_file *m, const char *fmt, va_list args);
121+
__printf(2, 3)
122+
void seq_printf(struct seq_file *m, const char *fmt, ...);
123+
void seq_putc(struct seq_file *m, char c);
124+
void seq_puts(struct seq_file *m, const char *s);
125+
void seq_put_decimal_ull(struct seq_file *m, char delimiter,
126+
unsigned long long num);
127+
void seq_put_decimal_ll(struct seq_file *m, char delimiter, long long num);
128+
void seq_escape(struct seq_file *m, const char *s, const char *esc);
124129

125130
void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
126131
int rowsize, int groupsize, const void *buf, size_t len,
@@ -138,10 +143,6 @@ int single_release(struct inode *, struct file *);
138143
void *__seq_open_private(struct file *, const struct seq_operations *, int);
139144
int seq_open_private(struct file *, const struct seq_operations *, int);
140145
int seq_release_private(struct inode *, struct file *);
141-
int seq_put_decimal_ull(struct seq_file *m, char delimiter,
142-
unsigned long long num);
143-
int seq_put_decimal_ll(struct seq_file *m, char delimiter,
144-
long long num);
145146

146147
static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
147148
{

0 commit comments

Comments
 (0)