summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorCasey Connolly <[email protected]>2026-04-01 16:15:19 +0200
committerTom Rini <[email protected]>2026-04-21 11:19:49 -0600
commit139f5292e7985d0326a1d18eee88720255e423dc (patch)
tree2afe47245a7f32ae921123b6394f547a949ffb0c /include/linux
parentf5e96fdffc024552944776848bd5570e1b2caa9b (diff)
string: add strdup_const and kstrdup_const
Extend Linux compat by adding kstrdup_const(), backed by lib/string.c. This leverages U-Boots .rodata section on ARM64 to avoid pointlessly duplicating const strings. This is used by the Linux CCF_FULL port and may be useful elsewhere in U-Boot. Signed-off-by: Casey Connolly <[email protected]>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/compat.h13
-rw-r--r--include/linux/string.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 62381451617..d4ba4d0088a 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -67,6 +67,19 @@ static inline void vfree(const void *addr)
free((void *)addr);
}
+/**
+ * kstrdup_const - conditionally duplicate an existing const string
+ * @s: the string to duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ *
+ * Note: Strings allocated by kstrdup_const should be freed by kfree_const and
+ * must not be passed to krealloc().
+ *
+ * Return: source string if it is in .rodata section otherwise
+ * fallback to kstrdup.
+ */
+#define kstrdup_const(s, gfp) strdup_const(s)
+
struct kmem_cache { int sz; };
struct kmem_cache *get_mem(int element_sz);
diff --git a/include/linux/string.h b/include/linux/string.h
index d943fcce690..a8a6cf4af50 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -104,6 +104,8 @@ size_t strcspn(const char *s, const char *reject);
#ifndef __HAVE_ARCH_STRDUP
extern char * strdup(const char *);
extern char * strndup(const char *, size_t);
+extern const char *strdup_const(const char *s);
+extern void kfree_const(const void *x);
#endif
#ifndef __HAVE_ARCH_STRSWAB
extern char * strswab(const char *);