Re: [PATCH v2] mm: thp: Fix refcount leak in thpsize_create() error path

From: Lance Yang

Date: Mon Apr 13 2026 - 10:18:38 EST




On 2026/4/13 19:39, David Hildenbrand (Arm) wrote:
[...]
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 40cf59301c21..c8ffa188a198 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -726,10 +726,8 @@ static struct thpsize *thpsize_create(int order, struct kobject *parent)
ret = kobject_init_and_add(&thpsize->kobj, &thpsize_ktype, parent,
"hugepages-%lukB", size);
- if (ret) {
- kfree(thpsize);
+ if (ret)
goto err;
- }

kobject_init_and_add() indeed documents "If this function returns an
error, kobject_put() must be called".

As Andrew says, that's not what the "goto err" does.

Right. v1[1] should do the trick: just jump to err_put

- if (ret) {
- kfree(thpsize);
- goto err;
- }
-
+ if (ret)
+ goto err_put;

Hmm... not sure why this changed to "goto err"

[1] https://lore.kernel.org/linux-mm/20260411062152.2092967-1-lgs201920130244@xxxxxxxxx/#t