[PATCH 0/8] add memdup_nul(), use it and memdup() in a few places
Rasmus Villemoes
ravi at prevas.dk
Sun Apr 12 21:59:39 CEST 2026
There are quite a few places where we allocate X+1 bytes, initialize
the first X bytes via memcpy() and then set the last byte to 0.
The kernel has a helper for that, kmemdup_nul(). Introduce a similar
one, and start making use of it in a few places. Also the existing
memdup() helper can be put to more use.
There are lots more places one could modify. But for code shared with
host tools, one would need to do some refactoring, putting memdup()
and memdup_nul() in their own str-util.c TU which could then also be
included in the tools build.
Rasmus Villemoes (8):
string: fix prototype of memdup()
stdio: drop stdio_clone
lib/string.c: drop pointless __HAVE_ARCH_STRDUP
lib/string.c: introduce memdup_nul() helper
lib/string.c: implement strdup() and strndup() in terms of
memdup_nul()
lib/hashtable.c: use memdup_nul() in himport_r
common/cli.c: use memdup_nul() in run_command_list()
drivers/core: use memdup() instead of malloc()+memcpy()
common/cli.c | 4 +---
common/stdio.c | 18 +--------------
drivers/core/acpi.c | 3 +--
drivers/core/ofnode.c | 3 +--
drivers/core/root.c | 3 +--
include/linux/string.h | 18 ++++++++++++---
include/stdio_dev.h | 1 -
lib/hashtable.c | 7 +++---
lib/string.c | 51 +++++++++++++++---------------------------
9 files changed, 41 insertions(+), 67 deletions(-)
--
2.53.0
More information about the U-Boot
mailing list