* [PATCH 1/5] ARM: dma-mapping: 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 5:58 ` Marek Szyprowski
2026-07-09 2:03 ` [PATCH 4/5] media: s5p-mfc: " Yury Norov
2026-07-09 2:03 ` [PATCH 5/5] bitmap: Return size when no zero area is found Yury Norov
2 siblings, 1 reply; 6+ messages in thread
From: Yury Norov @ 2026-07-09 2:03 UTC (permalink / raw)
To: Russell King, Marek Szyprowski, Jason Gunthorpe, Danilo Krummrich,
Leon Romanovsky, Matthew Wilcox (Oracle), Douglas Anderson,
Kees Cook, linux-arm-kernel, linux-kernel
Cc: Yury Norov
bitmap_find_next_zero_area() uses an out-of-range return value to
indicate failure. Check for values greater than or equal to the bitmap
size so the caller does not depend on the exact failure sentinel.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
arch/arm/mm/dma-mapping.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index f9bc53b60f99..7761099dde9e 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -773,7 +773,7 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping,
start = bitmap_find_next_zero_area(mapping->bitmaps[i],
mapping->bits, 0, count, align);
- if (start > mapping->bits)
+ if (start >= mapping->bits)
continue;
bitmap_set(mapping->bitmaps[i], start, count);
@@ -794,7 +794,7 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping,
start = bitmap_find_next_zero_area(mapping->bitmaps[i],
mapping->bits, 0, count, align);
- if (start > mapping->bits) {
+ if (start >= mapping->bits) {
spin_unlock_irqrestore(&mapping->lock, flags);
return DMA_MAPPING_ERROR;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 1/5] ARM: dma-mapping: Treat bitmap size as allocation failure
2026-07-09 2:03 ` [PATCH 1/5] ARM: dma-mapping: Treat bitmap size as allocation failure Yury Norov
@ 2026-07-09 5:58 ` Marek Szyprowski
0 siblings, 0 replies; 6+ messages in thread
From: Marek Szyprowski @ 2026-07-09 5:58 UTC (permalink / raw)
To: Yury Norov, Russell King, Jason Gunthorpe, Danilo Krummrich,
Leon Romanovsky, Matthew Wilcox (Oracle), Douglas Anderson,
Kees Cook, linux-arm-kernel, linux-kernel
On 09.07.2026 04:03, Yury Norov wrote:
> bitmap_find_next_zero_area() uses an out-of-range return value to
> indicate failure. Check for values greater than or equal to the bitmap
> size so the caller does not depend on the exact failure sentinel.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
> arch/arm/mm/dma-mapping.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index f9bc53b60f99..7761099dde9e 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -773,7 +773,7 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping,
> start = bitmap_find_next_zero_area(mapping->bitmaps[i],
> mapping->bits, 0, count, align);
>
> - if (start > mapping->bits)
> + if (start >= mapping->bits)
> continue;
>
> bitmap_set(mapping->bitmaps[i], start, count);
> @@ -794,7 +794,7 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping,
> start = bitmap_find_next_zero_area(mapping->bitmaps[i],
> mapping->bits, 0, count, align);
>
> - if (start > mapping->bits) {
> + if (start >= mapping->bits) {
> spin_unlock_irqrestore(&mapping->lock, flags);
> return DMA_MAPPING_ERROR;
> }
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/5] media: s5p-mfc: 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 ` [PATCH 1/5] ARM: dma-mapping: Treat bitmap size as allocation failure Yury Norov
@ 2026-07-09 2:03 ` Yury Norov
2026-07-09 5:57 ` Marek Szyprowski
2026-07-09 2:03 ` [PATCH 5/5] bitmap: Return size when no zero area is found Yury Norov
2 siblings, 1 reply; 6+ messages in thread
From: Yury Norov @ 2026-07-09 2:03 UTC (permalink / raw)
To: Marek Szyprowski, Andrzej Hajda, Mauro Carvalho Chehab,
linux-arm-kernel, linux-media, linux-kernel
Cc: Yury Norov
bitmap_find_next_zero_area() uses an out-of-range return value to
indicate failure. Check for values greater than or equal to the bitmap
size so the caller does not depend on the exact failure sentinel.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c
index 5ba791fa3676..b25ad2a37196 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c
@@ -43,7 +43,7 @@ int s5p_mfc_alloc_priv_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx,
if (dev->mem_virt) {
start = bitmap_find_next_zero_area(dev->mem_bitmap, bits, 0, count, align);
- if (start > bits)
+ if (start >= bits)
goto no_mem;
bitmap_set(dev->mem_bitmap, start, count);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 4/5] media: s5p-mfc: Treat bitmap size as allocation failure
2026-07-09 2:03 ` [PATCH 4/5] media: s5p-mfc: " Yury Norov
@ 2026-07-09 5:57 ` Marek Szyprowski
0 siblings, 0 replies; 6+ messages in thread
From: Marek Szyprowski @ 2026-07-09 5:57 UTC (permalink / raw)
To: Yury Norov, Andrzej Hajda, Mauro Carvalho Chehab,
linux-arm-kernel, linux-media, linux-kernel
On 09.07.2026 04:03, Yury Norov wrote:
> bitmap_find_next_zero_area() uses an out-of-range return value to
> indicate failure. Check for values greater than or equal to the bitmap
> size so the caller does not depend on the exact failure sentinel.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
> drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c
> index 5ba791fa3676..b25ad2a37196 100644
> --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c
> +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c
> @@ -43,7 +43,7 @@ int s5p_mfc_alloc_priv_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx,
>
> if (dev->mem_virt) {
> start = bitmap_find_next_zero_area(dev->mem_bitmap, bits, 0, count, align);
> - if (start > bits)
> + if (start >= bits)
> goto no_mem;
>
> bitmap_set(dev->mem_bitmap, start, count);
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 6+ 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 1/5] ARM: dma-mapping: Treat bitmap size as allocation failure Yury Norov
2026-07-09 2:03 ` [PATCH 4/5] media: s5p-mfc: " Yury Norov
@ 2026-07-09 2:03 ` Yury Norov
2 siblings, 0 replies; 6+ 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] 6+ messages in thread