Skip to content

Commit 81359c1

Browse files
jtlaytonbrauner
authored andcommitted
nilfs2: fix 64-bit division operations in nilfs_bmap_find_target_in_group()
With the change to make inode->i_ino a u64, the build started failing on 32-bit ARM with: ERROR: modpost: "__aeabi_uldivmod" [fs/nilfs2/nilfs2.ko] undefined! Fix this by using udiv_u64() for the division. For finding the index into the group, switch to using a bitwise & operation since that's more efficient. With this change however, NILFS_BMAP_GROUP_DIV must be a power of two, so add a compile-time assertion for that. Fixes: 998a59d ("treewide: fix missed i_ino format specifier conversions") Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202603100602.KPxiClIO-lkp@intel.com/ Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com> Acked-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://patch.msgid.link/20260316-iino-u64-v3-2-d1076b8f7a20@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent bef5b11 commit 81359c1

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

fs/nilfs2/bmap.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,18 +450,25 @@ __u64 nilfs_bmap_find_target_seq(const struct nilfs_bmap *bmap, __u64 key)
450450
return NILFS_BMAP_INVALID_PTR;
451451
}
452452

453-
#define NILFS_BMAP_GROUP_DIV 8
453+
#define NILFS_BMAP_GROUP_DIV 8 /* must be power of 2 */
454+
454455
__u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap)
455456
{
456457
struct inode *dat = nilfs_bmap_get_dat(bmap);
457458
unsigned long entries_per_group = nilfs_palloc_entries_per_group(dat);
458-
unsigned long group = bmap->b_inode->i_ino / entries_per_group;
459+
unsigned long group;
460+
u32 index;
461+
462+
BUILD_BUG_ON_NOT_POWER_OF_2(NILFS_BMAP_GROUP_DIV);
463+
464+
group = div_u64(bmap->b_inode->i_ino, entries_per_group);
465+
index = bmap->b_inode->i_ino & (NILFS_BMAP_GROUP_DIV - 1);
459466

460467
return group * entries_per_group +
461-
(bmap->b_inode->i_ino % NILFS_BMAP_GROUP_DIV) *
462-
(entries_per_group / NILFS_BMAP_GROUP_DIV);
468+
index * (entries_per_group / NILFS_BMAP_GROUP_DIV);
463469
}
464470

471+
465472
static struct lock_class_key nilfs_bmap_dat_lock_key;
466473
static struct lock_class_key nilfs_bmap_mdt_lock_key;
467474

0 commit comments

Comments
 (0)