[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1421082828.9233.13.camel@perches.com>
Date: Mon, 12 Jan 2015 09:13:48 -0800
From: Joe Perches <joe@...ches.com>
To: Andrzej Hajda <a.hajda@...sung.com>
Cc: linux-mm@...ck.org, Marek Szyprowski <m.szyprowski@...sung.com>,
Kyungmin Park <kyungmin.park@...sung.com>,
linux-kernel@...r.kernel.org, andi@...stfloor.org, andi@...as.de,
Mike Turquette <mturquette@...aro.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH 1/5] mm/util: add kstrdup_const
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 majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists