mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Liu Shixin <liushixin2@huawei.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Patrick Wang <patrick.wang.shcn@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	Liu Shixin <liushixin2@huawei.com>
Subject: [PATCH v3 5/7] mm: kmemleak: use mem_pool_free() to free object
Date: Wed, 18 Oct 2023 18:29:50 +0800	[thread overview]
Message-ID: <20231018102952.3339837-6-liushixin2@huawei.com> (raw)
In-Reply-To: <20231018102952.3339837-1-liushixin2@huawei.com>

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 <liushixin2@huawei.com>
---
 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. */
-- 
2.25.1


  parent reply	other threads:[~2023-10-18  9:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 10:29 [PATCH v3 0/7] Some bugfix about kmemleak Liu Shixin
2023-10-18 10:29 ` [PATCH v3 1/7] bootmem: use kmemleak_free_part_phys in put_page_bootmem Liu Shixin
2023-10-18 10:29 ` [PATCH v3 2/7] bootmem: use kmemleak_free_part_phys in free_bootmem_page Liu Shixin
2023-10-18 10:29 ` [PATCH v3 3/7] mm/kmemleak: fix print format of pointer in pr_debug() Liu Shixin
2023-10-18 10:29 ` [PATCH v3 4/7] mm: kmemleak: split __create_object into two functions Liu Shixin
2023-10-18 15:42   ` Catalin Marinas
2023-10-18 10:29 ` Liu Shixin [this message]
2023-10-18 15:48   ` [PATCH v3 5/7] mm: kmemleak: use mem_pool_free() to free object Catalin Marinas
2023-10-18 15:57     ` Catalin Marinas
2023-10-18 16:22       ` Andrew Morton
2023-10-18 16:34         ` Catalin Marinas
2023-10-18 10:29 ` [PATCH v3 6/7] mm: kmemleak: add __find_and_remove_object() Liu Shixin
2023-10-18 15:51   ` Catalin Marinas
2023-10-18 10:29 ` [PATCH v3 7/7] mm/kmemleak: fix partially freeing unknown object warning Liu Shixin
2023-10-18 16:39   ` Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231018102952.3339837-6-liushixin2@huawei.com \
    --to=liushixin2@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=patrick.wang.shcn@gmail.com \
    --cc=wangkefeng.wang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®