[PATCH v3 6/7] mm: kmemleak: add __find_and_remove_object()

Liu Shixin posted 7 patches 2 years, 2 months ago
[PATCH v3 6/7] mm: kmemleak: add __find_and_remove_object()
Posted by Liu Shixin 2 years, 2 months ago
Add new __find_and_remove_object() without kmemleak_lock protect, it is
in preparation for the next patch.

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 mm/kmemleak.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index ea34986c02b4..7c9125c18956 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -583,6 +583,19 @@ static void __remove_object(struct kmemleak_object *object)
 	object->del_state |= DELSTATE_REMOVED;
 }
 
+static struct kmemleak_object *__find_and_remove_object(unsigned long ptr,
+							int alias,
+							bool is_phys)
+{
+	struct kmemleak_object *object;
+
+	object = __lookup_object(ptr, alias, is_phys);
+	if (object)
+		__remove_object(object);
+
+	return object;
+}
+
 /*
  * Look up an object in the object search tree and remove it from both
  * object_tree_root (or object_phys_tree_root) and object_list. The
@@ -596,9 +609,7 @@ static struct kmemleak_object *find_and_remove_object(unsigned long ptr, int ali
 	struct kmemleak_object *object;
 
 	raw_spin_lock_irqsave(&kmemleak_lock, flags);
-	object = __lookup_object(ptr, alias, is_phys);
-	if (object)
-		__remove_object(object);
+	object = __find_and_remove_object(ptr, alias, is_phys);
 	raw_spin_unlock_irqrestore(&kmemleak_lock, flags);
 
 	return object;
-- 
2.25.1
Re: [PATCH v3 6/7] mm: kmemleak: add __find_and_remove_object()
Posted by Catalin Marinas 2 years, 2 months ago
On Wed, Oct 18, 2023 at 06:29:51PM +0800, Liu Shixin wrote:
> Add new __find_and_remove_object() without kmemleak_lock protect, it is
> in preparation for the next patch.
> 
> Signed-off-by: Liu Shixin <liushixin2@huawei.com>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>