string: Introduce __free(kfree_const)
PATCH 1/1 string: Introduce __free(kfree_const)
__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).
--- include/linux/string.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/string.h +3 -0
@@ -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)) +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);
Signature · 1 line
2.50.1
Quoted 17 lines · Andy Shevchenko
__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 (viakasprintf(), for example).Requested-by Chen-Yu Tsai <[email protected]>Link https://lore.kernel.org/r/CAGXv+5HGZwAKpGpyV4=QHfg7yBQPx-syc1Gma2qad_tzW_RLog@mail.gmail.com open hereSigned-off-by Andy Shevchenko <[email protected]>--- include/linux/string.h | 3 +++ 1 file changed, 3 insertions(+)include/linux/string.h +0
-0
include/linux/string.h static inline bool mem_is_zero(const void *s, size_t n) · line 301
Quoted 8 lines
include/linux/string.h +3
-0@@ -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
Quoted 6 lines
include/linux/string.h +0
-1extern 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
Quoted 6 lines · Chen-Yu Tsai
On Tue, Aug 11, 2026 at 3:13 PM Andy Shevchenko
<[email protected]> wrote:Matches what we already have for
kfree(), soReviewed-by Chen-Yu Tsai <[email protected]>
Thanks!
I think you can incorporate this to (will be) your mini-series. But let's hear from Kees and others if he is okay with the idea.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Chen-Yu Tsai
On Tue, Aug 11, 2026 at 3:13 PM Andy Shevchenko
<[email protected]> wrote:
Quoted 8 lines
Quoted 3 lines
Matches what we already have for
kfree(), soReviewed-by Chen-Yu Tsai <[email protected]>Thanks!
I think you can incorporate this to (will be) your mini-series. But let's hear from Kees and others if he is okay with the idea.
If folks can merge it for the next cycle that would be even better. My series already has three cross-tree build dependencies...
ChenYu
Quoted 12 lines · Chen-Yu Tsai
Quoted 9 lines · Andy Shevchenko
Quoted 6 lines · Chen-Yu Tsai
On Tue, Aug 11, 2026 at 3:13 PM Andy Shevchenko
<[email protected]> wrote:Matches what we already have for
kfree(), soReviewed-by Chen-Yu Tsai <[email protected]>
Quoted 7 lines
Quoted 4 lines
Thanks!
I think you can incorporate this to (will be) your mini-series. But let's hear from Kees and others if he is okay with the idea.
If folks can merge it for the next cycle that would be even better. My series already has three cross-tree build dependencies...
Ah, no, I got it confused with my other stuff in-flight. This one is easy.
Anyway, will wait for others to respond.