Commit 7b95e6ca authored by Liu Shixin's avatar Liu Shixin
Browse files

mm: kmemleak: add __find_and_remove_object()

mainline inclusion
from mainline-v6.7-rc1
commit 858a195b9330d0bd36f59e8652f693a1beb7da2f
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBE0E0

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=858a195b9330d0bd36f59e8652f693a1beb7da2f

--------------------------------

Add new __find_and_remove_object() without kmemleak_lock protect, it is in
preparation for the next patch.

Link: https://lkml.kernel.org/r/20231018102952.3339837-7-liushixin2@huawei.com


Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
Acked-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Patrick Wang <patrick.wang.shcn@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
parent c73813d6
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -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;