From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751697AbdGaSoh (ORCPT ); Mon, 31 Jul 2017 14:44:37 -0400 Received: from mail.parknet.co.jp ([210.171.160.6]:52318 "EHLO mail.parknet.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751607AbdGaSog (ORCPT ); Mon, 31 Jul 2017 14:44:36 -0400 From: OGAWA Hirofumi To: Andrew Morton Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, Joe Perches Subject: [PATCH v5] vfat: Deduplicate hex2bin() References: <20170731143349.84629-1-andriy.shevchenko@linux.intel.com> <877eyov49l.fsf@devron> Date: Tue, 01 Aug 2017 03:44:34 +0900 In-Reply-To: <877eyov49l.fsf@devron> (OGAWA Hirofumi's message of "Tue, 01 Aug 2017 03:40:38 +0900") Message-ID: <87zibktpil.fsf@devron> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We may use hex2bin() instead of custom approach. Signed-off-by: Andy Shevchenko Signed-off-by: OGAWA Hirofumi --- fs/fat/namei_vfat.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff -puN fs/fat/namei_vfat.c~fat-dont-use-custom-hex2bin fs/fat/namei_vfat.c --- linux/fs/fat/namei_vfat.c~fat-dont-use-custom-hex2bin 2017-01-07 09:52:14.981693213 +0900 +++ linux-hirofumi/fs/fat/namei_vfat.c 2017-01-07 09:52:14.982693219 +0900 @@ -19,6 +19,8 @@ #include #include #include +#include + #include "fat.h" static inline unsigned long vfat_d_version(struct dentry *dentry) @@ -510,10 +512,8 @@ xlate_to_uni(const unsigned char *name, struct nls_table *nls) { const unsigned char *ip; - unsigned char nc; unsigned char *op; - unsigned int ec; - int i, k, fill; + int i, fill; int charlen; if (utf8) { @@ -530,33 +530,22 @@ xlate_to_uni(const unsigned char *name, i < len && *outlen < FAT_LFN_LEN; *outlen += 1) { if (escape && (*ip == ':')) { + u8 uc[2]; + if (i > len - 5) return -EINVAL; - ec = 0; - for (k = 1; k < 5; k++) { - nc = ip[k]; - ec <<= 4; - if (nc >= '0' && nc <= '9') { - ec |= nc - '0'; - continue; - } - if (nc >= 'a' && nc <= 'f') { - ec |= nc - ('a' - 10); - continue; - } - if (nc >= 'A' && nc <= 'F') { - ec |= nc - ('A' - 10); - continue; - } + + if (hex2bin(uc, ip + 1, 2) < 0) return -EINVAL; - } - *op++ = ec & 0xFF; - *op++ = ec >> 8; + + *(wchar_t *)op = uc[0] << 8 | uc[1]; + + op += 2; ip += 5; i += 5; } else { charlen = nls->char2uni(ip, len - i, - (wchar_t *)op); + (wchar_t *)op); if (charlen < 0) return -EINVAL; ip += charlen; _ -- OGAWA Hirofumi