summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRandy Dunlap <rdunlap@infradead.org>2017-09-30 11:43:38 -0400
committerJonathan Corbet <corbet@lwn.net>2017-10-07 12:45:02 -0400
commita1c4d24e02d093efd84cbde417051d2e767fa8fa (patch)
tree7f64ec598a2ce0b9ef4b7656591f7b8bd6bdb4e8
parent13277782dd4bcef71341a1016bee1d09f8f95ae0 (diff)
linux/log2.h: fix kernel-doc notation
Fix <linux/log2.h> kernel-doc: - Add kernel-doc notation to some functions. - Fix kernel-doc notation in function parameters. Signed-off-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
-rw-r--r--include/linux/log2.h42
1 files changed, 23 insertions, 19 deletions
diff --git a/include/linux/log2.h b/include/linux/log2.h
index c373295f359f..41a1ae010993 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -37,19 +37,23 @@ int __ilog2_u64(u64 n)
37} 37}
38#endif 38#endif
39 39
40/* 40/**
41 * Determine whether some value is a power of two, where zero is 41 * is_power_of_2() - check if a value is a power of two
42 * @n: the value to check
43 *
44 * Determine whether some value is a power of two, where zero is
42 * *not* considered a power of two. 45 * *not* considered a power of two.
46 * Return: true if @n is a power of 2, otherwise false.
43 */ 47 */
44
45static inline __attribute__((const)) 48static inline __attribute__((const))
46bool is_power_of_2(unsigned long n) 49bool is_power_of_2(unsigned long n)
47{ 50{
48 return (n != 0 && ((n & (n - 1)) == 0)); 51 return (n != 0 && ((n & (n - 1)) == 0));
49} 52}
50 53
51/* 54/**
52 * round up to nearest power of two 55 * __roundup_pow_of_two() - round up to nearest power of two
56 * @n: value to round up
53 */ 57 */
54static inline __attribute__((const)) 58static inline __attribute__((const))
55unsigned long __roundup_pow_of_two(unsigned long n) 59unsigned long __roundup_pow_of_two(unsigned long n)
@@ -57,8 +61,9 @@ unsigned long __roundup_pow_of_two(unsigned long n)
57 return 1UL << fls_long(n - 1); 61 return 1UL << fls_long(n - 1);
58} 62}
59 63
60/* 64/**
61 * round down to nearest power of two 65 * __rounddown_pow_of_two() - round down to nearest power of two
66 * @n: value to round down
62 */ 67 */
63static inline __attribute__((const)) 68static inline __attribute__((const))
64unsigned long __rounddown_pow_of_two(unsigned long n) 69unsigned long __rounddown_pow_of_two(unsigned long n)
@@ -67,12 +72,12 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
67} 72}
68 73
69/** 74/**
70 * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value 75 * ilog2 - log base 2 of 32-bit or a 64-bit unsigned value
71 * @n - parameter 76 * @n: parameter
72 * 77 *
73 * constant-capable log of base 2 calculation 78 * constant-capable log of base 2 calculation
74 * - this can be used to initialise global variables from constant data, hence 79 * - this can be used to initialise global variables from constant data, hence
75 * the massive ternary operator construction 80 * the massive ternary operator construction
76 * 81 *
77 * selects the appropriately-sized optimised version depending on sizeof(n) 82 * selects the appropriately-sized optimised version depending on sizeof(n)
78 */ 83 */
@@ -150,7 +155,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
150 155
151/** 156/**
152 * roundup_pow_of_two - round the given value up to nearest power of two 157 * roundup_pow_of_two - round the given value up to nearest power of two
153 * @n - parameter 158 * @n: parameter
154 * 159 *
155 * round the given value up to the nearest power of two 160 * round the given value up to the nearest power of two
156 * - the result is undefined when n == 0 161 * - the result is undefined when n == 0
@@ -167,7 +172,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
167 172
168/** 173/**
169 * rounddown_pow_of_two - round the given value down to nearest power of two 174 * rounddown_pow_of_two - round the given value down to nearest power of two
170 * @n - parameter 175 * @n: parameter
171 * 176 *
172 * round the given value down to the nearest power of two 177 * round the given value down to the nearest power of two
173 * - the result is undefined when n == 0 178 * - the result is undefined when n == 0
@@ -180,6 +185,12 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
180 __rounddown_pow_of_two(n) \ 185 __rounddown_pow_of_two(n) \
181 ) 186 )
182 187
188static inline __attribute_const__
189int __order_base_2(unsigned long n)
190{
191 return n > 1 ? ilog2(n - 1) + 1 : 0;
192}
193
183/** 194/**
184 * order_base_2 - calculate the (rounded up) base 2 order of the argument 195 * order_base_2 - calculate the (rounded up) base 2 order of the argument
185 * @n: parameter 196 * @n: parameter
@@ -193,13 +204,6 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
193 * ob2(5) = 3 204 * ob2(5) = 3
194 * ... and so on. 205 * ... and so on.
195 */ 206 */
196
197static inline __attribute_const__
198int __order_base_2(unsigned long n)
199{
200 return n > 1 ? ilog2(n - 1) + 1 : 0;
201}
202
203#define order_base_2(n) \ 207#define order_base_2(n) \
204( \ 208( \
205 __builtin_constant_p(n) ? ( \ 209 __builtin_constant_p(n) ? ( \