summaryrefslogtreecommitdiff
path: root/include/linux/log2.h
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@redhat.com>2017-02-20 12:24:00 -0500
committerJ. Bruce Fields <bfields@redhat.com>2017-02-20 17:20:05 -0500
commit60709c093ed39aadb0f09972ebbc96dc34eb372e (patch)
tree983681311986070971d3756d9f8e75868aa7bb9a /include/linux/log2.h
parent7323f0d2881bbd426ce6bc0a956ef9e739ffe767 (diff)
parent0839ffb83e44e5ff1843e932592525fc2bff23ff (diff)
nfsd: merge stable fix into main nfsd branch
Diffstat (limited to 'include/linux/log2.h')
-rw-r--r--include/linux/log2.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/include/linux/log2.h b/include/linux/log2.h
index fd7ff3d91e6a..ef3d4f67118c 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -203,6 +203,17 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
* ... and so on.
*/
-#define order_base_2(n) ilog2(roundup_pow_of_two(n))
+static inline __attribute_const__
+int __order_base_2(unsigned long n)
+{
+ return n > 1 ? ilog2(n - 1) + 1 : 0;
+}
+#define order_base_2(n) \
+( \
+ __builtin_constant_p(n) ? ( \
+ ((n) == 0 || (n) == 1) ? 0 : \
+ ilog2((n) - 1) + 1) : \
+ __order_base_2(n) \
+)
#endif /* _LINUX_LOG2_H */