diff options
-rw-r--r-- | fs/cifs/cifs_unicode.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index 53cf2aabce8..71d5d0a5f6b 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c | |||
@@ -203,6 +203,27 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len, | |||
203 | int i; | 203 | int i; |
204 | wchar_t wchar_to; /* needed to quiet sparse */ | 204 | wchar_t wchar_to; /* needed to quiet sparse */ |
205 | 205 | ||
206 | /* special case for utf8 to handle no plane0 chars */ | ||
207 | if (!strcmp(codepage->charset, "utf8")) { | ||
208 | /* | ||
209 | * convert utf8 -> utf16, we assume we have enough space | ||
210 | * as caller should have assumed conversion does not overflow | ||
211 | * in destination len is length in wchar_t units (16bits) | ||
212 | */ | ||
213 | i = utf8s_to_utf16s(from, len, UTF16_LITTLE_ENDIAN, | ||
214 | (wchar_t *) to, len); | ||
215 | |||
216 | /* if success terminate and exit */ | ||
217 | if (i >= 0) | ||
218 | goto success; | ||
219 | /* | ||
220 | * if fails fall back to UCS encoding as this | ||
221 | * function should not return negative values | ||
222 | * currently can fail only if source contains | ||
223 | * invalid encoded characters | ||
224 | */ | ||
225 | } | ||
226 | |||
206 | for (i = 0; len && *from; i++, from += charlen, len -= charlen) { | 227 | for (i = 0; len && *from; i++, from += charlen, len -= charlen) { |
207 | charlen = codepage->char2uni(from, len, &wchar_to); | 228 | charlen = codepage->char2uni(from, len, &wchar_to); |
208 | if (charlen < 1) { | 229 | if (charlen < 1) { |
@@ -215,6 +236,7 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len, | |||
215 | put_unaligned_le16(wchar_to, &to[i]); | 236 | put_unaligned_le16(wchar_to, &to[i]); |
216 | } | 237 | } |
217 | 238 | ||
239 | success: | ||
218 | put_unaligned_le16(0, &to[i]); | 240 | put_unaligned_le16(0, &to[i]); |
219 | return i; | 241 | return i; |
220 | } | 242 | } |