git: c27779e0a954 - main - linuxkpi: Change `strscpy()` and `strscpy_pad()` to make their `len` argument optional
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 20 Jun 2026 11:53:59 UTC
The branch main has been updated by dumbbell:
URL: https://cgit.FreeBSD.org/src/commit/?id=c27779e0a9546e8b2bfde74b5c9cbf08bbed000e
commit c27779e0a9546e8b2bfde74b5c9cbf08bbed000e
Author: Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2026-06-12 20:22:51 +0000
Commit: Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2026-06-20 10:36:04 +0000
linuxkpi: Change `strscpy()` and `strscpy_pad()` to make their `len` argument optional
The previous implementation always took the `len` but now, it is
optional and defaults to the size of `dst`.
The DRM drivers started to use `strscpy()` without the `len` in Linux 6.13.
Reviewed by: emaste
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57585
---
sys/compat/linuxkpi/common/include/linux/string.h | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/sys/compat/linuxkpi/common/include/linux/string.h b/sys/compat/linuxkpi/common/include/linux/string.h
index b195dcc8fe9b..8a4da9e19c94 100644
--- a/sys/compat/linuxkpi/common/include/linux/string.h
+++ b/sys/compat/linuxkpi/common/include/linux/string.h
@@ -31,6 +31,7 @@
#include <sys/ctype.h>
+#include <linux/args.h>
#include <linux/array_size.h>
#include <linux/types.h>
#include <linux/gfp.h>
@@ -245,7 +246,7 @@ strreplace(char *str, char old, char new)
}
static inline ssize_t
-strscpy(char* dst, const char* src, size_t len)
+sized_strscpy(char* dst, const char* src, size_t len)
{
size_t i;
@@ -260,8 +261,13 @@ strscpy(char* dst, const char* src, size_t len)
return (-E2BIG);
}
+#define __strscpy0(dst, src, ...) sized_strscpy(dst, src, sizeof(dst))
+#define __strscpy1(dst, src, len) sized_strscpy(dst, src, len)
+#define strscpy(dst, src, ...) \
+ CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src, __VA_ARGS__)
+
static inline ssize_t
-strscpy_pad(char* dst, const char* src, size_t len)
+sized_strscpy_pad(char* dst, const char* src, size_t len)
{
bzero(dst, len);
@@ -269,6 +275,11 @@ strscpy_pad(char* dst, const char* src, size_t len)
return (strscpy(dst, src, len));
}
+#define __strscpy_pad0(dst, src, ...) sized_strscpy_pad(dst, src, sizeof(dst))
+#define __strscpy_pad1(dst, src, len) sized_strscpy_pad(dst, src, len)
+#define strscpy_pad(dst, src, ...) \
+ CONCATENATE(__strscpy_pad, COUNT_ARGS(__VA_ARGS__))(dst, src, __VA_ARGS__)
+
static inline char *
strnchr(const char *cp, size_t n, int ch)
{