aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <dumbbell@FreeBSD.org>2026-06-12 20:22:51 +0000
committerJean-Sébastien Pédron <dumbbell@FreeBSD.org>2026-06-20 10:36:04 +0000
commitc27779e0a9546e8b2bfde74b5c9cbf08bbed000e (patch)
tree260617d788e05236ce1e522896ec41a440bfe92a
parentaf187b20cdb00b89a39dfea1a8eef41ce5c134aa (diff)
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
-rw-r--r--sys/compat/linuxkpi/common/include/linux/string.h15
1 files 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)
{