On Mon, 2015-01-12 at 10:18 +0100, Andrzej Hajda wrote: > The patch adds alternative version of kstrdup which returns pointer > to constant char array. The function checks if input string is in > persistent and read-only memory section, if yes it returns the input string, > otherwise it fallbacks to kstrdup. > kstrdup_const is accompanied by kfree_const performing conditional memory > deallocation of the string.
trivia: > diff --git a/mm/util.c b/mm/util.c [] > +void kfree_const(const void *x) > +{ > + if (!is_kernel_rodata((unsigned long)x)) > + kfree(x); > +} > +EXPORT_SYMBOL(kfree_const); [] > +const char *kstrdup_const(const char *s, gfp_t gfp) > +{ > + if (is_kernel_rodata((unsigned long)s)) > + return s; > + > + return kstrdup(s, gfp); > +} > +EXPORT_SYMBOL(kstrdup_const); I think it'd be nicer if these used the same form even if it's a vertical line or 2 longer void kfree_const(const void *x) { if (is_kernel_rodata((unsigned long)x)) return; kfree(x); } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/