From patchwork Wed Oct 18 10:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13426729 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 F1062CDB47E for ; Wed, 18 Oct 2023 09:30:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A3A28D014D; Wed, 18 Oct 2023 05:30:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 000FB8D014C; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBBE18D014A; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) 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 A96228D014C for ; Wed, 18 Oct 2023 05:30:27 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 821731CBEAC for ; Wed, 18 Oct 2023 09:30:27 +0000 (UTC) X-FDA: 81358061694.22.307FFB8 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf02.hostedemail.com (Postfix) with ESMTP id 4B65D80013 for ; Wed, 18 Oct 2023 09:30:24 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697621425; 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=qu7uzGEbwAgsDRGmzt6Cx98gc/6f+dugQWs0XNrfOZI=; b=6xR7t/XJjR16W3WlyUG3AaOhDLV0+o2OXpddiYy5MbImnayAJVeBsA1GGErQeZ4DXp2RPZ aRliX+CoEKUilD+O5euANWyFKkQpFV45tylfkj1c4EQzbWjEra/fRCTP8bALeBFVPA7YOI sVwRgU01iZyAR8T+REansmxAocO5AeE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697621425; a=rsa-sha256; cv=none; b=PG08XTKyP3lpt+AQvBGLcWP/MpIb6YyYwUt8Bb1oJiP9en4GBTI9Y9mADYQvlNwNslkeQM 4yNz6ZIjwLouFFHMU+So8jO6MQyKeae5iwpAV/ze9tEP9IjO5NoKnofXePsu+6nLxs7H1g xnBjiOsZ07BIriqLcjI7fFt/g5YF0lE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S9QTW6l4szRt63; Wed, 18 Oct 2023 17:26:39 +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; Wed, 18 Oct 2023 17:30:19 +0800 From: Liu Shixin To: Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH v3 5/7] mm: kmemleak: use mem_pool_free() to free object Date: Wed, 18 Oct 2023 18:29:50 +0800 Message-ID: <20231018102952.3339837-6-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231018102952.3339837-1-liushixin2@huawei.com> References: <20231018102952.3339837-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Stat-Signature: d438z5wsbr4dpxiq9g67pwiu71p1gk3n X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4B65D80013 X-Rspam-User: X-HE-Tag: 1697621424-349813 X-HE-Meta: U2FsdGVkX1+ap+Nyy/CoYAjnINegqJxPLlwSVrMhUrC3/aFxGEyFa1drz0SJt95/71SLPWB49irsfnV8XANBWH45VIntooLD/ivMLnfjLN937vqYljJYWqCGFav6gz5ExE91quFRIc28HvPRNvVQbxMXFTCXjjqyR4oGqPYV8tVb5eM5xezdz6Kby6ujoKcmcnTQfUZb/+A6yileFrXLp3BaUhnTfX60Ywl9W70/3gcNdP/VBKVJMHSryofZoDZUVrsSSDxNrVGlWB5thF6Aw4DI6gKFTxk99xsq+I4aOB9m6abyDTLQQ5As6QJ//IQ2kMt9KEfWJiY9CaTbpm9kmBw+PTjKK1Apb8o8tuYhKiBN6Xd6OzlKsrRozLe2/Lu8QyeoUK6qPw2SR61Tf/inTp59I9EHfaNYhbr/+CUp1oRbcloX2vrGloPwY35S4Jt8f10fD13BsMeU7oAiTsVvIKNa4sKADaGagNPpvzQ1x6l5rFwdY/MGzegIm8XLC4eKK80FUFT4wxsS/3DtnWMdHFWUdqTf7K+s92YZywA2bZp5h0C9KV1R+iJCTcluW66ZATuEINoMcs/3fKmnb3eI825cEbbDD6r4E9IVqAU7Dt87aVxMmPQtXob3hY8jDnp3RC/QPXDpKYrZYH5twtlzd7dK8lzwznxuWihnK8j6zxB5LdHhCU2MXaZubQKpVulLgD//Nm0LUEvneaFKbQDg7pdfS3Hw0eiL6LC/qChhi15Wop/T1vxTOeayW+1gmc9g6Onact6UxN5W+t9ZjrejMwNhsly1RFynLQxN4OtlSG/25d9O2GwC/MtVFJ41yHomP4CaoK/5ovPkIxnSmI4/mrteK5gwNYB2kSd+TCH9RsUCJhaqvUMFj2kAYNLaj9NSu2zw3aLWwrZc70DPqu9Um301X7zJCn5/sJ/atKfgNIWqjtSY1oS0vk1Jd3UtZnZBxSfzCTkdIkkfYyWdBJO TwR2usUP KbcqRA/anvxY+NJX32GOIWjbEZbONbXnOGqACEh4N+9gXcIRe5gLYdhYcML0GaZdhm0YPcRMDJkwH9GbJHs+KHYfJ4BciHyK0gfAog3394CklVTgjkcSd12KEHKFxWd2gbJO2l8L3p/j9ZkJxuIDIeLKZK0KwbUueY95j8Xk0XRkukIAFQPQ3DzhNFopOCj5CW4Uqj7djnuZXG61dJ/VXbjqp0G9JwgzVoAZxI7xT8fps8XwHwYRhcSzJu+KfD00XZf9E6dCw0rAyMHY= 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 kmemleak object is allocated by mem_pool_alloc(), which could be from slab or mem_pool[], so it's not suitable using __kmem_cache_free() to free the object, use __mem_pool_free() instead. Fixes: 0647398a8c7b ("mm: kmemleak: simple memory allocation pool for kmemleak objects") Signed-off-by: Liu Shixin Reviewed-by: Catalin Marinas --- mm/kmemleak.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 064fc3695c6b..ea34986c02b4 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -668,8 +668,8 @@ static struct kmemleak_object * __alloc_object(gfp_t gfp) return object; } -static void __link_object(struct kmemleak_object *object, unsigned long ptr, - size_t size, int min_count, bool is_phys) +static int __link_object(struct kmemleak_object *object, unsigned long ptr, + size_t size, int min_count, bool is_phys) { struct kmemleak_object *parent; @@ -711,14 +711,15 @@ static void __link_object(struct kmemleak_object *object, unsigned long ptr, * be freed while the kmemleak_lock is held. */ dump_object_info(parent); - kmem_cache_free(object_cache, object); - return; + return -EEXIST; } } rb_link_node(&object->rb_node, rb_parent, link); rb_insert_color(&object->rb_node, is_phys ? &object_phys_tree_root : &object_tree_root); list_add_tail_rcu(&object->object_list, &object_list); + + return 0; } /* @@ -731,14 +732,17 @@ static void __create_object(unsigned long ptr, size_t size, { struct kmemleak_object *object; unsigned long flags; + int ret; object = __alloc_object(gfp); if (!object) return; raw_spin_lock_irqsave(&kmemleak_lock, flags); - __link_object(object, ptr, size, min_count, is_phys); + ret = __link_object(object, ptr, size, min_count, is_phys); raw_spin_unlock_irqrestore(&kmemleak_lock, flags); + if (ret) + mem_pool_free(object); } /* Create kmemleak object which allocated with virtual address. */