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

vfat: deduplicate hex2bin()

We may use hex2bin() instead of custom approach.

Link: http://lkml.kernel.org/r/87zibktpil.fsf@devron
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

OGAWA Hirofumi and committed by
Linus Torvalds
5680db4b b9fa2ad1

+12 -23
+12 -23
fs/fat/namei_vfat.c
··· 19 19 #include <linux/ctype.h> 20 20 #include <linux/slab.h> 21 21 #include <linux/namei.h> 22 + #include <linux/kernel.h> 23 + 22 24 #include "fat.h" 23 25 24 26 static inline unsigned long vfat_d_version(struct dentry *dentry) ··· 512 510 struct nls_table *nls) 513 511 { 514 512 const unsigned char *ip; 515 - unsigned char nc; 516 513 unsigned char *op; 517 - unsigned int ec; 518 - int i, k, fill; 514 + int i, fill; 519 515 int charlen; 520 516 521 517 if (utf8) { ··· 530 530 i < len && *outlen < FAT_LFN_LEN; 531 531 *outlen += 1) { 532 532 if (escape && (*ip == ':')) { 533 + u8 uc[2]; 534 + 533 535 if (i > len - 5) 534 536 return -EINVAL; 535 - ec = 0; 536 - for (k = 1; k < 5; k++) { 537 - nc = ip[k]; 538 - ec <<= 4; 539 - if (nc >= '0' && nc <= '9') { 540 - ec |= nc - '0'; 541 - continue; 542 - } 543 - if (nc >= 'a' && nc <= 'f') { 544 - ec |= nc - ('a' - 10); 545 - continue; 546 - } 547 - if (nc >= 'A' && nc <= 'F') { 548 - ec |= nc - ('A' - 10); 549 - continue; 550 - } 537 + 538 + if (hex2bin(uc, ip + 1, 2) < 0) 551 539 return -EINVAL; 552 - } 553 - *op++ = ec & 0xFF; 554 - *op++ = ec >> 8; 540 + 541 + *(wchar_t *)op = uc[0] << 8 | uc[1]; 542 + 543 + op += 2; 555 544 ip += 5; 556 545 i += 5; 557 546 } else { 558 547 charlen = nls->char2uni(ip, len - i, 559 - (wchar_t *)op); 548 + (wchar_t *)op); 560 549 if (charlen < 0) 561 550 return -EINVAL; 562 551 ip += charlen;