On Thu, Jan 7, 2021 at 8:36 PM Miaohe Lin <linmia...@huawei.com> wrote: > > In hugetlb_sysfs_add_hstate(), we would do kobject_put() on hstate_kobjs > when failed to create sysfs group but forget to set hstate_kobjs to NULL. > Then in hugetlb_register_node() error path, we may free it again via > hugetlb_unregister_node(). > > Fixes: a3437870160c ("hugetlb: new sysfs interface") > Signed-off-by: Miaohe Lin <linmia...@huawei.com> > Cc: <sta...@vger.kernel.org> > --- > mm/hugetlb.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-)
Reviewed-by: Muchun Song <smuc...@gmail.com> > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index e249bffa0e75..91a2a2025a2c 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -2947,8 +2947,10 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, > struct kobject *parent, > return -ENOMEM; > > retval = sysfs_create_group(hstate_kobjs[hi], hstate_attr_group); > - if (retval) > + if (retval) { > kobject_put(hstate_kobjs[hi]); > + hstate_kobjs[hi] = NULL; > + } > > return retval; > } > -- > 2.19.1 >