From: Denis Efremov <efremov@linux.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, Denis Efremov <efremov@linux.com>,
Russell King <linux@armlinux.org.uk>
Subject: [PATCH v2] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer()
Date: Thu, 27 Aug 2020 18:43:32 +0300 [thread overview]
Message-ID: <20200827154332.41571-1-efremov@linux.com> (raw)
In-Reply-To: <20200827151541.39662-1-efremov@linux.com>
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
WARNING: multiple messages have this Message-ID (diff)
From: Denis Efremov <efremov@linux.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Denis Efremov <efremov@linux.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Russell King <linux@armlinux.org.uk>
Subject: [PATCH v2] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer()
Date: Thu, 27 Aug 2020 18:43:32 +0300 [thread overview]
Message-ID: <20200827154332.41571-1-efremov@linux.com> (raw)
In-Reply-To: <20200827151541.39662-1-efremov@linux.com>
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
next prev parent reply other threads:[~2020-08-27 15:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 15:15 [PATCH] ARM/dma-mapping: use kvzalloc() in __iommu_alloc_buffer() Denis Efremov
2020-08-27 15:15 ` Denis Efremov
2020-08-27 15:43 ` Denis Efremov [this message]
2020-08-27 15:43 ` [PATCH v2] " Denis Efremov
2020-08-27 18:27 ` Robin Murphy
2020-08-27 18:27 ` Robin Murphy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200827154332.41571-1-efremov@linux.com \
--to=efremov@linux.com \
--cc=akpm@linux-foundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.