From: David Timber <dxdt@dev.snart.me>
To: Namjae Jeon <linkinjeon@kernel.org>,
Sungjong Seo <sj1557.seo@samsung.com>,
Yuezhang Mo <yuezhang.mo@sony.com>
Cc: exfat@lists.linux.dev, Hyunchul Lee <hyc.lee@gmail.com>,
linux-kernel@vger.kernel.org, David Timber <dxdt@dev.snart.me>
Subject: [PATCH v1 2/2] exfat: remove runtime integer division
Date: Sat, 5 Sep 2026 17:10:43 +0000 [thread overview]
Message-ID: <20260905171043.922793-3-dxdt@dev.snart.me> (raw)
In-Reply-To: <20260905171043.922793-1-dxdt@dev.snart.me>
Replace the arithmetic ops that compiles to the use of actual integer
division with bitwise ops. As the divisors involved are all power of
two, integer division is not necessary.
No functional change.
Signed-off-by: David Timber <dxdt@dev.snart.me>
---
fs/exfat/dir.c | 3 ++-
fs/exfat/exfat_fs.h | 1 +
fs/exfat/namei.c | 4 ++--
fs/exfat/super.c | 4 ++--
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index fa9abedf4d84..46514b13bebd 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -1309,7 +1309,8 @@ static int exfat_get_volume_label_dentry(struct super_block *sb,
es->bh = es->__bh;
es->bh[0] = bh;
es->num_bh = 1;
- es->start_off = exfat_dentries_to_bytes(i) % sb->s_blocksize;
+ es->start_off = exfat_dentries_to_bytes(i) &
+ ((u32)sb->s_blocksize - 1);
return 0;
}
diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
index a9131fe03302..41a2c7dfc479 100644
--- a/fs/exfat/exfat_fs.h
+++ b/fs/exfat/exfat_fs.h
@@ -232,6 +232,7 @@ struct exfat_sb_info {
unsigned int num_FAT_sectors; /* num of FAT sectors */
unsigned int root_dir; /* root dir cluster */
unsigned int dentries_per_clu; /* num of dentries per cluster */
+ unsigned int dentries_per_clu_bits;
unsigned int vol_flags; /* volume flags */
unsigned int vol_flags_persistent; /* volume flags to retain */
struct buffer_head *boot_bh; /* buffer_head of BOOT sector */
diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 80f60e80786e..3c5746fc57d9 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -386,7 +386,7 @@ int exfat_find_empty_entry(struct inode *inode,
}
p_dir->dir = exfat_sector_to_cluster(sbi, es->bh[0]->b_blocknr);
- p_dir->size -= dentry / sbi->dentries_per_clu;
+ p_dir->size -= dentry >> sbi->dentries_per_clu_bits;
return dentry & (sbi->dentries_per_clu - 1);
}
@@ -638,7 +638,7 @@ static int exfat_find(struct inode *dir, const struct qstr *qname,
/* adjust cdir to the optimized value */
cdir.dir = hint_opt.clu;
if (cdir.flags & ALLOC_NO_FAT_CHAIN)
- cdir.size -= dentry / sbi->dentries_per_clu;
+ cdir.size -= dentry >> sbi->dentries_per_clu_bits;
dentry = hint_opt.eidx;
info->dir = cdir;
diff --git a/fs/exfat/super.c b/fs/exfat/super.c
index 2409e57e7370..217d150652cf 100644
--- a/fs/exfat/super.c
+++ b/fs/exfat/super.c
@@ -519,8 +519,8 @@ static int exfat_read_boot_sector(struct super_block *sb)
EXFAT_RESERVED_CLUSTERS;
sbi->root_dir = le32_to_cpu(p_boot->root_cluster);
- sbi->dentries_per_clu = 1 <<
- (sbi->cluster_size_bits - DENTRY_SIZE_BITS);
+ sbi->dentries_per_clu_bits = sbi->cluster_size_bits - DENTRY_SIZE_BITS;
+ sbi->dentries_per_clu = 1 << sbi->dentries_per_clu_bits;
sbi->vol_flags = le16_to_cpu(p_boot->vol_flags);
sbi->vol_flags_persistent = sbi->vol_flags & (VOLUME_DIRTY | MEDIA_FAILURE);
--
2.55.0
next prev parent reply other threads:[~2026-09-05 17:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 17:10 [PATCH v1 0/2] exfat: update percent_in_use, " David Timber
2026-09-05 17:10 ` [PATCH v1 1/2] exfat: update percent_in_use field when updating volume flags David Timber
2026-09-05 17:10 ` David Timber [this message]
2026-09-07 14:42 ` [PATCH v1 0/2] exfat: update percent_in_use, remove runtime integer division Namjae Jeon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260905171043.922793-3-dxdt@dev.snart.me \
--to=dxdt@dev.snart.me \
--cc=exfat@lists.linux.dev \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sj1557.seo@samsung.com \
--cc=yuezhang.mo@sony.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®