Skip to content

Commit 245245c

Browse files
Liu Shixinakpm00
authored andcommitted
mm/kmemleak: move the initialisation of object to __link_object
In patch (mm: kmemleak: split __create_object into two functions), the initialisation of object has been splited in two places. Catalin said it feels a bit weird and error prone. So leave __alloc_object() to just do the actual allocation and let __link_object() do the full initialisation. Link: https://lkml.kernel.org/r/20231023025125.90972-1-liushixin2@huawei.com Signed-off-by: Liu Shixin <liushixin2@huawei.com> Suggested-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 5e4fc57 commit 245245c

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

mm/kmemleak.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -642,16 +642,32 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp)
642642
if (!object) {
643643
pr_warn("Cannot allocate a kmemleak_object structure\n");
644644
kmemleak_disable();
645-
return NULL;
646645
}
647646

647+
return object;
648+
}
649+
650+
static int __link_object(struct kmemleak_object *object, unsigned long ptr,
651+
size_t size, int min_count, bool is_phys)
652+
{
653+
654+
struct kmemleak_object *parent;
655+
struct rb_node **link, *rb_parent;
656+
unsigned long untagged_ptr;
657+
unsigned long untagged_objp;
658+
648659
INIT_LIST_HEAD(&object->object_list);
649660
INIT_LIST_HEAD(&object->gray_list);
650661
INIT_HLIST_HEAD(&object->area_list);
651662
raw_spin_lock_init(&object->lock);
652663
atomic_set(&object->use_count, 1);
664+
object->flags = OBJECT_ALLOCATED | (is_phys ? OBJECT_PHYS : 0);
665+
object->pointer = ptr;
666+
object->size = kfence_ksize((void *)ptr) ?: size;
653667
object->excess_ref = 0;
668+
object->min_count = min_count;
654669
object->count = 0; /* white color initially */
670+
object->jiffies = jiffies;
655671
object->checksum = 0;
656672
object->del_state = 0;
657673

@@ -676,24 +692,6 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp)
676692
/* kernel backtrace */
677693
object->trace_handle = set_track_prepare();
678694

679-
return object;
680-
}
681-
682-
static int __link_object(struct kmemleak_object *object, unsigned long ptr,
683-
size_t size, int min_count, bool is_phys)
684-
{
685-
686-
struct kmemleak_object *parent;
687-
struct rb_node **link, *rb_parent;
688-
unsigned long untagged_ptr;
689-
unsigned long untagged_objp;
690-
691-
object->flags = OBJECT_ALLOCATED | (is_phys ? OBJECT_PHYS : 0);
692-
object->pointer = ptr;
693-
object->size = kfence_ksize((void *)ptr) ?: size;
694-
object->min_count = min_count;
695-
object->jiffies = jiffies;
696-
697695
untagged_ptr = (unsigned long)kasan_reset_tag((void *)ptr);
698696
/*
699697
* Only update min_addr and max_addr with object

0 commit comments

Comments
 (0)