Skip to contentSkip to conversation

mm/damon/core: initialize damon_target->list in damon_new_target()

PATCH Applied SeongJae Park 2 participants 2 messages Oct 2, 2022 – Oct 3, 2022

Subsystems (2)
lore
Share & tools
lore

SeongJae Park

author maintainer
#0 lore raw

PATCH 1/1 mm/damon/core: initialize damon_target->list in damon_new_target()

'struct damon_target' creation function, 'damon_new_target()' is not initializing its '->list' field, unlike other DAMON structs creator functions such as 'damon_new_region()'. Normal users of 'damon_new_target()' initializes the field by adding the target to DAMON context's targets list, but some code could access the uninitialized field.

This commit avoids the case by initializing the field in 'damon_new_target()'.

Fixes f23b8eee1871 ("mm/damon/core: implement region-based sampling")

---

 mm/damon/core.c | 1 +
 1 file changed, 1 insertion(+)
mm/damon/core.c +1 -0
index 1d952fa7ba3e..1e6691771a95 100644
@@ -345,6 +345,7 @@ struct damon_target *damon_new_target(void)
 	t->pid = NULL;
 	t->nr_regions = 0;
 	INIT_LIST_HEAD(&t->regions_list);
+	INIT_LIST_HEAD(&t->list);
 
 	return t;
 }
Signature · 1 line
2.25.1
Tested-by on v1 1/1
#1 lore raw
Quoted 23 lines · SeongJae Park

'struct damon_target' creation function, 'damon_new_target()' is not initializing its '->list' field, unlike other DAMON structs creator functions such as 'damon_new_region()'. Normal users of 'damon_new_target()' initializes the field by adding the target to DAMON context's targets list, but some code could access the uninitialized field.

This commit avoids the case by initializing the field in 'damon_new_target()'.

Fixes f23b8eee1871 ("mm/damon/core: implement region-based sampling")

---

 mm/damon/core.c | 1 +
 1 file changed, 1 insertion(+)
mm/damon/core.c +0 -0
index 1d952fa7ba3e..1e6691771a95 100644

mm/damon/core.c struct damon_target *damon_new_target(void) · line 351

Quoted 7 lines
mm/damon/core.c +1 -0
@@ -345,6 +345,7 @@ struct damon_target *damon_new_target(void)
 	t->pid = NULL;
 	t->nr_regions = 0;
 	INIT_LIST_HEAD(&t->regions_list);
+	INIT_LIST_HEAD(&t->list);
 
 	return t;
 }

I tried again with it and this fixes the bug I reported.

Thank you for such a quick fix!

Quoted 3 lines
Signature · 1 line
2.25.1
Signature · 2 lines
Thanks,
Hyeonggon