From 775100031abe00e416585102deafc21e437866e7 Mon Sep 17 00:00:00 2001 From: David Timber Date: Sat, 5 Sep 2026 17:10:43 +0000 Subject: [PATCH] exfat: remove runtime integer division 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 Signed-off-by: Namjae Jeon --- 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 5acfe7ef57d6..5f258e96fce9 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 1cd778a2380b..d116c89d724e 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 c13852eb1cc5..4943cef97741 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);