Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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")
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://patch.msgid.link/20251129111535.8984-1-W_Armin@gmx.de
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Armin Wolf and committed by
Ilpo Järvinen
c36f9d7b 859d4cea

+7 -4
+7 -4
fs/nls/nls_base.c
··· 67 67 l &= t->lmask; 68 68 if (l < t->lval || l > UNICODE_MAX || 69 69 (l & SURROGATE_MASK) == SURROGATE_PAIR) 70 - return -1; 70 + return -EILSEQ; 71 + 71 72 *pu = (unicode_t) l; 72 73 return nc; 73 74 } 74 75 if (inlen <= nc) 75 - return -1; 76 + return -EOVERFLOW; 77 + 76 78 s++; 77 79 c = (*s ^ 0x80) & 0xFF; 78 80 if (c & 0xC0) 79 - return -1; 81 + return -EILSEQ; 82 + 80 83 l = (l << 6) | c; 81 84 } 82 - return -1; 85 + return -EILSEQ; 83 86 } 84 87 EXPORT_SYMBOL(utf8_to_utf32); 85 88