* [PATCH 3/5] crypto: ccp: Treat bitmap size as allocation failure
2026-07-09 2:03 [PATCH 0/5] bitmap: align bitmap_find_next_zero_area_off() output with the rest of the API Yury Norov
@ 2026-07-09 2:03 ` Yury Norov
2026-07-09 2:03 ` [PATCH 5/5] bitmap: Return size when no zero area is found Yury Norov
1 sibling, 0 replies; 3+ messages in thread
From: Yury Norov @ 2026-07-09 2:03 UTC (permalink / raw)
To: Tom Lendacky, John Allen, Herbert Xu, David S. Miller,
linux-crypto, linux-kernel
Cc: Yury Norov
bitmap_find_next_zero_area() uses an out-of-range return value to
indicate failure. Accept only offsets strictly below the bitmap size so
the callers do not depend on the exact failure sentinel.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/crypto/ccp/ccp-dev-v3.c | 2 +-
drivers/crypto/ccp/ccp-dev-v5.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/crypto/ccp/ccp-dev-v3.c b/drivers/crypto/ccp/ccp-dev-v3.c
index fe69053b2394..60a133e23e5f 100644
--- a/drivers/crypto/ccp/ccp-dev-v3.c
+++ b/drivers/crypto/ccp/ccp-dev-v3.c
@@ -28,7 +28,7 @@ static u32 ccp_alloc_ksb(struct ccp_cmd_queue *cmd_q, unsigned int count)
ccp->sb_count,
ccp->sb_start,
count, 0);
- if (start <= ccp->sb_count) {
+ if (start < ccp->sb_count) {
bitmap_set(ccp->sb, start, count);
mutex_unlock(&ccp->sb_mutex);
diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
index 7b73332d6aa1..e18ddb881bf5 100644
--- a/drivers/crypto/ccp/ccp-dev-v5.c
+++ b/drivers/crypto/ccp/ccp-dev-v5.c
@@ -25,6 +25,7 @@
static u32 ccp_lsb_alloc(struct ccp_cmd_queue *cmd_q, unsigned int count)
{
struct ccp_device *ccp;
+ unsigned int nbits = MAX_LSB_CNT * LSB_SIZE;
int start;
/* First look at the map for the queue */
@@ -43,11 +44,10 @@ static u32 ccp_lsb_alloc(struct ccp_cmd_queue *cmd_q, unsigned int count)
for (;;) {
mutex_lock(&ccp->sb_mutex);
- start = (u32)bitmap_find_next_zero_area(ccp->lsbmap,
- MAX_LSB_CNT * LSB_SIZE,
+ start = (u32)bitmap_find_next_zero_area(ccp->lsbmap, nbits,
0,
count, 0);
- if (start <= MAX_LSB_CNT * LSB_SIZE) {
+ if (start < nbits) {
bitmap_set(ccp->lsbmap, start, count);
mutex_unlock(&ccp->sb_mutex);
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 5/5] bitmap: Return size when no zero area is found
2026-07-09 2:03 [PATCH 0/5] bitmap: align bitmap_find_next_zero_area_off() output with the rest of the API Yury Norov
2026-07-09 2:03 ` [PATCH 3/5] crypto: ccp: Treat bitmap size as allocation failure Yury Norov
@ 2026-07-09 2:03 ` Yury Norov
1 sibling, 0 replies; 3+ messages in thread
From: Yury Norov @ 2026-07-09 2:03 UTC (permalink / raw)
To: Russell King, Christophe Leroy (CS GROUP), David S. Miller,
Matthew Wilcox (Oracle), Andrew Morton, Andrzej Hajda,
Danilo Krummrich, Douglas Anderson, Herbert Xu, Jason Gunthorpe,
John Allen, Kees Cook, Leon Romanovsky, Madhavan Srinivasan,
Marek Szyprowski, Mauro Carvalho Chehab, Michael Ellerman,
Nicholas Piggin, Rasmus Villemoes, Tom Lendacky, Yury Norov,
linux-arm-kernel, linux-crypto, linux-kernel, linux-media,
linuxppc-dev
Cc: Yury Norov, sunyi
Return the bitmap size, rather than size + 1, when
bitmap_find_next_zero_area_off() cannot find a suitable area. This
matches the conventional find_bit() failure sentinel and still lets
callers detect failure with an out-of-range check.
Document the public failure contract as a value greater than or equal
to the bitmap size, without requiring callers to depend on the exact
sentinel.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
include/linux/bitmap.h | 3 +++
lib/bitmap.c | 10 ++++------
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 8854acf77869..33f175a30304 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -209,6 +209,9 @@ unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
* The @align_mask should be one less than a power of 2; the effect is that
* the bit offset of all zero areas this function finds is multiples of that
* power of 2. A @align_mask of 0 means no alignment is required.
+ *
+ * Return: The bit offset of the found area or a value >= @size
+ * if no area is found.
*/
static __always_inline
unsigned long bitmap_find_next_zero_area(unsigned long *map,
diff --git a/lib/bitmap.c b/lib/bitmap.c
index b464d843f4eb..ed685127a107 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -424,6 +424,9 @@ EXPORT_SYMBOL(__bitmap_clear);
* The @align_mask should be one less than a power of 2; the effect is that
* the bit offset of all zero areas this function finds plus @align_offset
* is multiple of that power of 2.
+ *
+ * Return: The bit offset of the found area or a value greater than or equal
+ * to @size if no area is found.
*/
unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
unsigned long size,
@@ -448,12 +451,7 @@ unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
start = i;
}
- /*
- * Here, returning size + 1 is to maintain consistency
- * with the old version, where the return value is always
- * greater than size when no zero areas are found.
- */
- return size + 1;
+ return size;
}
EXPORT_SYMBOL(bitmap_find_next_zero_area_off);
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread