From patchwork Wed Jun 3 08:40:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Song Bao Hua (Barry Song)" X-Patchwork-Id: 11585321 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EFC08739 for ; Wed, 3 Jun 2020 08:42:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BD1F5206C3 for ; Wed, 3 Jun 2020 08:42:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD1F5206C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=hisilicon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EFB8180007; Wed, 3 Jun 2020 04:42:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EAC6B8E0006; Wed, 3 Jun 2020 04:42:13 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC2EB80007; Wed, 3 Jun 2020 04:42:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id C52468E0006 for ; Wed, 3 Jun 2020 04:42:13 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 81D8D824C742 for ; Wed, 3 Jun 2020 08:42:13 +0000 (UTC) X-FDA: 76887258546.28.end57_6aa9590efd634 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 6A0EB6D6E for ; Wed, 3 Jun 2020 08:42:13 +0000 (UTC) X-Spam-Summary: 2,0,0,14b417bab9de01ee,d41d8cd98f00b204,song.bao.hua@hisilicon.com,,RULES_HIT:41:355:379:541:582:800:960:973:988:989:1152:1260:1261:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3870:3874:4250:4321:5007:6261:8603:9036:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12555:12895:12986:13069:13311:13357:13894:14181:14394:14721:14819:21080:21451:21611:21627:21990:30012:30029:30054:30064,0,RBL:45.249.212.190:@hisilicon.com:.lbl8.mailshell.net-62.2.2.100 64.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:28,LUA_SUMMARY:none X-HE-Tag: end57_6aa9590efd634 X-Filterd-Recvd-Size: 2939 Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Jun 2020 08:42:12 +0000 (UTC) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 11FBF637D0B8783E79BB; Wed, 3 Jun 2020 16:42:09 +0800 (CST) Received: from SWX921481.china.huawei.com (10.126.202.66) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Wed, 3 Jun 2020 16:41:58 +0800 From: Barry Song To: , CC: , , , , Barry Song Subject: [PATCH 1/2] mm: cma: fix the name of CMA areas Date: Wed, 3 Jun 2020 20:40:24 +1200 Message-ID: <20200603084025.62740-2-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200603084025.62740-1-song.bao.hua@hisilicon.com> References: <20200603084025.62740-1-song.bao.hua@hisilicon.com> MIME-Version: 1.0 X-Originating-IP: [10.126.202.66] X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 6A0EB6D6E X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: if users give a name saved in stack, the current code will generate magic pointer. if users don't give a name(NULL), kasprintf() will always return NULL as we are at the early stage. that means cma_init_reserved_mem() will return -ENOMEM if users set name parameter as NULL. Cc: Roman Gushchin Signed-off-by: Barry Song Acked-by: Roman Gushchin Reviewed-by: Mike Kravetz --- mm/cma.c | 13 ++++++------- mm/cma.h | 4 +++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 0463ad2ce06b..b24151fa2101 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -202,13 +202,12 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, * subsystems (like slab allocator) are available. */ cma = &cma_areas[cma_area_count]; - if (name) { - cma->name = name; - } else { - cma->name = kasprintf(GFP_KERNEL, "cma%d\n", cma_area_count); - if (!cma->name) - return -ENOMEM; - } + + if (name) + snprintf(cma->name, CMA_MAX_NAME, name); + else + snprintf(cma->name, CMA_MAX_NAME, "cma%d\n", cma_area_count); + cma->base_pfn = PFN_DOWN(base); cma->count = size >> PAGE_SHIFT; cma->order_per_bit = order_per_bit; diff --git a/mm/cma.h b/mm/cma.h index 33c0b517733c..27d3f0e9f68f 100644 --- a/mm/cma.h +++ b/mm/cma.h @@ -2,6 +2,8 @@ #ifndef __MM_CMA_H__ #define __MM_CMA_H__ +#define CMA_MAX_NAME 64 + struct cma { unsigned long base_pfn; unsigned long count; @@ -12,7 +14,7 @@ struct cma { struct hlist_head mem_head; spinlock_t mem_head_lock; #endif - const char *name; + char name[CMA_MAX_NAME]; }; extern struct cma cma_areas[MAX_CMA_AREAS];