ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer()
PATCH 1/1 ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer()
Use kvzalloc() in __iommu_alloc_buffer() instead of open-coding it.
--- arch/arm/mm/dma-mapping.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
arch/arm/mm/dma-mapping.c +1 -4
@@ -1203,10 +1203,7 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,int i =0 ;int order_idx =0 ; -if (array_size <=PAGE_SIZE ) - pages =kzalloc (array_size,GFP_KERNEL ); -else - pages =vzalloc (array_size); + pages =kvzalloc (array_size,GFP_KERNEL );if (!pages)return NULL ;
Signature · 1 line
2.26.2
PATCH v2 1/1 ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer()
Use kvzalloc() in __iommu_alloc_buffer() instead of open-coding it. Size computation wrapped in array_size() macro to prevent potential integer overflows.
---
Changes in v2:
- array_size() added
arch/arm/mm/dma-mapping.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/arm/mm/dma-mapping.c +1 -5
@@ -1199,14 +1199,10 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, {struct page **pages;int count = size >>PAGE_SHIFT ; -int array_size = count *sizeof (struct page *);int i =0 ;int order_idx =0 ; -if (array_size <=PAGE_SIZE ) - pages =kzalloc (array_size,GFP_KERNEL ); -else - pages =vzalloc (array_size); + pages =kvzalloc (array_size (sizeof (*pages), count),GFP_KERNEL );if (!pages)return NULL ;
Signature · 1 line
2.26.2
Quoted 3 lines · Denis Efremov
Use
kvzalloc()in__iommu_alloc_buffer()instead of open-coding it. Size computation wrapped inarray_size()macro to prevent potential integer overflows.
FWIW I'm currently working on a much more thorough cleanup by way of removing this code entirely [1] ;)
Robin.
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/
Quoted 29 lines
Signed-off-by Denis Efremov <[email protected]>---
Changes in v2:
-array_size()addedarch/arm/mm/dma-mapping.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)arch/arm/mm/dma-mapping.c +1
-5@@ -1199,14 +1199,10 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, {struct page **pages;int count = size >>PAGE_SHIFT ; -int array_size = count *sizeof (struct page *);int i =0 ;int order_idx =0 ; -if (array_size <=PAGE_SIZE ) - pages =kzalloc (array_size,GFP_KERNEL ); -else - pages =vzalloc (array_size); + pages =kvzalloc (array_size (sizeof (*pages), count),GFP_KERNEL );if (!pages)return NULL ;