linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer()
@ 2020-08-27 15:15 Denis Efremov
  2020-08-27 15:43 ` [PATCH v2] " Denis Efremov
  0 siblings, 1 reply; 3+ messages in thread
From: Denis Efremov @ 2020-08-27 15:15 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Andrew Morton, linux-kernel, Denis Efremov, Russell King

Use kvzalloc() in __iommu_alloc_buffer() instead of open-coding it.

Signed-off-by: Denis Efremov <efremov@linux.com>
---
 arch/arm/mm/dma-mapping.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 8a8949174b1c..9def10affa70 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -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;
 
-- 
2.26.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer()
  2020-08-27 15:15 [PATCH] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer() Denis Efremov
@ 2020-08-27 15:43 ` Denis Efremov
  2020-08-27 18:27   ` Robin Murphy
  0 siblings, 1 reply; 3+ messages in thread
From: Denis Efremov @ 2020-08-27 15:43 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Andrew Morton, linux-kernel, Denis Efremov, Russell King

Use kvzalloc() in __iommu_alloc_buffer() instead of open-coding it.
Size computation wrapped in array_size() macro to prevent potential
integer overflows.

Signed-off-by: Denis Efremov <efremov@linux.com>
---
Changes in v2:
 - array_size() added

 arch/arm/mm/dma-mapping.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 8a8949174b1c..c1f864ff7b84 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -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;
 
-- 
2.26.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer()
  2020-08-27 15:43 ` [PATCH v2] " Denis Efremov
@ 2020-08-27 18:27   ` Robin Murphy
  0 siblings, 0 replies; 3+ messages in thread
From: Robin Murphy @ 2020-08-27 18:27 UTC (permalink / raw)
  To: Denis Efremov, linux-arm-kernel; +Cc: Andrew Morton, linux-kernel, Russell King

On 2020-08-27 16:43, Denis Efremov wrote:
> Use kvzalloc() in __iommu_alloc_buffer() instead of open-coding it.
> Size computation wrapped in array_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/cover.1597931875.git.robin.murphy@arm.com/

> Signed-off-by: Denis Efremov <efremov@linux.com>
> ---
> Changes in v2:
>   - array_size() added
> 
>   arch/arm/mm/dma-mapping.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index 8a8949174b1c..c1f864ff7b84 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -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;
>   
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-27 18:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 15:15 [PATCH] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer() Denis Efremov
2020-08-27 15:43 ` [PATCH v2] " Denis Efremov
2020-08-27 18:27   ` Robin Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).