From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B404C433E1 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 07774207D3 for ; Tue, 16 Jun 2020 22:33:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07774207D3 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) Received: by kanga.kvack.org (Postfix, from userid 40) id AC2116B0006; Tue, 16 Jun 2020 18:33:33 -0400 (EDT) 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-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-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 Content-Type: text/plain 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 Content-Transfer-Encoding: quoted-printable 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 =3D &cma_areas[cma_area_count]; - if (name) { - cma->name =3D name; - } else { - cma->name =3D 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 =3D PFN_DOWN(base); cma->count =3D size >> PAGE_SHIFT; cma->order_per_bit =3D 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__ =20 +#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]; }; =20 extern struct cma cma_areas[MAX_CMA_AREAS]; --=20 2.23.0