Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1000996ybs; Mon, 25 May 2020 04:53:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpwl1X74qMpwhlmdr2Df3DYF3VHCfAXSIZZIUtYzxV0l17ma2Dfor6Rjsi967wy+h+gLO2 X-Received: by 2002:a17:906:a415:: with SMTP id l21mr19209811ejz.100.1590407626077; Mon, 25 May 2020 04:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590407626; cv=none; d=google.com; s=arc-20160816; b=p5umdDmlAXif67+Lp2F2ax2E3SzvhH8VFCCnrgw2zPPNwAnTs9OV3On9WU+oFC7BOm w7u/y+1u6yQWsxPxJktOnkwe9/NgSMAhWt2MyFFF2/AHMOa6HK8jq7kQZE+3uCzKRSb/ +ujKBpbD6Q0jW3gIP/yMRuZnax68Q7/4dlw82gj+e9SQbZHBMJ/jy3n2HMBZo9JQQjg+ wcirtWgFNGxWqh4aGPricty0bahLiIldvJUaMjDZjcM2M7V71fidCRVKuDhh5oI9/H7N NbQztMZBeA0XctMimOwIlMVAQP6l4DKeaZrkPePXHxFZ1FfWCEobF22SGaCQMZH8D5gs RqNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JbNRen2/Tk695LLfZwS5txYYClAhgTrM7DAlNWvlVRw=; b=KmGfgGhmLjTifnfqW3ojHZrWm9FpGUdXHxQf2dn0ZITV6JIuNDDAwJx4pU8ikdRRFH 5aAGmACqN5V5uOG+upGcPLjLYasnwxUnFiAvE3z542rnl0aKv7BdgHTfx9ojxormW1x8 7FMmWqehHnUzS3Eyy8oSJl7YasEGtGIiXICGj1XKNk5iz+HaNS3JYAD2aj3IJaA1V4RV eaBmaoIwAnoae8PzIBSPu+DlbfnycgpYlkiJHzxuGk7cExlkWg64tADNDlAfcdZvsjPF O26WfFtHay1btb0PWLPFRPBzIkrPcEEEdC+lkvtatLY7hACmAwl8FJ4p622+ii5rFDel LBDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WfIjr0zA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si9685186edo.493.2020.05.25.04.53.23; Mon, 25 May 2020 04:53:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WfIjr0zA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390411AbgEYLvV (ORCPT + 99 others); Mon, 25 May 2020 07:51:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390401AbgEYLvT (ORCPT ); Mon, 25 May 2020 07:51:19 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F79AC061A0E; Mon, 25 May 2020 04:51:19 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id b190so8744811pfg.6; Mon, 25 May 2020 04:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JbNRen2/Tk695LLfZwS5txYYClAhgTrM7DAlNWvlVRw=; b=WfIjr0zAdwYGFfkOYct2uo06KaEt3yXAbzowOaYxPvJ3GOqyrv1KATzSSL/2G3eMfm QkO/BvqIdcMVKU+q5VAH/5py+wYM63pvo86CEI6UoPk3hyGKjv3EdEERJ6FjMCFOvd4k OocjIC2cuXE8WF9DV2Wobx0TqrGBdI85639ExBIr+hu6N646cNVWbk4gh6PoimTU2NZQ NeIpcsQY01hyFWs2XcuoGzp7s9RVsNIDMNGXFjVOgs/QtrZNv1SRFGMJNXIAJl0NLHe4 rkHJpOGj0B07IpTmQ86OTH87dLg7/KkAt9KclRZOCj0AlUrKYdCSVfQ86ieYfvd7/ght EUyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JbNRen2/Tk695LLfZwS5txYYClAhgTrM7DAlNWvlVRw=; b=YLuUG842/PSONBK9rNl0YNVJWqcshxlsMmI3EIz92ghMePj8QY8D8pDg+1pzOKyVR2 rbGgfDefpSeaB3fSkLUwV8MKRHJUxqt3guSBBCRCvW5LboMcoxzQXE1y0pT6pxZc8Two 8JCvvhDjMUP/Kv34qmRby0z4Wxo+fPNKLdyrXMtD8Q0f+dRtceWSr7lUQzyinsyjV92B Ou/mIBzwZOcYN5zvdyjQUN8//XR4kzLDWUnMmgJOAc8TUqxmUebKt4bIHViVeZFWvDeU m2fGqJ/rrRL/2bLms7L2+ExVLgXu8M0tcHZGh+ZZstKqPIVYa+aZ6jgsfhQT9iskoF+N UxPw== X-Gm-Message-State: AOAM5314DANqmX7WzYTgxTosz/DPBj/OfKJ6qJAgX+NA6FJMTsIQpkmd WLX6ZLUJQAJhSqlFM2SvOz4= X-Received: by 2002:a62:8c15:: with SMTP id m21mr16852203pfd.59.1590407478647; Mon, 25 May 2020 04:51:18 -0700 (PDT) Received: from dc803.flets-west.jp ([2404:7a87:83e0:f800:b9cb:9f91:3c10:565c]) by smtp.gmail.com with ESMTPSA id h16sm13017537pfq.56.2020.05.25.04.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 04:51:18 -0700 (PDT) From: Tetsuhiro Kohada To: kohada.t2@gmail.com Cc: kohada.tetsuhiro@dc.mitsubishielectric.co.jp, mori.takahiro@ab.mitsubishielectric.co.jp, motai.hirotaka@aj.mitsubishielectric.co.jp, Namjae Jeon , Sungjong Seo , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] exfat: standardize checksum calculation Date: Mon, 25 May 2020 20:50:51 +0900 Message-Id: <20200525115052.19243-4-kohada.t2@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200525115052.19243-1-kohada.t2@gmail.com> References: <20200525115052.19243-1-kohada.t2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To clarify that it is a 16-bit checksum, the parts related to the 16-bit checksum are renamed and change type to u16. Furthermore, replace checksum calculation in exfat_load_upcase_table() with exfat_calc_checksum32(). Signed-off-by: Tetsuhiro Kohada --- fs/exfat/dir.c | 12 ++++++------ fs/exfat/exfat_fs.h | 5 ++--- fs/exfat/misc.c | 10 ++++------ fs/exfat/nls.c | 19 +++++++------------ 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index b5a237c33d50..b673362a895c 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -496,7 +496,7 @@ int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, int ret = 0; int i, num_entries; sector_t sector; - unsigned short chksum; + u16 chksum; struct exfat_dentry *ep, *fep; struct buffer_head *fbh, *bh; @@ -505,7 +505,7 @@ int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, return -EIO; num_entries = fep->dentry.file.num_ext + 1; - chksum = exfat_calc_chksum_2byte(fep, DENTRY_SIZE, 0, CS_DIR_ENTRY); + chksum = exfat_calc_chksum16(fep, DENTRY_SIZE, 0, CS_DIR_ENTRY); for (i = 1; i < num_entries; i++) { ep = exfat_get_dentry(sb, p_dir, entry + i, &bh, NULL); @@ -513,7 +513,7 @@ int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, ret = -EIO; goto release_fbh; } - chksum = exfat_calc_chksum_2byte(ep, DENTRY_SIZE, chksum, + chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, chksum, CS_DEFAULT); brelse(bh); } @@ -600,10 +600,10 @@ int exfat_update_dir_chksum_with_entry_set(struct super_block *sb, int chksum_type = CS_DIR_ENTRY, i, num_entries = es->num_entries; unsigned int buf_off = (off - es->offset); unsigned int remaining_byte_in_sector, copy_entries, clu; - unsigned short chksum = 0; + u16 chksum = 0; for (i = 0; i < num_entries; i++) { - chksum = exfat_calc_chksum_2byte(&es->entries[i], DENTRY_SIZE, + chksum = exfat_calc_chksum16(&es->entries[i], DENTRY_SIZE, chksum, chksum_type); chksum_type = CS_DEFAULT; } @@ -1047,7 +1047,7 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, } if (entry_type == TYPE_STREAM) { - unsigned short name_hash; + u16 name_hash; if (step != DIRENT_STEP_STRM) { step = DIRENT_STEP_FILE; diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 15817281b3c8..993d13bbebec 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -139,7 +139,7 @@ struct exfat_dentry_namebuf { struct exfat_uni_name { /* +3 for null and for converting */ unsigned short name[MAX_NAME_LENGTH + 3]; - unsigned short name_hash; + u16 name_hash; unsigned char name_len; }; @@ -515,8 +515,7 @@ void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts, void exfat_truncate_atime(struct timespec64 *ts); void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts, u8 *tz, __le16 *time, __le16 *date, u8 *time_cs); -unsigned short exfat_calc_chksum_2byte(void *data, int len, - unsigned short chksum, int type); +u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type); u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type); void exfat_update_bh(struct super_block *sb, struct buffer_head *bh, int sync); void exfat_chain_set(struct exfat_chain *ec, unsigned int dir, diff --git a/fs/exfat/misc.c b/fs/exfat/misc.c index b82d2dd5bd7c..17d41f3d3709 100644 --- a/fs/exfat/misc.c +++ b/fs/exfat/misc.c @@ -136,17 +136,15 @@ void exfat_truncate_atime(struct timespec64 *ts) ts->tv_nsec = 0; } -unsigned short exfat_calc_chksum_2byte(void *data, int len, - unsigned short chksum, int type) +u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type) { int i; - unsigned char *c = (unsigned char *)data; + u8 *c = (u8 *)data; for (i = 0; i < len; i++, c++) { - if (((i == 2) || (i == 3)) && (type == CS_DIR_ENTRY)) + if (unlikely(type == CS_DIR_ENTRY && (i == 2 || i == 3))) continue; - chksum = (((chksum & 1) << 15) | ((chksum & 0xFFFE) >> 1)) + - (unsigned short)*c; + chksum = ((chksum << 15) | (chksum >> 1)) + *c; } return chksum; } diff --git a/fs/exfat/nls.c b/fs/exfat/nls.c index 1ebda90cbdd7..19321773dd07 100644 --- a/fs/exfat/nls.c +++ b/fs/exfat/nls.c @@ -527,7 +527,7 @@ static int exfat_utf8_to_utf16(struct super_block *sb, *uniname = '\0'; p_uniname->name_len = unilen; - p_uniname->name_hash = exfat_calc_chksum_2byte(upname, unilen << 1, 0, + p_uniname->name_hash = exfat_calc_chksum16(upname, unilen << 1, 0, CS_DEFAULT); if (p_lossy) @@ -623,7 +623,7 @@ static int exfat_nls_to_ucs2(struct super_block *sb, *uniname = '\0'; p_uniname->name_len = unilen; - p_uniname->name_hash = exfat_calc_chksum_2byte(upname, unilen << 1, 0, + p_uniname->name_hash = exfat_calc_chksum16(upname, unilen << 1, 0, CS_DEFAULT); if (p_lossy) @@ -655,7 +655,8 @@ static int exfat_load_upcase_table(struct super_block *sb, { struct exfat_sb_info *sbi = EXFAT_SB(sb); unsigned int sect_size = sb->s_blocksize; - unsigned int i, index = 0, checksum = 0; + unsigned int i, index = 0; + u32 chksum = 0; int ret; unsigned char skip = false; unsigned short *upcase_table; @@ -681,13 +682,6 @@ static int exfat_load_upcase_table(struct super_block *sb, for (i = 0; i < sect_size && index <= 0xFFFF; i += 2) { unsigned short uni = get_unaligned_le16(bh->b_data + i); - checksum = ((checksum & 1) ? 0x80000000 : 0) + - (checksum >> 1) + - *(((unsigned char *)bh->b_data) + i); - checksum = ((checksum & 1) ? 0x80000000 : 0) + - (checksum >> 1) + - *(((unsigned char *)bh->b_data) + (i + 1)); - if (skip) { index += uni; skip = false; @@ -701,13 +695,14 @@ static int exfat_load_upcase_table(struct super_block *sb, } } brelse(bh); + chksum = exfat_calc_chksum32(bh->b_data, i, chksum, CS_DEFAULT); } - if (index >= 0xFFFF && utbl_checksum == checksum) + if (index >= 0xFFFF && utbl_checksum == chksum) return 0; exfat_err(sb, "failed to load upcase table (idx : 0x%08x, chksum : 0x%08x, utbl_chksum : 0x%08x)", - index, checksum, utbl_checksum); + index, chksum, utbl_checksum); ret = -EINVAL; free_table: exfat_free_upcase_table(sbi); -- 2.25.1