aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2016-01-15 19:58:28 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-16 14:17:25 -0500
commitcfccde04e28d26e9f102e535b7358bf6cf3bc6fb (patch)
tree2a1ff647c17950e2210dcbed6c1c08bc699b18aa
parent8d91f8b15361dfb438ab6eb3b319e2ded43458ff (diff)
lib/vsprintf.c: pull out padding code from dentry_name()
Pull out the logic in dentry_name() which handles field width space padding, in preparation for reusing it from string(). Rename the widen() helper to move_right(), since it is used for handling the !(flags & LEFT) case. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Al Viro <viro@ZenIV.linux.org.uk> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Joe Perches <joe@perches.com> Cc: Kees Cook <keescook@chromium.org> Cc: Maurizio Lombardi <mlombard@redhat.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--lib/vsprintf.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index ac3f9476b776..3f37b478c429 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -541,7 +541,7 @@ char *string(char *buf, char *end, const char *s, struct printf_spec spec)
541 return buf; 541 return buf;
542} 542}
543 543
544static void widen(char *buf, char *end, unsigned len, unsigned spaces) 544static void move_right(char *buf, char *end, unsigned len, unsigned spaces)
545{ 545{
546 size_t size; 546 size_t size;
547 if (buf >= end) /* nowhere to put anything */ 547 if (buf >= end) /* nowhere to put anything */
@@ -559,6 +559,35 @@ static void widen(char *buf, char *end, unsigned len, unsigned spaces)
559 memset(buf, ' ', spaces); 559 memset(buf, ' ', spaces);
560} 560}
561 561
562/*
563 * Handle field width padding for a string.
564 * @buf: current buffer position
565 * @n: length of string
566 * @end: end of output buffer
567 * @spec: for field width and flags
568 * Returns: new buffer position after padding.
569 */
570static noinline_for_stack
571char *widen_string(char *buf, int n, char *end, struct printf_spec spec)
572{
573 unsigned spaces;
574
575 if (likely(n >= spec.field_width))
576 return buf;
577 /* we want to pad the sucker */
578 spaces = spec.field_width - n;
579 if (!(spec.flags & LEFT)) {
580 move_right(buf - n, end, n, spaces);
581 return buf + spaces;
582 }
583 while (spaces--) {
584 if (buf < end)
585 *buf = ' ';
586 ++buf;
587 }
588 return buf;
589}
590
562static noinline_for_stack 591static noinline_for_stack
563char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_spec spec, 592char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_spec spec,
564 const char *fmt) 593 const char *fmt)
@@ -600,20 +629,7 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
600 *buf = c; 629 *buf = c;
601 } 630 }
602 rcu_read_unlock(); 631 rcu_read_unlock();
603 if (n < spec.field_width) { 632 return widen_string(buf, n, end, spec);
604 /* we want to pad the sucker */
605 unsigned spaces = spec.field_width - n;
606 if (!(spec.flags & LEFT)) {
607 widen(buf - n, end, n, spaces);
608 return buf + spaces;
609 }
610 while (spaces--) {
611 if (buf < end)
612 *buf = ' ';
613 ++buf;
614 }
615 }
616 return buf;
617} 633}
618 634
619#ifdef CONFIG_BLOCK 635#ifdef CONFIG_BLOCK