Skip to contentSkip to conversation

lib: crypto: fix comments for count_leading_zeros()

PATCH In review Yury Norov 3 participants 4 messages Mar 12

Subsystems (3)
lore
Share & tools
lore

Yury Norov

author
#0 lore raw

PATCH v2 1/1 lib: crypto: fix comments for count_leading_zeros()

count_leading_zeros() is based on fls(), which is defined for x == 0, contrary to ffs() family. The comment in crypto/mpi erroneously states that the function may return undef in such case.

Fix the comment together with the outdated function signature, and now that COUNT_LEADING_ZEROS_0 is not referenced in the codebase, get rid of it too.

---
v1: https://lore.kernel.org/all/[email protected]/
v2: cleanup trailing whitespaces, tweak comments (Andy)

 include/linux/count_zeros.h | 4 +---
 lib/crypto/mpi/longlong.h   | 8 ++++----
 2 files changed, 5 insertions(+), 7 deletions(-)
include/linux/count_zeros.h +1 -3
index 5b8ff5ac660d..4e5680327ece 100644
@@ -18,7 +18,7 @@
  *
  * If the MSB of @x is set, the result is 0.
  * If only the LSB of @x is set, then the result is BITS_PER_LONG-1.
- * If @x is 0 then the result is COUNT_LEADING_ZEROS_0.
+ * If @x is 0 then the result is BITS_PER_LONG.
  */
 static inline int count_leading_zeros(unsigned long x)
 {
@@ -28,8 +28,6 @@ static inline int count_leading_zeros(unsigned long x)
 		return BITS_PER_LONG - fls64(x);
 }
 
-#define COUNT_LEADING_ZEROS_0 BITS_PER_LONG
-
 /**
  * count_trailing_zeros - Count the number of zeros from the LSB forwards
  * @x: The value
lib/crypto/mpi/longlong.h +4 -4
index b6fa1d08fb55..a5ef41c8f85d 100644
@@ -66,12 +66,12 @@
  * denominator).  Like udiv_qrnnd but the numbers are signed.  The quotient
  * is rounded towards 0.
  *
- * 5) count_leading_zeros(count, x) counts the number of zero-bits from the
+ * 5) count_leading_zeros(x) counts the number of zero-bits from the
  * msb to the first non-zero bit in the UWtype X.  This is the number of
- * steps X needs to be shifted left to set the msb.  Undefined for X == 0,
- * unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
+ * steps X needs to be shifted left to set the msb.
+ * count_leading_zeros(0) == BITS_PER_LONG
  *
- * 6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
+ * 6) count_trailing_zeros() like count_leading_zeros(), but counts
  * from the least significant end.
  *
  * 7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Yury Norov

count_leading_zeros() is based on fls(), which is defined for x == 0, contrary to ffs() family. The comment in crypto/mpi erroneously states that the function may return undef in such case.

Fix the comment together with the outdated function signature, and now that COUNT_LEADING_ZEROS_0 is not referenced in the codebase, get rid of it too.

FWIW,

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Yury Norov

count_leading_zeros() is based on fls(), which is defined for x == 0, contrary to ffs() family. The comment in crypto/mpi erroneously states that the function may return undef in such case.

Fix the comment together with the outdated function signature, and now that COUNT_LEADING_ZEROS_0 is not referenced in the codebase, get rid of it too.

FWIW,

Thanks, it worth!

Applied for testing in -next.

Thanks,
Yury

maintainer Acked-by
#3 lore raw
Quoted 13 lines · Yury Norov
Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Yury Norov

count_leading_zeros() is based on fls(), which is defined for x == 0, contrary to ffs() family. The comment in crypto/mpi erroneously states that the function may return undef in such case.

Fix the comment together with the outdated function signature, and now that COUNT_LEADING_ZEROS_0 is not referenced in the codebase, get rid of it too.

FWIW,

Quoted 6 lines

Thanks, it worth!

Applied for testing in -next.

Thanks,
Yury

- Eric