Skip to content

Commit fa535f7

Browse files
johnpgarrykawasaki
authored andcommitted
ilog2: add max_pow_of_two_factor()
Relocate the function max_pow_of_two_factor() to common ilog2.h from the xfs code, as it will be used elsewhere. Also simplify the function, as advised by Mikulas Patocka. Signed-off-by: John Garry <[email protected]>
1 parent ac8b12e commit fa535f7

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

fs/xfs/xfs_mount.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,6 @@ static inline xfs_extlen_t xfs_calc_atomic_write_max(struct xfs_mount *mp)
672672
return rounddown_pow_of_two(XFS_B_TO_FSB(mp, MAX_RW_COUNT));
673673
}
674674

675-
static inline unsigned int max_pow_of_two_factor(const unsigned int nr)
676-
{
677-
return 1 << (ffs(nr) - 1);
678-
}
679-
680675
/*
681676
* If the data device advertises atomic write support, limit the size of data
682677
* device atomic writes to the greatest power-of-two factor of the AG size so

include/linux/log2.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,18 @@ int __bits_per(unsigned long n)
255255
) : \
256256
__bits_per(n) \
257257
)
258+
259+
/**
260+
* max_pow_of_two_factor - return highest power-of-2 factor
261+
* @n: parameter
262+
*
263+
* find highest power-of-2 which is evenly divisible into n.
264+
* 0 is returned for n == 0 or 1.
265+
*/
266+
static inline __attribute__((const))
267+
unsigned int max_pow_of_two_factor(unsigned int n)
268+
{
269+
return n & -n;
270+
}
271+
258272
#endif /* _LINUX_LOG2_H */

0 commit comments

Comments
 (0)