Skip to content

add memdup_nul(), use it and memdup() in a few places

Rasmus Villemoes u-boot 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest9 patches 5 repliesIn review
  2. v18 patches 9 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9string: fix prototype of memdup()include/linux/string.h lib/string.c+4 -60 replies
2/9stdio: drop stdio_clonecommon/stdio.c include/stdio_dev.h+1 -180 replies
3/9lib/string.c: drop pointless __HAVE_ARCH_STRDUPinclude/linux/string.h lib/string.c+1 -40 replies
4/9lib/string.c: introduce memdup_nul() helperinclude/linux/string.h lib/string.c+28 -00 replies
5/9lib/string.c: implement strdup() and strndup() in terms of memdup_nul()lib/string.c+2 -283 replies
6/9lib/hashtable.c: use memdup_nul() in himport_rlib/hashtable.c+3 -40 replies
7/9common/cli.c: use memdup_nul() in run_command_list()common/cli.c+1 -30 replies
8/9drivers/core: use memdup() instead of malloc()+memcpy()drivers/core/acpi.c drivers/core/ofnode.c drivers/core/root.c+3 -60 replies
9/9test: lib: add test of memdup_nul()test/lib/string.c+34 -01 reply

Reviews trailers per patch

All 9 patches have a Reviewed-by or Acked-by.

PatchSimon Glass
1/9R-b
2/9R-b
3/9R-b
4/9R-b
5/9R-b
6/9R-b
7/9R-b
8/9R-b
9/9R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/9] add memdup_nul(), use it and memdup() in a few places

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.

v2: Fix grammar in commit msg, add Simon's R-B to patches 1-8, add test (new patch 9).

v1: https://lore.kernel.org/u-boot/[email protected]/

Rasmus Villemoes (9):
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()
test: lib: add test of memdup_nul()

 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 +++++++++++++++---------------------------
 test/lib/string.c      | 34 ++++++++++++++++++++++++++++
 10 files changed, 75 insertions(+), 67 deletions(-)
Signature · 1 line
2.53.0