summaryrefslogtreecommitdiff
path: root/include/linux/log2.h
diff options
context:
space:
mode:
authorJohn Garry <john.g.garry@oracle.com>2025-07-11 10:52:53 +0000
committerJens Axboe <axboe@kernel.dk>2025-07-17 06:01:16 -0600
commit6381061d82141909c382811978ccdd7566698bca (patch)
treee4b11307fdd1b8cee0878c16268862996f8e00bf /include/linux/log2.h
parentab17ead0e0ee8650cd1cf4e481b1ed0ee9731956 (diff)
downloadlinux-next-6381061d82141909c382811978ccdd7566698bca.tar.gz
linux-next-6381061d82141909c382811978ccdd7566698bca.zip
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 <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>
Diffstat (limited to 'include/linux/log2.h')
-rw-r--r--include/linux/log2.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/linux/log2.h b/include/linux/log2.h
index 1366cb688a6d..2eac3fc9303d 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -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 */