]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ilog2: add max_pow_of_two_factor()
authorJohn Garry <john.g.garry@oracle.com>
Fri, 11 Jul 2025 10:52:53 +0000 (10:52 +0000)
committerJens Axboe <axboe@kernel.dk>
Thu, 17 Jul 2025 12:01:16 +0000 (06:01 -0600)
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 <john.g.garry@oracle.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20250711105258.3135198-2-john.g.garry@oracle.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/xfs/xfs_mount.c
include/linux/log2.h

index 29276fe60df9c6d21e3ad0a3de551c92a46ef239..6c669ae082d4d9939f2c98b600e38d52c09dcf5c 100644 (file)
@@ -672,11 +672,6 @@ static inline xfs_extlen_t xfs_calc_atomic_write_max(struct xfs_mount *mp)
        return rounddown_pow_of_two(XFS_B_TO_FSB(mp, MAX_RW_COUNT));
 }
 
-static inline unsigned int max_pow_of_two_factor(const unsigned int nr)
-{
-       return 1 << (ffs(nr) - 1);
-}
-
 /*
  * If the data device advertises atomic write support, limit the size of data
  * device atomic writes to the greatest power-of-two factor of the AG size so
index 1366cb688a6d91043affe8f47b995a2c88b2ba12..2eac3fc9303d6ab8b36f929316b8fc076b028676 100644 (file)
@@ -255,4 +255,18 @@ int __bits_per(unsigned long n)
        ) :                                     \
        __bits_per(n)                           \
 )
+
+/**
+ * max_pow_of_two_factor - return highest power-of-2 factor
+ * @n: parameter
+ *
+ * find highest power-of-2 which is evenly divisible into n.
+ * 0 is returned for n == 0 or 1.
+ */
+static inline __attribute__((const))
+unsigned int max_pow_of_two_factor(unsigned int n)
+{
+       return n & -n;
+}
+
 #endif /* _LINUX_LOG2_H */