bitmap: align bitmap_find_next_zero_area_off() output with the rest of the API
Subsystems (8)
cover bitmap: align bitmap_find_next_zero_area_off() output with the rest of the API
Bitmap search functions return a value greater than or equal to nbits when no suitable bits are found. bitmap_find_next_zero_area_off() is an
exception: it returns a value greater than nbits.
Align the function with the rest of the API and adjust the affected callers accordingly.
Patches 1-4 are sent only to their respective maintainers and mailing lists. Patch 5 and the cover letter are sent to all recipients.
On top of -next. I plan to carry the series with bitmap-for-next.
Yury Norov (5):
ARM: dma-mapping: Treat bitmap size as allocation failure powerpc/msi: Treat bitmap size as allocation failure
crypto: ccp: Treat bitmap size as allocation failure
media: s5p-mfc: Treat bitmap size as allocation failure
bitmap: Return size when no zero area is found
arch/arm/mm/dma-mapping.c | 4 ++-- arch/powerpc/sysdev/msi_bitmap.c | 2 +- drivers/crypto/ccp/ccp-dev-v3.c | 2 +- drivers/crypto/ccp/ccp-dev-v5.c | 6 +++--- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c | 2 +- include/linux/bitmap.h | 3 +++ lib/bitmap.c | 10 ++++------ 7 files changed, 15 insertions(+), 14 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/5 ARM: dma-mapping: Treat bitmap size as allocation failure
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.
--- arch/arm/mm/dma-mapping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mm/dma-mapping.c +2 -2
@@ -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 ; }
Signature · 1 line
2.53.0
Re: [PATCH 1/5] ARM: dma-mapping: Treat bitmap size as allocation failure
Quoted 5 lines · 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 <[email protected]>
Quoted 18 lines
--- arch/arm/mm/dma-mapping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm/mm/dma-mapping.c +1
-1@@ -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);
arch/arm/mm/dma-mapping.c static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping, · line 800
Quoted 8 lines
arch/arm/mm/dma-mapping.c +1
-1@@ -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
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
PATCH 2/5 powerpc/msi: Treat bitmap size as allocation failure
In reply to Yury Norovbitmap_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.
--- arch/powerpc/sysdev/msi_bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/msi_bitmap.c +1 -1
@@ -21,7 +21,7 @@ int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num) offset =bitmap_find_next_zero_area (bmp->bitmap, bmp->irq_count,0 , num, (1 << order) -1 ); -if (offset > bmp->irq_count) +if (offset >= bmp->irq_count) goto err;bitmap_set (bmp->bitmap, offset, num);
Signature · 1 line
2.53.0
Re: [PATCH 2/5] powerpc/msi: Treat bitmap size as allocation failure
Quoted 3 lines · 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.
Changes seems to fine.
When reviewing this, I did find the return value of bitmap_find_next_zero_area to be unsigned long, but we are casting it to int. Not as concern at this point this will be an issue when irq_count exceeds. May be a follow patch is needed to fix this I guess.
Maddy
Quoted 18 lines
Signed-off-by Yury Norov <[email protected]>--- arch/powerpc/sysdev/msi_bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/powerpc/sysdev/msi_bitmap.c +1
-1@@ -21,7 +21,7 @@ int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num) offset =bitmap_find_next_zero_area (bmp->bitmap, bmp->irq_count,0 , num, (1 << order) -1 ); -if (offset > bmp->irq_count) +if (offset >= bmp->irq_count) goto err;bitmap_set (bmp->bitmap, offset, num);
PATCH 3/5 crypto: ccp: Treat bitmap size as allocation failure
In reply to Yury Norovbitmap_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.
--- drivers/crypto/ccp/ccp-dev-v3.c | 2 +- drivers/crypto/ccp/ccp-dev-v5.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/ccp/ccp-dev-v3.c +1 -1
@@ -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);
drivers/crypto/ccp/ccp-dev-v5.c +3 -3
@@ -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);
Signature · 1 line
2.53.0
PATCH 4/5 media: s5p-mfc: Treat bitmap size as allocation failure
In reply to Yury Norovbitmap_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.
--- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c +1 -1
@@ -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);
Signature · 1 line
2.53.0
Re: [PATCH 4/5] media: s5p-mfc: Treat bitmap size as allocation failure
Quoted 5 lines · 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 <[email protected]>
Quoted 9 lines
--- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c +0
-0
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c int s5p_mfc_alloc_priv_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx, · line 49
Quoted 8 lines
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c +1
-1@@ -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
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
PATCH 5/5 bitmap: Return size when no zero area is found
In reply to Yury NorovReturn 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.
--- include/linux/bitmap.h | 3 +++ lib/bitmap.c | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/bitmap.h +3 -0
@@ -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,
lib/bitmap.c +4 -6
@@ -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);
Signature · 1 line
2.53.0
OK, adding in bitmap-for-next. Thanks everyone for review!
Thanks,
Yury
Quoted 30 lines · Yury Norov
Bitmap search functions return a value greater than or equal to nbits when no suitable bits are found.
bitmap_find_next_zero_area_off()is an
exception: it returns a value greater than nbits.Align the function with the rest of the API and adjust the affected callers accordingly.
Patches 1-4 are sent only to their respective maintainers and mailing lists. Patch 5 and the cover letter are sent to all recipients.
On top of -next. I plan to carry the series with bitmap-for-next.
Yury Norov (5):
ARM: dma-mapping: Treat bitmap size as allocation failure powerpc/msi: Treat bitmap size as allocation failure
crypto: ccp: Treat bitmap size as allocation failure
media: s5p-mfc: Treat bitmap size as allocation failure
bitmap: Return size when no zero area is foundarch/arm/mm/dma-mapping.c | 4 ++-- arch/powerpc/sysdev/msi_bitmap.c | 2 +- drivers/crypto/ccp/ccp-dev-v3.c | 2 +- drivers/crypto/ccp/ccp-dev-v5.c | 6 +++--- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c | 2 +- include/linux/bitmap.h | 3 +++ lib/bitmap.c | 10 ++++------ 7 files changed, 15 insertions(+), 14 deletions(-)Signature · 1 line
2.53.0