Skip to content

Commit 2e1d473

Browse files
Liu Shixinakpm00
authored andcommitted
mm: kmemleak: use mem_pool_free() to free object
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. Link: https://lkml.kernel.org/r/20231018102952.3339837-6-liushixin2@huawei.com Fixes: 0647398 ("mm: kmemleak: simple memory allocation pool for kmemleak objects") Signed-off-by: Liu Shixin <liushixin2@huawei.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: Patrick Wang <patrick.wang.shcn@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 0edd7b5 commit 2e1d473

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

mm/kmemleak.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,8 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp)
668668
return object;
669669
}
670670

671-
static void __link_object(struct kmemleak_object *object, unsigned long ptr,
672-
size_t size, int min_count, bool is_phys)
671+
static int __link_object(struct kmemleak_object *object, unsigned long ptr,
672+
size_t size, int min_count, bool is_phys)
673673
{
674674

675675
struct kmemleak_object *parent;
@@ -711,14 +711,15 @@ static void __link_object(struct kmemleak_object *object, unsigned long ptr,
711711
* be freed while the kmemleak_lock is held.
712712
*/
713713
dump_object_info(parent);
714-
kmem_cache_free(object_cache, object);
715-
return;
714+
return -EEXIST;
716715
}
717716
}
718717
rb_link_node(&object->rb_node, rb_parent, link);
719718
rb_insert_color(&object->rb_node, is_phys ? &object_phys_tree_root :
720719
&object_tree_root);
721720
list_add_tail_rcu(&object->object_list, &object_list);
721+
722+
return 0;
722723
}
723724

724725
/*
@@ -731,14 +732,17 @@ static void __create_object(unsigned long ptr, size_t size,
731732
{
732733
struct kmemleak_object *object;
733734
unsigned long flags;
735+
int ret;
734736

735737
object = __alloc_object(gfp);
736738
if (!object)
737739
return;
738740

739741
raw_spin_lock_irqsave(&kmemleak_lock, flags);
740-
__link_object(object, ptr, size, min_count, is_phys);
742+
ret = __link_object(object, ptr, size, min_count, is_phys);
741743
raw_spin_unlock_irqrestore(&kmemleak_lock, flags);
744+
if (ret)
745+
mem_pool_free(object);
742746
}
743747

744748
/* Create kmemleak object which allocated with virtual address. */

0 commit comments

Comments
 (0)