From: Barry Song <song.bao.hua@hisilicon.com>
To: <hch@lst.de>, <m.szyprowski@samsung.com>, <robin.murphy@arm.com>,
<will@kernel.org>, <ganapatrao.kulkarni@cavium.com>,
<catalin.marinas@arm.com>, <akpm@linux-foundation.org>
Cc: linuxarm@huawei.com, linux-kernel@vger.kernel.org,
iommu@lists.linux-foundation.org, prime.zeng@hisilicon.com,
huangdaode@huawei.com, Roman Gushchin <guro@fb.com>,
linux-arm-kernel@lists.infradead.org,
Mike Kravetz <mike.kravetz@oracle.com>
Subject: [PATCH v7 3/3] mm: cma: use CMA_MAX_NAME to define the length of cma name array
Date: Fri, 21 Aug 2020 23:33:55 +1200 [thread overview]
Message-ID: <20200821113355.6140-4-song.bao.hua@hisilicon.com> (raw)
In-Reply-To: <20200821113355.6140-1-song.bao.hua@hisilicon.com>
CMA_MAX_NAME should be visible to CMA's users as they might need it to set
the name of CMA areas and avoid hardcoding the size locally.
So this patch moves CMA_MAX_NAME from local header file to include/linux
header file and removes the magic number in hugetlb.c and contiguous.c.
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Roman Gushchin <guro@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
---
this patch is fixing the magic number issue with respect to Will's comment here:
https://lore.kernel.org/linux-iommu/4ab78767553f48a584217063f6f24eb9@hisilicon.com/
include/linux/cma.h | 2 ++
kernel/dma/contiguous.c | 2 +-
mm/cma.h | 2 --
mm/hugetlb.c | 4 ++--
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/linux/cma.h b/include/linux/cma.h
index 6ff79fefd01f..217999c8a762 100644
--- a/include/linux/cma.h
+++ b/include/linux/cma.h
@@ -18,6 +18,8 @@
#endif
+#define CMA_MAX_NAME 64
+
struct cma;
extern unsigned long totalcma_pages;
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 0383c9b86715..d2d6b715c274 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -119,7 +119,7 @@ void __init dma_pernuma_cma_reserve(void)
for_each_online_node(nid) {
int ret;
- char name[20];
+ char name[CMA_MAX_NAME];
struct cma **cma = &dma_contiguous_pernuma_area[nid];
snprintf(name, sizeof(name), "pernuma%d", nid);
diff --git a/mm/cma.h b/mm/cma.h
index 20f6e24bc477..42ae082cb067 100644
--- a/mm/cma.h
+++ b/mm/cma.h
@@ -4,8 +4,6 @@
#include <linux/debugfs.h>
-#define CMA_MAX_NAME 64
-
struct cma {
unsigned long base_pfn;
unsigned long count;
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index a301c2d672bf..9eec0ea9ba68 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5683,12 +5683,12 @@ void __init hugetlb_cma_reserve(int order)
reserved = 0;
for_each_node_state(nid, N_ONLINE) {
int res;
- char name[20];
+ char name[CMA_MAX_NAME];
size = min(per_node, hugetlb_cma_size - reserved);
size = round_up(size, PAGE_SIZE << order);
- snprintf(name, 20, "hugetlb%d", nid);
+ snprintf(name, sizeof(name), "hugetlb%d", nid);
res = cma_declare_contiguous_nid(0, size, 0, PAGE_SIZE << order,
0, false, name,
&hugetlb_cma[nid], nid);
--
2.27.0
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-08-21 11:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-21 11:33 [PATCH v7 0/3] make dma_alloc_coherent NUMA-aware by per-NUMA CMA Barry Song
2020-08-21 11:33 ` [PATCH v7 1/3] dma-contiguous: provide the ability to reserve per-numa CMA Barry Song
2020-08-21 14:28 ` Mike Rapoport
2020-08-21 19:14 ` Song Bao Hua (Barry Song)
2020-08-21 16:08 ` Randy Dunlap
2020-08-21 19:17 ` Song Bao Hua (Barry Song)
2020-08-21 11:33 ` [PATCH v7 2/3] arm64: mm: reserve per-numa CMA to localize coherent dma buffers Barry Song
2020-08-21 11:33 ` Barry Song [this message]
2020-08-21 17:52 ` [PATCH v7 0/3] make dma_alloc_coherent NUMA-aware by per-NUMA CMA Mike Kravetz
2020-08-21 19:29 ` Song Bao Hua (Barry Song)
2020-08-21 20:47 ` Song Bao Hua (Barry Song)
2020-08-21 21:10 ` Mike Kravetz
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=20200821113355.6140-4-song.bao.hua@hisilicon.com \
--to=song.bao.hua@hisilicon.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=ganapatrao.kulkarni@cavium.com \
--cc=guro@fb.com \
--cc=hch@lst.de \
--cc=huangdaode@huawei.com \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=m.szyprowski@samsung.com \
--cc=mike.kravetz@oracle.com \
--cc=prime.zeng@hisilicon.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/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 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).