From patchwork Tue Jun 16 22:31:30 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: 11608735 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 9754C6A2 for ; Tue, 16 Jun 2020 22:33:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 64E51207E8 for ; Tue, 16 Jun 2020 22:33:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64E51207E8 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 B10646B0005; Tue, 16 Jun 2020 18:33:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AC2116B0006; Tue, 16 Jun 2020 18:33:33 -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 9FE856B0008; Tue, 16 Jun 2020 18:33:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id 855256B0005 for ; Tue, 16 Jun 2020 18:33:33 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 375A2181AC9B6 for ; Tue, 16 Jun 2020 22:33:33 +0000 (UTC) X-FDA: 76936527906.17.brain43_44121a526e02 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 1305E180D0180 for ; Tue, 16 Jun 2020 22:33:33 +0000 (UTC) X-Spam-Summary: 2,0,0,011c00c299a5edd8,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:3867:3868: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-64.100.201.201 62.2.2.100,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:25,LUA_SUMMARY:none X-HE-Tag: brain43_44121a526e02 X-Filterd-Recvd-Size: 3082 Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 16 Jun 2020 22:33:32 +0000 (UTC) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 2A5E3746552EF6D3B867; Wed, 17 Jun 2020 06:33:29 +0800 (CST) Received: from SWX921481.china.huawei.com (10.126.203.10) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Wed, 17 Jun 2020 06:33:19 +0800 From: Barry Song To: , CC: , , , Barry Song , "Roman Gushchin" Subject: [PATCH v2 1/2] mm: cma: fix the name of CMA areas Date: Wed, 17 Jun 2020 10:31:30 +1200 Message-ID: <20200616223131.33828-2-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200616223131.33828-1-song.bao.hua@hisilicon.com> References: <20200616223131.33828-1-song.bao.hua@hisilicon.com> MIME-Version: 1.0 X-Originating-IP: [10.126.203.10] X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 1305E180D0180 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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. Acked-by: Roman Gushchin Reviewed-by: Mike Kravetz Signed-off-by: Barry Song --- -v2: rebase to 5.8-rc1 add acked-by and reviewed-by 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];