Skip to content

Commit 01088a6

Browse files
MiaoheLinakpm00
authored andcommitted
mm/hugetlb: fix sysfs group leak in hugetlb_unregister_node()
The sysfs group per_node_hstate_attr_group and hstate_demote_attr_group when h->demote_order != 0 are created in hugetlb_register_node(). But these sysfs groups are not removed when unregister the node, thus sysfs group is leaked. Using sysfs_remove_group() to fix this issue. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Miaohe Lin <[email protected]> Reviewed-by: Fengwei Yin <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Muchun Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 939de63 commit 01088a6

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

mm/hugetlb.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,12 +3850,18 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent,
38503850
}
38513851

38523852
if (h->demote_order) {
3853-
if (sysfs_create_group(hstate_kobjs[hi],
3854-
&hstate_demote_attr_group))
3853+
retval = sysfs_create_group(hstate_kobjs[hi],
3854+
&hstate_demote_attr_group);
3855+
if (retval) {
38553856
pr_warn("HugeTLB unable to create demote interfaces for %s\n", h->name);
3857+
sysfs_remove_group(hstate_kobjs[hi], hstate_attr_group);
3858+
kobject_put(hstate_kobjs[hi]);
3859+
hstate_kobjs[hi] = NULL;
3860+
return retval;
3861+
}
38563862
}
38573863

3858-
return retval;
3864+
return 0;
38593865
}
38603866

38613867
static void __init hugetlb_sysfs_init(void)
@@ -3941,10 +3947,15 @@ static void hugetlb_unregister_node(struct node *node)
39413947

39423948
for_each_hstate(h) {
39433949
int idx = hstate_index(h);
3944-
if (nhs->hstate_kobjs[idx]) {
3945-
kobject_put(nhs->hstate_kobjs[idx]);
3946-
nhs->hstate_kobjs[idx] = NULL;
3947-
}
3950+
struct kobject *hstate_kobj = nhs->hstate_kobjs[idx];
3951+
3952+
if (!hstate_kobj)
3953+
continue;
3954+
if (h->demote_order)
3955+
sysfs_remove_group(hstate_kobj, &hstate_demote_attr_group);
3956+
sysfs_remove_group(hstate_kobj, &per_node_hstate_attr_group);
3957+
kobject_put(hstate_kobj);
3958+
nhs->hstate_kobjs[idx] = NULL;
39483959
}
39493960

39503961
kobject_put(nhs->hugepages_kobj);

0 commit comments

Comments
 (0)