]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
string: fix prototype of memdup()
authorRasmus Villemoes <ravi@prevas.dk>
Tue, 21 Apr 2026 07:54:31 +0000 (09:54 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 12 May 2026 21:38:00 +0000 (15:38 -0600)
It doesn't make sense to restrict memdup() to only return char*
pointers, especially when it is already defined to accept void*. This
makes it uglier to use to e.g. duplicate a struct.

Make it return void*, just as kmemdup() does in the kernel (and which
our kmemdup() in fact also does).

While in here, make a small optimization: memcpy() is defined to
return the destination register, so we write this in a way that the
compiler may do a tail call.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
include/linux/string.h
lib/string.c

index d943fcce690c572c197d5e17309a406be8e30ae8..9e47fe01c165e5a52e6704eaec251ab6d0da2a2c 100644 (file)
@@ -142,7 +142,7 @@ void *memchr_inv(const void *, int, size_t);
  *     memory is available
  *
  */
-char *memdup(const void *src, size_t len);
+void *memdup(const void *src, size_t len);
 
 unsigned long ustrtoul(const char *cp, char **endp, unsigned int base);
 unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base);
index d56f88d4a847a43f7808ca85366faf9db2830bd7..c2813e0f8549ae05e489b2ef70fec50b90ac3b66 100644 (file)
@@ -667,17 +667,15 @@ void * memscan(void * addr, int c, size_t size)
 }
 #endif
 
-char *memdup(const void *src, size_t len)
+void *memdup(const void *src, size_t len)
 {
-       char *p;
+       void *p;
 
        p = malloc(len);
        if (!p)
                return NULL;
 
-       memcpy(p, src, len);
-
-       return p;
+       return memcpy(p, src, len);
 }
 
 #ifndef __HAVE_ARCH_STRNSTR