All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Andy Shevchenko <andy@kernel.org>
Cc: Kees Cook <kees@kernel.org>,
	Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
	llvm@lists.linux.dev, linux-efi@vger.kernel.org
Subject: Re: [PATCH RFC 2/2] wcslen() prototype in string.h
Date: Tue, 25 Mar 2025 17:33:03 -0700	[thread overview]
Message-ID: <20250326003303.GA2394@ax162> (raw)
In-Reply-To: <20250325214516.GA672870@ax162>

On Tue, Mar 25, 2025 at 02:45:21PM -0700, Nathan Chancellor wrote:
> Okay, sounds reasonable to me. This is what I ended up with for that
> change, which will become patch one of the series.
...
> 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;
> -- 
> 2.49.0
> 
> Then the first patch (which becomes the second) becomes:
> 
> 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 */

Good thing I waited :) This include makes s390 unhappy:

https://lore.kernel.org/202503260611.MDurOUhF-lkp@intel.com/

It is possible that should be fixed by adding -Wno-pointer-sign to
KBUILD_CFLAGS_DECOMPRESSOR so that arch/s390/boot matches the rest of
the kernel but...

> diff --git a/lib/string.c b/lib/string.c
> index eb4486ed40d2..1aa09925254b 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -21,6 +21,7 @@
>  #include <linux/errno.h>
>  #include <linux/limits.h>
>  #include <linux/linkage.h>
> +#include <linux/nls.h>
>  #include <linux/stddef.h>
>  #include <linux/string.h>
>  #include <linux/types.h>

I wonder if would be better to do something like the below patch in lieu
of the EFI change above (since there is no chance for a collision) then
change both of the includes for wchar_t in this diff to nls_types.h? I
have no strong opinion but this seems like it would be cleaner for the
sake of backports while not being a bad solution upstream?

Subject: [PATCH] include: Move typedefs in nls.h to their own header

In order to allow commonly included headers such as string.h to access
typedefs such as wchar_t without running into issues with the rest of
the NLS library, refactor the typedefs out into their own header that
can be included in a much safer manner.

Cc: stable@vger.kernel.org
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 include/linux/nls.h       | 19 +------------------
 include/linux/nls_types.h | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 18 deletions(-)
 create mode 100644 include/linux/nls_types.h

diff --git a/include/linux/nls.h b/include/linux/nls.h
index e0bf8367b274..3d416d1f60b6 100644
--- a/include/linux/nls.h
+++ b/include/linux/nls.h
@@ -3,24 +3,7 @@
 #define _LINUX_NLS_H
 
 #include <linux/init.h>
-
-/* Unicode has changed over the years.  Unicode code points no longer
- * fit into 16 bits; as of Unicode 5 valid code points range from 0
- * to 0x10ffff (17 planes, where each plane holds 65536 code points).
- *
- * The original decision to represent Unicode characters as 16-bit
- * wchar_t values is now outdated.  But plane 0 still includes the
- * most commonly used characters, so we will retain it.  The newer
- * 32-bit unicode_t type can be used when it is necessary to
- * represent the full Unicode character set.
- */
-
-/* Plane-0 Unicode character */
-typedef u16 wchar_t;
-#define MAX_WCHAR_T	0xffff
-
-/* Arbitrary Unicode character */
-typedef u32 unicode_t;
+#include <linux/nls_types.h>
 
 struct nls_table {
 	const char *charset;
diff --git a/include/linux/nls_types.h b/include/linux/nls_types.h
new file mode 100644
index 000000000000..8caefdba19b1
--- /dev/null
+++ b/include/linux/nls_types.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_NLS_TYPES_H
+#define _LINUX_NLS_TYPES_H
+
+#include <linux/types.h>
+
+/* Unicode has changed over the years.  Unicode code points no longer
+ * fit into 16 bits; as of Unicode 5 valid code points range from 0
+ * to 0x10ffff (17 planes, where each plane holds 65536 code points).
+ *
+ * The original decision to represent Unicode characters as 16-bit
+ * wchar_t values is now outdated.  But plane 0 still includes the
+ * most commonly used characters, so we will retain it.  The newer
+ * 32-bit unicode_t type can be used when it is necessary to
+ * represent the full Unicode character set.
+ */
+
+/* Plane-0 Unicode character */
+typedef u16 wchar_t;
+#define MAX_WCHAR_T	0xffff
+
+/* Arbitrary Unicode character */
+typedef u32 unicode_t;
+
+#endif /* _LINUX_NLS_TYPES_H */
-- 
2.49.0

diff --git a/include/linux/string.h b/include/linux/string.h
index 45e01cf3434c..4a48f8eac301 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -7,7 +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/nls_types.h>	/* for wchar_t */
 #include <linux/stddef.h>	/* for NULL */
 #include <linux/err.h>		/* for ERR_PTR() */
 #include <linux/errno.h>	/* for E2BIG */
diff --git a/lib/string.c b/lib/string.c
index 1aa09925254b..2c6f8c8f4159 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -21,7 +21,7 @@
 #include <linux/errno.h>
 #include <linux/limits.h>
 #include <linux/linkage.h>
-#include <linux/nls.h>
+#include <linux/nls_types.h>
 #include <linux/stddef.h>
 #include <linux/string.h>
 #include <linux/types.h>

  reply	other threads:[~2025-03-26  0:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-25 15:45 [PATCH 0/2] string.c: Add wcslen() Nathan Chancellor
2025-03-25 15:45 ` [PATCH 1/2] lib/string.c: " Nathan Chancellor
2025-03-25 15:45 ` [PATCH RFC 2/2] wcslen() prototype in string.h Nathan Chancellor
2025-03-25 16:17   ` Andy Shevchenko
2025-03-25 16:58     ` Nathan Chancellor
2025-03-25 17:05       ` Andy Shevchenko
2025-03-25 21:45         ` Nathan Chancellor
2025-03-26  0:33           ` Nathan Chancellor [this message]
2025-03-26  8:59             ` Andy Shevchenko
2025-03-26 15:37               ` Nathan Chancellor
2025-03-26 15:43                 ` Andy Shevchenko
2025-03-26  8:52           ` Andy Shevchenko
2025-03-25 23:55   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250326003303.GA2394@ax162 \
    --to=nathan@kernel.org \
    --cc=andy@kernel.org \
    --cc=ardb@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nick.desaulniers+lkml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.