mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
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 <casey.connolly@linaro.org>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user