Commit 5fe9d8ca authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

coredump: cn_vprintf() has no reason to call vsnprintf() twice

cn_vprintf() looks really overcomplicated and sub-optimal.  We do not need
vsnprintf(NULL) to calculate the size we need, we can simply try to print
into the current buffer and expand/retry only if necessary.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Colin Walters <walters@verbum.org>
Cc: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Lennart Poettering <mzxreary@0pointer.de>
Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>
Acked-by: default avatarNeil Horman <nhorman@tuxdriver.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bc03c691
...@@ -71,26 +71,20 @@ static int expand_corename(struct core_name *cn) ...@@ -71,26 +71,20 @@ static int expand_corename(struct core_name *cn)
static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg) static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
{ {
char *cur; int free, need;
int need;
int ret; again:
free = cn->size - cn->used;
need = vsnprintf(NULL, 0, fmt, arg); need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
if (likely(need < cn->size - cn->used - 1)) if (need < free) {
goto out_printf; cn->used += need;
return 0;
ret = expand_corename(cn); }
if (ret)
goto expand_fail;
out_printf: if (!expand_corename(cn))
cur = cn->corename + cn->used; goto again;
vsnprintf(cur, need + 1, fmt, arg);
cn->used += need;
return 0;
expand_fail: return -ENOMEM;
return ret;
} }
static int cn_printf(struct core_name *cn, const char *fmt, ...) static int cn_printf(struct core_name *cn, const char *fmt, ...)
......
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