aboutsummaryrefslogtreecommitdiffstats
path: root/fs/seq_file.c
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2015-09-11 16:07:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-11 18:21:34 -0400
commit6798a8caaf64fa68b9ab2044e070fe4545034e03 (patch)
tree0703bb5ad58e92d21c00a69359ba962ba4928740 /fs/seq_file.c
parentc9946c4208a3725e116c05180d93154eb406d451 (diff)
fs/seq_file: convert int seq_vprint/seq_printf/etc... returns to void
The seq_<foo> function return values were frequently misused. See: commit 1f33c41c03da ("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>
Diffstat (limited to 'fs/seq_file.c')
-rw-r--r--fs/seq_file.c70
1 files changed, 31 insertions, 39 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 263b125dbcf4..225586e141ca 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -372,16 +372,16 @@ EXPORT_SYMBOL(seq_release);
372 * @esc: set of characters that need escaping 372 * @esc: set of characters that need escaping
373 * 373 *
374 * Puts string into buffer, replacing each occurrence of character from 374 * Puts string into buffer, replacing each occurrence of character from
375 * @esc with usual octal escape. Returns 0 in case of success, -1 - in 375 * @esc with usual octal escape.
376 * case of overflow. 376 * Use seq_has_overflowed() to check for errors.
377 */ 377 */
378int seq_escape(struct seq_file *m, const char *s, const char *esc) 378void seq_escape(struct seq_file *m, const char *s, const char *esc)
379{ 379{
380 char *end = m->buf + m->size; 380 char *end = m->buf + m->size;
381 char *p; 381 char *p;
382 char c; 382 char c;
383 383
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++) {
385 if (!strchr(esc, c)) { 385 if (!strchr(esc, c)) {
386 *p++ = c; 386 *p++ = c;
387 continue; 387 continue;
@@ -394,14 +394,13 @@ int seq_escape(struct seq_file *m, const char *s, const char *esc)
394 continue; 394 continue;
395 } 395 }
396 seq_set_overflow(m); 396 seq_set_overflow(m);
397 return -1; 397 return;
398 } 398 }
399 m->count = p - m->buf; 399 m->count = p - m->buf;
400 return 0;
401} 400}
402EXPORT_SYMBOL(seq_escape); 401EXPORT_SYMBOL(seq_escape);
403 402
404int seq_vprintf(struct seq_file *m, const char *f, va_list args) 403void seq_vprintf(struct seq_file *m, const char *f, va_list args)
405{ 404{
406 int len; 405 int len;
407 406
@@ -409,24 +408,20 @@ int seq_vprintf(struct seq_file *m, const char *f, va_list args)
409 len = vsnprintf(m->buf + m->count, m->size - m->count, f, args); 408 len = vsnprintf(m->buf + m->count, m->size - m->count, f, args);
410 if (m->count + len < m->size) { 409 if (m->count + len < m->size) {
411 m->count += len; 410 m->count += len;
412 return 0; 411 return;
413 } 412 }
414 } 413 }
415 seq_set_overflow(m); 414 seq_set_overflow(m);
416 return -1;
417} 415}
418EXPORT_SYMBOL(seq_vprintf); 416EXPORT_SYMBOL(seq_vprintf);
419 417
420int seq_printf(struct seq_file *m, const char *f, ...) 418void seq_printf(struct seq_file *m, const char *f, ...)
421{ 419{
422 int ret;
423 va_list args; 420 va_list args;
424 421
425 va_start(args, f); 422 va_start(args, f);
426 ret = seq_vprintf(m, f, args); 423 seq_vprintf(m, f, args);
427 va_end(args); 424 va_end(args);
428
429 return ret;
430} 425}
431EXPORT_SYMBOL(seq_printf); 426EXPORT_SYMBOL(seq_printf);
432 427
@@ -664,26 +659,25 @@ int seq_open_private(struct file *filp, const struct seq_operations *ops,
664} 659}
665EXPORT_SYMBOL(seq_open_private); 660EXPORT_SYMBOL(seq_open_private);
666 661
667int seq_putc(struct seq_file *m, char c) 662void seq_putc(struct seq_file *m, char c)
668{ 663{
669 if (m->count < m->size) { 664 if (m->count >= m->size)
670 m->buf[m->count++] = c; 665 return;
671 return 0; 666
672 } 667 m->buf[m->count++] = c;
673 return -1;
674} 668}
675EXPORT_SYMBOL(seq_putc); 669EXPORT_SYMBOL(seq_putc);
676 670
677int seq_puts(struct seq_file *m, const char *s) 671void seq_puts(struct seq_file *m, const char *s)
678{ 672{
679 int len = strlen(s); 673 int len = strlen(s);
680 if (m->count + len < m->size) { 674
681 memcpy(m->buf + m->count, s, len); 675 if (m->count + len >= m->size) {
682 m->count += len; 676 seq_set_overflow(m);
683 return 0; 677 return;
684 } 678 }
685 seq_set_overflow(m); 679 memcpy(m->buf + m->count, s, len);
686 return -1; 680 m->count += len;
687} 681}
688EXPORT_SYMBOL(seq_puts); 682EXPORT_SYMBOL(seq_puts);
689 683
@@ -694,8 +688,8 @@ EXPORT_SYMBOL(seq_puts);
694 * This routine is very quick when you show lots of numbers. 688 * This routine is very quick when you show lots of numbers.
695 * In usual cases, it will be better to use seq_printf(). It's easier to read. 689 * In usual cases, it will be better to use seq_printf(). It's easier to read.
696 */ 690 */
697int seq_put_decimal_ull(struct seq_file *m, char delimiter, 691void seq_put_decimal_ull(struct seq_file *m, char delimiter,
698 unsigned long long num) 692 unsigned long long num)
699{ 693{
700 int len; 694 int len;
701 695
@@ -707,35 +701,33 @@ int seq_put_decimal_ull(struct seq_file *m, char delimiter,
707 701
708 if (num < 10) { 702 if (num < 10) {
709 m->buf[m->count++] = num + '0'; 703 m->buf[m->count++] = num + '0';
710 return 0; 704 return;
711 } 705 }
712 706
713 len = num_to_str(m->buf + m->count, m->size - m->count, num); 707 len = num_to_str(m->buf + m->count, m->size - m->count, num);
714 if (!len) 708 if (!len)
715 goto overflow; 709 goto overflow;
716 m->count += len; 710 m->count += len;
717 return 0; 711 return;
712
718overflow: 713overflow:
719 seq_set_overflow(m); 714 seq_set_overflow(m);
720 return -1;
721} 715}
722EXPORT_SYMBOL(seq_put_decimal_ull); 716EXPORT_SYMBOL(seq_put_decimal_ull);
723 717
724int seq_put_decimal_ll(struct seq_file *m, char delimiter, 718void seq_put_decimal_ll(struct seq_file *m, char delimiter, long long num)
725 long long num)
726{ 719{
727 if (num < 0) { 720 if (num < 0) {
728 if (m->count + 3 >= m->size) { 721 if (m->count + 3 >= m->size) {
729 seq_set_overflow(m); 722 seq_set_overflow(m);
730 return -1; 723 return;
731 } 724 }
732 if (delimiter) 725 if (delimiter)
733 m->buf[m->count++] = delimiter; 726 m->buf[m->count++] = delimiter;
734 num = -num; 727 num = -num;
735 delimiter = '-'; 728 delimiter = '-';
736 } 729 }
737 return seq_put_decimal_ull(m, delimiter, num); 730 seq_put_decimal_ull(m, delimiter, num);
738
739} 731}
740EXPORT_SYMBOL(seq_put_decimal_ll); 732EXPORT_SYMBOL(seq_put_decimal_ll);
741 733