From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4305299959; Sun, 12 Apr 2026 18:35:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776018926; cv=none; b=VvcJVzHOMHtVQWh0bQFUzhZDutyi6qYrCXANK2roVXV5bayVGHvWmT5t6NbCpWhIrDg3uHMCBImMzujs+KgSOmPNkYu5/rVc1Z+6jyNKt2l+bzWOgmxA0si4SJm9Ym62aHPKQCGAKO/3I0U6MogheiPdx2B0vAVzUSbJIL2CXyw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776018926; c=relaxed/simple; bh=So/3lxgYie/RFC6n3vqqdr/LETFNhsSstDNNMcIkf3Y=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=kNTR54/fJUtiDp1KGC/LrhrPuv7K98UkYIDUrgtZ/h7f2f20XMNgyN6TrEXzpcPsC0W2Pdod3TmEwwClxoGYGrrx/jJb9z579GJy8j4RItKnRryZA5ZhB6S3GV4XuI4wDqpjKbdR9/dZjiEnum9LYYEsf9Ph02IJ1o9KFe0wtu0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=H8c866ev; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="H8c866ev" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A684C19424; Sun, 12 Apr 2026 18:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1776018925; bh=So/3lxgYie/RFC6n3vqqdr/LETFNhsSstDNNMcIkf3Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=H8c866evefI92Se05d+uNHgaZ0YwhuRVksrZmupUBpRLIui9yH3GbIJ4hhcQu5nYr mPvFcAkyOhJSzNKEfb2lopgLsXI1BmMtU8sOHGQFmzRy39y2oXRUzU+uyQ1QKKtCJN tSg4Ux6bB0v29wmUwTQ/DP97TArKYuh8sW1f/6/k= Date: Sun, 12 Apr 2026 11:35:18 -0700 From: Andrew Morton To: Guangshuo Li Cc: David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] mm: thp: Fix refcount leak in thpsize_create() error path Message-Id: <20260412113518.af50cc58b0ac8635f7e9e086@linux-foundation.org> In-Reply-To: <20260412175428.2613383-1-lgs201920130244@gmail.com> References: <20260412175428.2613383-1-lgs201920130244@gmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 13 Apr 2026 01:54:28 +0800 Guangshuo Li wrote: > After kobject_init_and_add(), the lifetime of the embedded struct > kobject is expected to be managed through the kobject core reference > counting. > > In thpsize_create(), if kobject_init_and_add() fails, thpsize is freed > directly with kfree() rather than releasing the kobject reference with > kobject_put(). This may leave the reference count of the embedded struct > kobject unbalanced, resulting in a refcount leak. > > Fix this by using kobject_put(&thpsize->kobj) in the failure path and > letting thpsize_release() handle the final cleanup. OK... > > ... > > --- 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; So this should be goto err_put? > - } > > > ret = sysfs_add_group(&thpsize->kobj, &any_ctrl_attr_grp); > -- > 2.43.0