Skip to contentSkip to conversation

string: Introduce __free(kfree_const)

PATCH In review Andy Shevchenko 2 participants 5 messages Aug 11 Generic string library

lore
Share & tools
lore
#0 lore raw

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
index 75bfc194ad20..6f3501b56c11 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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 (via kasprintf(), for example).

---
 include/linux/string.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/string.h +0 -0
index 75bfc194ad20..6f3501b56c11 100644

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 -1
 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

#2 lore raw
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(), so

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
#3 lore raw
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(), so

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

#4 lore raw
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(), so

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.