From: Ran Xiaokai As documented in the comments for kobject_init_and_add(): "If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. This is the same type of error handling after a call to kobject_add() and kobject lifetime rules are the same here." This is because kobject_init_and_add() may have already allocated memory internally for the kobject name (kobj->name), and leaving the refcount at 1 prevents its release callback from being triggered. Fixes: 3485b88390b0a ("mm: thp: introduce multi-size THP sysfs interface") Signed-off-by: Ran Xiaokai --- mm/huge_memory.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 653f2dc03403..601750dbe79f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -790,11 +790,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); - goto err; - } - + if (ret) + goto err_put; ret = sysfs_add_group(&thpsize->kobj, &any_ctrl_attr_grp); if (ret) -- 2.25.1