Re: [PATCH v1 1/1] string: Introduce __free(kfree_const)

From: Chen-Yu Tsai

Date: Tue Aug 11 2026 - 06:44:24 EST


On Tue, Aug 11, 2026 at 3:13 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
>
> __free(kfree_const) may be used in the cases when one part of the code
> relies on the constant string literals, while the other uses a heap
> (via kasprintf(), for example).
>
> Requested-by: Chen-Yu Tsai <wenst@xxxxxxxxxxxx>
> Link: https://lore.kernel.org/r/CAGXv+5HGZwAKpGpyV4=QHfg7yBQPx-syc1Gma2qad_tzW_RLog@xxxxxxxxxxxxxx
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> ---
> include/linux/string.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 75bfc194ad20..6f3501b56c11 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -294,8 +294,11 @@ static inline bool mem_is_zero(const void *s, size_t n)
> return !memchr_inv(s, 0, n);
> }
>
> +/* mm/util.c */
> extern void kfree_const(const void *x);
>
> +DEFINE_FREE(kfree_const, void *, if (!IS_ERR_OR_NULL(_T)) kfree_const(_T))
> +

Matches what we already have for kfree(), so

Reviewed-by: Chen-Yu Tsai <wenst@xxxxxxxxxxxx>

> extern char *kstrdup(const char *s, gfp_t gfp) __malloc;
> extern const char *kstrdup_const(const char *s, gfp_t gfp);
> extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
> --
> 2.50.1
>