Skip to contentSkip to conversation

fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8()

PATCH In review Armin Wolf 2 participants 2 messages Nov 29, 2025 – Dec 1, 2025 x86 platform drivers

lore
Share & tools
lore

Armin Wolf

author
#0 lore raw

PATCH v2 1/1 fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8()

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.

Fixes 25524b619029 ("fs/nls: Fix utf16 to utf8 conversion")

---
Changes since v1:
- add Fixes and Reviewed-by tags

Note: This patch should be applied to the x86 platform drivers tree.

---
 fs/nls/nls_base.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
fs/nls/nls_base.c +7 -4
index d434c4463a8f..a5c3a9f1b8dc 100644
@@ -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);
 
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 8 lines · Armin Wolf

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.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8()

      commit: c36f9d7b2869a003a2f7d6ff2c6bac9e62fd7d68

--
i.