[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250325-string-add-wcslen-for-llvm-opt-v1-2-b8f1e2c17888@kernel.org>
Date: Tue, 25 Mar 2025 08:45:19 -0700
From: Nathan Chancellor <nathan@...nel.org>
To: Kees Cook <kees@...nel.org>
Cc: Andy Shevchenko <andy@...nel.org>,
Nick Desaulniers <nick.desaulniers+lkml@...il.com>,
Bill Wendling <morbo@...gle.com>, Justin Stitt <justinstitt@...gle.com>,
Ard Biesheuvel <ardb@...nel.org>, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org, llvm@...ts.linux.dev,
linux-efi@...r.kernel.org, Nathan Chancellor <nathan@...nel.org>
Subject: [PATCH RFC 2/2] wcslen() prototype in string.h
If this is desired, it should be squashed into the previous change. I
wrote it separately because it is slightly more invasive.
In order to export wcslen() to the rest of the kernel (should it ever be
necessary elsewhere), it needs to be added to string.h, along with nls.h
for the typedef of wchar_t. However, dragging in nls.h into string.h
causes an error in the efistub due to a conflicting function name:
drivers/firmware/efi/libstub/printk.c:27:5: error: static declaration of 'utf8_to_utf32' follows non-static declaration
27 | u32 utf8_to_utf32(const u8 **s8)
| ^
include/linux/nls.h:55:12: note: previous declaration is here
55 | extern int utf8_to_utf32(const u8 *s, int len, unicode_t *pu);
| ^
drivers/firmware/efi/libstub/printk.c:85:26: error: too few arguments to function call, expected 3, have 1
85 | c32 = utf8_to_utf32(&s8);
| ~~~~~~~~~~~~~ ^
include/linux/nls.h:55:12: note: 'utf8_to_utf32' declared here
55 | extern int utf8_to_utf32(const u8 *s, int len, unicode_t *pu);
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
Rename the efi function to avoid the conflict.
Signed-off-by: Nathan Chancellor <nathan@...nel.org>
---
drivers/firmware/efi/libstub/printk.c | 4 ++--
include/linux/string.h | 2 ++
lib/string.c | 1 -
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/firmware/efi/libstub/printk.c b/drivers/firmware/efi/libstub/printk.c
index 3a67a2cea7bd..334f7e89845c 100644
--- a/drivers/firmware/efi/libstub/printk.c
+++ b/drivers/firmware/efi/libstub/printk.c
@@ -24,7 +24,7 @@ void efi_char16_puts(efi_char16_t *str)
}
static
-u32 utf8_to_utf32(const u8 **s8)
+u32 efi_utf8_to_utf32(const u8 **s8)
{
u32 c32;
u8 c0, cx;
@@ -82,7 +82,7 @@ void efi_puts(const char *str)
while (*s8) {
if (*s8 == '\n')
buf[pos++] = L'\r';
- c32 = utf8_to_utf32(&s8);
+ c32 = efi_utf8_to_utf32(&s8);
if (c32 < 0x10000) {
/* Characters in plane 0 use a single word. */
buf[pos++] = c32;
diff --git a/include/linux/string.h b/include/linux/string.h
index 0403a4ca4c11..45e01cf3434c 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -7,6 +7,7 @@
#include <linux/cleanup.h> /* for DEFINE_FREE() */
#include <linux/compiler.h> /* for inline */
#include <linux/types.h> /* for size_t */
+#include <linux/nls.h> /* for wchar_t */
#include <linux/stddef.h> /* for NULL */
#include <linux/err.h> /* for ERR_PTR() */
#include <linux/errno.h> /* for E2BIG */
@@ -203,6 +204,7 @@ extern __kernel_size_t strlen(const char *);
#ifndef __HAVE_ARCH_STRNLEN
extern __kernel_size_t strnlen(const char *,__kernel_size_t);
#endif
+extern __kernel_size_t wcslen(const wchar_t *s);
#ifndef __HAVE_ARCH_STRPBRK
extern char * strpbrk(const char *,const char *);
#endif
diff --git a/lib/string.c b/lib/string.c
index bbee8a9e4d83..1aa09925254b 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -430,7 +430,6 @@ size_t strnlen(const char *s, size_t count)
EXPORT_SYMBOL(strnlen);
#endif
-size_t wcslen(const wchar_t *s);
size_t wcslen(const wchar_t *s)
{
const wchar_t *sc;
--
2.49.0
Powered by blists - more mailing lists