From: Matthew Wilcox Date: Wed, 12 Dec 2018 19:00:08 +0000 (-0500) Subject: printf: Convert dentry_name() to printf_state X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5d68ee99bea59af5d58447ed99197b3d5cc668e6;p=users%2Fwilly%2Flinux.git printf: Convert dentry_name() to printf_state Turn %pD into a fallthrough instead of a separate call. Add printf_widen_string() as widen_string() still has legacy callers. Signed-off-by: Matthew Wilcox --- diff --git a/lib/vsprintf.c b/lib/vsprintf.c index fa7c7ae9216b..7fadfd514e9f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -587,6 +587,11 @@ char *widen_string(char *buf, int n, char *end, struct printf_spec spec) return buf; } +static void printf_widen_string(struct printf_state *ps, int n) +{ + ps->buf = widen_string(ps->buf, n, ps->end, ps->spec); +} + static noinline_for_stack char *string(char *buf, char *end, const char *s, struct printf_spec spec) { @@ -717,17 +722,16 @@ static char *ptr_to_id(char *buf, char *end, const void *ptr, } static noinline_for_stack -char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_spec spec, - const char *fmt) +char *dentry_name(struct printf_state *ps, const struct dentry *d) { const char *array[4], *s; const struct dentry *p; int depth; int i, n; - switch (fmt[1]) { + switch (ps->fmt[1]) { case '2': case '3': case '4': - depth = fmt[1] - '0'; + depth = ps->fmt[1] - '0'; break; default: depth = 1; @@ -745,7 +749,7 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp } } s = array[--i]; - for (n = 0; n != spec.precision; n++, buf++) { + for (n = 0; n != ps->spec.precision; n++, ps->buf++) { char c = *s++; if (!c) { if (!i) @@ -753,11 +757,12 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp c = '/'; s = array[--i]; } - if (buf < end) - *buf = c; + if (ps->buf < ps->end) + *ps->buf = c; } rcu_read_unlock(); - return widen_string(buf, n, end, spec); + printf_widen_string(ps, n); + return ps->buf; } #ifdef CONFIG_BLOCK @@ -1954,14 +1959,13 @@ char *pointer(struct printf_state *ps, void *ptr) return netdev_bits(buf, end, ptr, spec, fmt); case 'a': return address_val(buf, end, ptr, fmt); + case 'D': + ptr = ((const struct file *)ptr)->f_path.dentry; + /* fall through */ case 'd': - return dentry_name(buf, end, ptr, spec, fmt); + return dentry_name(ps, ptr); case 'C': return clock(buf, end, ptr, spec, fmt); - case 'D': - return dentry_name(buf, end, - ((const struct file *)ptr)->f_path.dentry, - spec, fmt); #ifdef CONFIG_BLOCK case 'g': return bdev_name(ps, ptr);