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

Chen-Yu Tsai <[email protected]>
Newsgroups org.kernel.vger.linux-hardening,org.kernel.vger.linux-kernel
Message-ID <CAGXv+5EKtcEy29oy=8Qah=1=PXXMds3BvR08u7DQ656FB2u95Q@mail.gmail.com>
On Tue, Aug 11, 2026 at 3:13 PM Andy Shevchenko
<[email protected]> 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 <[email protected]>
> Link: https://lore.kernel.org/r/CAGXv+5HGZwAKpGpyV4=QHfg7yBQPx-syc1Gma2qad_tzW_RLog@mail.gmail.com
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
>  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 <[email protected]>

>  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
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.