• Rasmus Villemoes's avatar
    lib/kasprintf.c: introduce kvasprintf_const · 0a9df786
    Rasmus Villemoes authored
    This adds kvasprintf_const which tries to use kstrdup_const if possible:
    If the format string contains no % characters, or if the format string is
    exactly "%s", we delegate to kstrdup_const.  Otherwise, we fall back to
    Just as for kstrdup_const, the main motivation is to save memory by
    reusing .rodata when possible.
    The return value should be freed by kfree_const, just like for
    There is deliberately no kasprintf_const: In the vast majority of cases,
    the format string argument is a literal, so one can determine statically
    whether one could instead use kstrdup_const directly (which would also
    require one to change all corresponding kfree calls to kfree_const).
    Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
    Cc: Greg KH <greg@kroah.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
kernel.h 27.2 KB