From patchwork Mon Oct 23 02:51:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13432252 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 0C206C07545 for ; Mon, 23 Oct 2023 01:52:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84FEF6B009B; Sun, 22 Oct 2023 21:52:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FF526B009C; Sun, 22 Oct 2023 21:52:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C7A56B009D; Sun, 22 Oct 2023 21:52:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5C1936B009B for ; Sun, 22 Oct 2023 21:52:03 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2EB88408F7 for ; Mon, 23 Oct 2023 01:52:03 +0000 (UTC) X-FDA: 81375050526.19.0C912BD Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf05.hostedemail.com (Postfix) with ESMTP id 04E2F100006 for ; Mon, 23 Oct 2023 01:51:59 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 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=1698025921; 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: references; bh=5SL2n/2tkdS4XyJzx4HQ8OO+bB4HcJR0PHkAoulFN5o=; b=oWT4gcmBflFCaB/B3ShoYKEdOV39iPozWDwaE1VZlMqVDAfvIJIFb0vqgO4K71ZDHtp71b +VHmbJJGHOQlJyARD9svP3FJM7k/LVKfiLceVW8cLFwkqCzv+/GmyeYoY5qaEZNloJAyvj i5ki5LMXGujIwMb/dykyArbHvOJQeWY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698025921; a=rsa-sha256; cv=none; b=tDOCaCeSTKBJAbiaOhClurZT5HyDS7xOoK8p6k6Xic6QDFj9KQ9AorncLMd58i1/xE1Gaf WvxCGRQDfeqOQKrNfElX5LI+9ZwoPRJchnPreQZqrbbq90IwBFmNuy1iXJwilthgxAiL4x 03g6Y5TH75EhzB4563XCkW+ouCkK400= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SDJ5G2fmzzrTMY; Mon, 23 Oct 2023 09:49:06 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 23 Oct 2023 09:51:55 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH -next] mm/kmemleak: move the initialisation of object to __link_object Date: Mon, 23 Oct 2023 10:51:25 +0800 Message-ID: <20231023025125.90972-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: 4pqnt9kpw67dns5nr137imf7cft31y3c X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 04E2F100006 X-HE-Tag: 1698025919-127516 X-HE-Meta: U2FsdGVkX1+itnvjZDsZLXMsz8qWOCyLG9BOy0N1dBUD+8mgmOXIQrpTPN5Kvoct+DsOX8Vg10q1rPoFC3qvXVS/mWtNXQUpb/dcseHZnHLNlGk5tRkmVQj7vmSuJSQ0u56ivjTsgPuXTQnCwSkrZsgWqLzjmm3uCSEZoy03WPg2WKDua4Ki2z+/58c9+I9YgchehV1fHjns1f+wsdGFwduuGinpw9ESeC1B769uG59q4SCf+31gNb2OzRGs7vurNhuro1lM910MOGj/RA3cYDIMj+D6LbQo+ahzXe4V5Rf901PFq8e25szXvxQyJtPbKy6cNPnveddReKnk8KnJRantkFlcljO7+n+Bi4i+8zA6M8En+KzNV23SvGVx2RWq4fTwZrbAUWQs4IfyRzoOKwNVa+0g3x4A+rAYPIqIrH4F9d2vT1GszqaW69PPH2cbqHKY5UCsksM5b9ZAKvqqhxvEWgZyBObuw2xuJ16qWTTJ7szEmQ8UsBffu1jPvEtTE8Psl6k3NL+v3Tjdr1Nas1YkaYKjOhZ/BsgQ0NgmSraRmmQZLOcZgbzOg+1hgzoMM0TbGAbIUyXR3BelMMWMV+HGFq7RUksFaAgN0U24L45sq2FdkLd7aW3lQikHnpsTXRZNLGQgO6BauoPYSfjaKhnIvTENOJwuqjJSFxOab2t1A44xXAENOGNAIKT4ob+dqpWIUJMm1EslWkAax1fhHHz493jWTYJX5YRUwjtTxAEIJFlpPK/hqCX4iePBi+1lysAumX2z9iLMA8V5T3BEC7B/pihTLtCEPprndJClO3vEU2eUbDnHXpVw+N1x3VaQGNpvF1Uc6h5njTJNL7MRahZxNcupvfIRURC1oCoThnXh9lN4e0S+MKa/oaEITWdRfWdYQFT/p0yIWKJc6JfyN3cqEMJL687T/SG4uGFxMYmJfgVLMZRRy7eJ2HR2bFcIlr659T4Wtjpk9RglvpY wCHBPTet 53NrG2CWYxgM6eyfBpCAZQzTiRQjeRnSfMwaCxZTtkLmye9tUhWFzBliRUW/j1twdAnN5nnDup9BhUcLdUOEJYplXhO4tEmYvm4gj9kfruF0+2K3Loo5t0kwnHPx/untiVfe1c8wuUeZlxL5fGJS+dmtWZRTdC9MvevyjOK8soeSACIO+4YsCY0Vi9gYjVZRuEhTP3oiYLLzlWGFRizdYq8HzaKnuMwhGFdJaYS0CG6P9li6DZwldDO64ft/C6VAEoGN2p9PGEx46xOUMifKHyvXdKGZAZ8N+B+s6fvEPd2CrJCmGcTYMXNVUozCzsNxbBdsVVZC0+/N9bugxKBrpyh3+JV20f9z0o9TexCkqvbSz+GYbo8CY4n7yCzp26VvY1X9iy0/of1JXTm5+8hrsuMTxSbcj9I3+/m1g 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: List-Subscribe: List-Unsubscribe: Leave __alloc_object() just do the actual allocation and __link_object() do the full initialisation. Suggested-by: Catalin Marinas Signed-off-by: Liu Shixin Reviewed-by: Catalin Marinas --- mm/kmemleak.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index a956b2734324..f51544a682de 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -642,16 +642,32 @@ static struct kmemleak_object * __alloc_object(gfp_t gfp) if (!object) { pr_warn("Cannot allocate a kmemleak_object structure\n"); kmemleak_disable(); - return NULL; } + return object; +} + +static int __link_object(struct kmemleak_object *object, unsigned long ptr, + size_t size, int min_count, bool is_phys) +{ + + struct kmemleak_object *parent; + struct rb_node **link, *rb_parent; + unsigned long untagged_ptr; + unsigned long untagged_objp; + INIT_LIST_HEAD(&object->object_list); INIT_LIST_HEAD(&object->gray_list); INIT_HLIST_HEAD(&object->area_list); raw_spin_lock_init(&object->lock); atomic_set(&object->use_count, 1); + object->flags = OBJECT_ALLOCATED | (is_phys ? OBJECT_PHYS : 0); + object->pointer = ptr; + object->size = kfence_ksize((void *)ptr) ?: size; object->excess_ref = 0; + object->min_count = min_count; object->count = 0; /* white color initially */ + object->jiffies = jiffies; object->checksum = 0; object->del_state = 0; @@ -676,24 +692,6 @@ static struct kmemleak_object * __alloc_object(gfp_t gfp) /* kernel backtrace */ object->trace_handle = set_track_prepare(); - return object; -} - -static int __link_object(struct kmemleak_object *object, unsigned long ptr, - size_t size, int min_count, bool is_phys) -{ - - struct kmemleak_object *parent; - struct rb_node **link, *rb_parent; - unsigned long untagged_ptr; - unsigned long untagged_objp; - - object->flags = OBJECT_ALLOCATED | (is_phys ? OBJECT_PHYS : 0); - object->pointer = ptr; - object->size = kfence_ksize((void *)ptr) ?: size; - object->min_count = min_count; - object->jiffies = jiffies; - untagged_ptr = (unsigned long)kasan_reset_tag((void *)ptr); /* * Only update min_addr and max_addr with object