From patchwork Sat Nov 12 11:20:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13041158 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7B91C4332F for ; Sat, 12 Nov 2022 10:33:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D8876B0071; Sat, 12 Nov 2022 05:33:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DC158E0002; Sat, 12 Nov 2022 05:33:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 519176B0074; Sat, 12 Nov 2022 05:33:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 394606B0071 for ; Sat, 12 Nov 2022 05:33:07 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 105C31A0E65 for ; Sat, 12 Nov 2022 10:33:07 +0000 (UTC) X-FDA: 80124427614.15.F99D7D8 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf08.hostedemail.com (Postfix) with ESMTP id F296B16000B for ; Sat, 12 Nov 2022 10:33:05 +0000 (UTC) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N8WzS6dx3zJndw; Sat, 12 Nov 2022 18:29:56 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 12 Nov 2022 18:33:01 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 12 Nov 2022 18:33:00 +0800 From: Liu Shixin To: Christoph Lameter , Pekka Enberg , "David Rientjes" , Joonsoo Kim , "Andrew Morton" , Vlastimil Babka , "Roman Gushchin" , Hyeonggon Yoo <42.hyeyoo@gmail.com> CC: , , Liu Shixin Subject: [PATCH v3 1/3] mm/slab_common: Move cache_name to create_cache() Date: Sat, 12 Nov 2022 19:20:53 +0800 Message-ID: <20221112112055.1111078-2-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221112112055.1111078-1-liushixin2@huawei.com> References: <20221112112055.1111078-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668249186; a=rsa-sha256; cv=none; b=sO+S0zCNvVsm3Pau+zyfUFJuHdZfhNBo9cvpmeP+rFdf8QgF0fxvILaQHX4LjTIiomFsvQ YqG03XpeBk0SDFNi8kXaysJSpCTgmjW/3h2asW7dKf2ks/CgHqVT5YSrl4gLZHgv+ANTKq ncodoaxO0aHtln4JY+3cJY4zyy5r6Rk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668249186; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=leyZkFm/H1Ug67EGoS9cgja/SPXbwRKk1/xB4yKJAtU=; b=1QHXse//9ClChXsr4/SvT+DQXAI9CMldyky0h4CBlsy3wLV+8ZURfmPXkLuqji+Bi0lIIM kpWdJ56fzbzKiwZaitBG4TcsFnAubdC0hk00hDzRuTFvfUhHa+umBC57Psdt2WQn86gge6 HB2J0lXZ3FhnWZq/k/MjTmFvFE0xy1g= Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=liushixin2@huawei.com X-Rspam-User: X-Stat-Signature: 57omy4z3o3z6pmsoon8njx61sdbu38ao X-Rspamd-Queue-Id: F296B16000B X-Rspamd-Server: rspam05 X-HE-Tag: 1668249185-918985 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: The string cache_name and its kmem_cache have same life cycle. The latter is allocated in create_cache() so move cache_name to create_cache() too for better error handing. Signed-off-by: Liu Shixin --- mm/slab_common.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 33b1886b06eb..e5f430a17d95 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -209,17 +209,21 @@ static struct kmem_cache *create_cache(const char *name, struct kmem_cache *root_cache) { struct kmem_cache *s; - int err; + const char *cache_name; + int err = -ENOMEM; if (WARN_ON(useroffset + usersize > object_size)) useroffset = usersize = 0; - err = -ENOMEM; s = kmem_cache_zalloc(kmem_cache, GFP_KERNEL); if (!s) - goto out; + return ERR_PTR(err); - s->name = name; + cache_name = kstrdup_const(name, GFP_KERNEL); + if (!cache_name) + goto out_free_cache; + + s->name = cache_name; s->size = s->object_size = object_size; s->align = align; s->ctor = ctor; @@ -228,18 +232,17 @@ static struct kmem_cache *create_cache(const char *name, err = __kmem_cache_create(s, flags); if (err) - goto out_free_cache; + goto out_free_name; s->refcount = 1; list_add(&s->list, &slab_caches); -out: - if (err) - return ERR_PTR(err); return s; +out_free_name: + kfree_const(s->name); out_free_cache: kmem_cache_free(kmem_cache, s); - goto out; + return ERR_PTR(err); } /** @@ -278,7 +281,6 @@ kmem_cache_create_usercopy(const char *name, void (*ctor)(void *)) { struct kmem_cache *s = NULL; - const char *cache_name; int err; #ifdef CONFIG_SLUB_DEBUG @@ -326,19 +328,11 @@ kmem_cache_create_usercopy(const char *name, if (s) goto out_unlock; - cache_name = kstrdup_const(name, GFP_KERNEL); - if (!cache_name) { - err = -ENOMEM; - goto out_unlock; - } - - s = create_cache(cache_name, size, + s = create_cache(name, size, calculate_alignment(flags, align, size), flags, useroffset, usersize, ctor, NULL); - if (IS_ERR(s)) { + if (IS_ERR(s)) err = PTR_ERR(s); - kfree_const(cache_name); - } out_unlock: mutex_unlock(&slab_mutex);