* [PATCH v2] lib: crypto: fix comments for count_leading_zeros()
@ 2026-03-12 16:11 Yury Norov
2026-03-12 16:17 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Yury Norov @ 2026-03-12 16:11 UTC (permalink / raw)
To: Yury Norov, Andy Shevchenko, Rasmus Villemoes, Eric Biggers,
Jason A. Donenfeld, Ard Biesheuvel
Cc: Yury Norov, linux-kernel, linux-crypto
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.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
v1: https://lore.kernel.org/all/20260310211021.95362-1-ynorov@nvidia.com/
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(-)
diff --git a/include/linux/count_zeros.h b/include/linux/count_zeros.h
index 5b8ff5ac660d..4e5680327ece 100644
--- a/include/linux/count_zeros.h
+++ b/include/linux/count_zeros.h
@@ -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
diff --git a/lib/crypto/mpi/longlong.h b/lib/crypto/mpi/longlong.h
index b6fa1d08fb55..a5ef41c8f85d 100644
--- a/lib/crypto/mpi/longlong.h
+++ b/lib/crypto/mpi/longlong.h
@@ -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,
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] lib: crypto: fix comments for count_leading_zeros()
2026-03-12 16:11 [PATCH v2] lib: crypto: fix comments for count_leading_zeros() Yury Norov
@ 2026-03-12 16:17 ` Andy Shevchenko
2026-03-12 16:34 ` Yury Norov
0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-03-12 16:17 UTC (permalink / raw)
To: Yury Norov
Cc: Yury Norov, Rasmus Villemoes, Eric Biggers, Jason A. Donenfeld,
Ard Biesheuvel, linux-kernel, linux-crypto
On Thu, Mar 12, 2026 at 12:11:32PM -0400, Yury Norov wrote:
> 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,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] lib: crypto: fix comments for count_leading_zeros()
2026-03-12 16:17 ` Andy Shevchenko
@ 2026-03-12 16:34 ` Yury Norov
2026-03-12 21:55 ` Eric Biggers
0 siblings, 1 reply; 4+ messages in thread
From: Yury Norov @ 2026-03-12 16:34 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Yury Norov, Rasmus Villemoes, Eric Biggers, Jason A. Donenfeld,
Ard Biesheuvel, linux-kernel, linux-crypto
On Thu, Mar 12, 2026 at 06:17:48PM +0200, Andy Shevchenko wrote:
> On Thu, Mar 12, 2026 at 12:11:32PM -0400, Yury Norov wrote:
> > 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,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Thanks, it worth!
Applied for testing in -next.
Thanks,
Yury
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] lib: crypto: fix comments for count_leading_zeros()
2026-03-12 16:34 ` Yury Norov
@ 2026-03-12 21:55 ` Eric Biggers
0 siblings, 0 replies; 4+ messages in thread
From: Eric Biggers @ 2026-03-12 21:55 UTC (permalink / raw)
To: Yury Norov
Cc: Andy Shevchenko, Yury Norov, Rasmus Villemoes, Jason A. Donenfeld,
Ard Biesheuvel, linux-kernel, linux-crypto
On Thu, Mar 12, 2026 at 12:34:39PM -0400, Yury Norov wrote:
> On Thu, Mar 12, 2026 at 06:17:48PM +0200, Andy Shevchenko wrote:
> > On Thu, Mar 12, 2026 at 12:11:32PM -0400, Yury Norov wrote:
> > > 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,
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Thanks, it worth!
>
> Applied for testing in -next.
>
> Thanks,
> Yury
Acked-by: Eric Biggers <ebiggers@kernel.org>
- Eric
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-12 21:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 16:11 [PATCH v2] lib: crypto: fix comments for count_leading_zeros() Yury Norov
2026-03-12 16:17 ` Andy Shevchenko
2026-03-12 16:34 ` Yury Norov
2026-03-12 21:55 ` Eric Biggers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox