The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8()
@ 2025-11-26 20:43 Armin Wolf
  2025-11-26 21:13 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Armin Wolf @ 2025-11-26 20:43 UTC (permalink / raw)
  To: andriy.shevchenko, hansg, ilpo.jarvinen; +Cc: platform-driver-x86, linux-kernel

After commit 25524b619029 ("fs/nls: Fix utf16 to utf8 conversion"),
the return values of utf8_to_utf32() and utf32_to_utf8() are
inconsistent when encountering an error: utf8_to_utf32() returns -1,
while utf32_to_utf8() returns errno codes. Fix this inconsistency
by modifying utf8_to_utf32() to return errno codes as well.

Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 fs/nls/nls_base.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
index d434c4463a8f..a5c3a9f1b8dc 100644
--- a/fs/nls/nls_base.c
+++ b/fs/nls/nls_base.c
@@ -67,19 +67,22 @@ int utf8_to_utf32(const u8 *s, int inlen, unicode_t *pu)
 			l &= t->lmask;
 			if (l < t->lval || l > UNICODE_MAX ||
 					(l & SURROGATE_MASK) == SURROGATE_PAIR)
-				return -1;
+				return -EILSEQ;
+
 			*pu = (unicode_t) l;
 			return nc;
 		}
 		if (inlen <= nc)
-			return -1;
+			return -EOVERFLOW;
+
 		s++;
 		c = (*s ^ 0x80) & 0xFF;
 		if (c & 0xC0)
-			return -1;
+			return -EILSEQ;
+
 		l = (l << 6) | c;
 	}
-	return -1;
+	return -EILSEQ;
 }
 EXPORT_SYMBOL(utf8_to_utf32);
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8()
  2025-11-26 20:43 [PATCH] fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8() Armin Wolf
@ 2025-11-26 21:13 ` Andy Shevchenko
  2025-11-26 21:14   ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2025-11-26 21:13 UTC (permalink / raw)
  To: Armin Wolf; +Cc: hansg, ilpo.jarvinen, platform-driver-x86, linux-kernel

On Wed, Nov 26, 2025 at 09:43:55PM +0100, Armin Wolf wrote:
> After commit 25524b619029 ("fs/nls: Fix utf16 to utf8 conversion"),
> the return values of utf8_to_utf32() and utf32_to_utf8() are
> inconsistent when encountering an error: utf8_to_utf32() returns -1,
> while utf32_to_utf8() returns errno codes. Fix this inconsistency
> by modifying utf8_to_utf32() to return errno codes as well.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

Thanks!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8()
  2025-11-26 21:13 ` Andy Shevchenko
@ 2025-11-26 21:14   ` Andy Shevchenko
  2025-11-26 22:47     ` Armin Wolf
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2025-11-26 21:14 UTC (permalink / raw)
  To: Armin Wolf; +Cc: hansg, ilpo.jarvinen, platform-driver-x86, linux-kernel

On Wed, Nov 26, 2025 at 11:13:50PM +0200, Andy Shevchenko wrote:
> On Wed, Nov 26, 2025 at 09:43:55PM +0100, Armin Wolf wrote:
> > After commit 25524b619029 ("fs/nls: Fix utf16 to utf8 conversion"),
> > the return values of utf8_to_utf32() and utf32_to_utf8() are
> > inconsistent when encountering an error: utf8_to_utf32() returns -1,
> > while utf32_to_utf8() returns errno codes. Fix this inconsistency
> > by modifying utf8_to_utf32() to return errno codes as well.
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> 
> Thanks!

Note, you might need a Fixes tag as the original one was marked as Fixes.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8()
  2025-11-26 21:14   ` Andy Shevchenko
@ 2025-11-26 22:47     ` Armin Wolf
  0 siblings, 0 replies; 4+ messages in thread
From: Armin Wolf @ 2025-11-26 22:47 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: hansg, ilpo.jarvinen, platform-driver-x86, linux-kernel

Am 26.11.25 um 22:14 schrieb Andy Shevchenko:

> On Wed, Nov 26, 2025 at 11:13:50PM +0200, Andy Shevchenko wrote:
>> On Wed, Nov 26, 2025 at 09:43:55PM +0100, Armin Wolf wrote:
>>> After commit 25524b619029 ("fs/nls: Fix utf16 to utf8 conversion"),
>>> the return values of utf8_to_utf32() and utf32_to_utf8() are
>>> inconsistent when encountering an error: utf8_to_utf32() returns -1,
>>> while utf32_to_utf8() returns errno codes. Fix this inconsistency
>>> by modifying utf8_to_utf32() to return errno codes as well.
>> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
>>
>> Thanks!
> Note, you might need a Fixes tag as the original one was marked as Fixes.
>
Alright, i will add it in the next patch revision.

Thanks,
Armin Wolf


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-26 22:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26 20:43 [PATCH] fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8() Armin Wolf
2025-11-26 21:13 ` Andy Shevchenko
2025-11-26 21:14   ` Andy Shevchenko
2025-11-26 22:47     ` Armin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox