From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 0BC03329C54 for ; Tue, 9 Jun 2026 14:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781014851; cv=none; b=RJTSHsKWBBXGgWgSHF9ZaQ9pvUp0Edsbsr77I27D0NOD5JlM28fHBAeXqzTCVY1V1l6RBBvJN8jjY+JXCCU6uqVJe+5VWioE9WTMDCrrS8M3jdeWzXwYpuCc/sMb6DP0RV8zOwVsKGQHYbJ91WlQYTjqUwOBgV1Ph2HDo9qYs8k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781014851; c=relaxed/simple; bh=3QNlItcjtpaI4Gpoc636mvViUswBxIS8xNoAKvC+FOc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=egSGj+P6n8jHucmwFTjfm/oQqYa/5v1GadeO/fzX5nthiJ1EYHT8sN5faDx8EtUohiWl5L2SYoPeVNEnzOgUaaMkkUqeyhhmvdEG/SbqJYhL/JXofkcTlk3v0o3T8Y4yOVpYg2I8axe6NBF5ToI4qJKfp+oYgIJx3+L0SPS4X/0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=flnRsIYE; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="flnRsIYE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FC891F00893; Tue, 9 Jun 2026 14:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781014849; bh=Mr28FJp+qSm7flFpPjHxz5ehcZCYEDaf60+LJYYJIlM=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=flnRsIYEt297kGasiVICyMjovbQkZuXa1e93qSqoj8rtO72Ul2/+OCht2TNKTGvQx clV47lt+1HdPFqFtVoYnhoY/LT4WAfFd4ny+KbAhComiD+WgPrjgFT0klkORkA5crA oFq10gZpLtekqZuWY0F7kKf20Sz14+udXOt9gCC2z+sbc2ztJ0NHBjvPs+bEVNhiOl 6feU5XnMBVkhSPjqPrn3CkP0VIWgFD6GxshUhr4elJngfhqMzWcmUIQA2hMkO/aObh 6CWXZJ6AFaMhJO9Woi8ft4fbXCgqehSVEL6YShghEmu62vVWATiImXlvI2FfQrj3dU //JhhRTsHDXlQ== Date: Tue, 9 Jun 2026 15:20:43 +0100 From: Lorenzo Stoakes To: Lance Yang Cc: ranxiaokai627@163.com, linux-mm@kvack.org, ziy@nvidia.com, dev.jain@arm.com, akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, baohua@kernel.org, "David Hildenbrand (Arm)" , linux-kernel@vger.kernel.org, npache@redhat.com, Ran Xiaokai , liam@infradead.org, ryan.roberts@arm.com Subject: Re: [PATCH] mm/huge_memory: fix memory leak when kobject_init_and_add() fails Message-ID: References: <20260609131249.89288-1-ranxiaokai627@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jun 09, 2026 at 10:04:16PM +0800, Lance Yang wrote: > > > On 2026/6/9 21:19, David Hildenbrand (Arm) wrote: > > On 6/9/26 15:12, ranxiaokai627@163.com wrote: > > > 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) > > > > This looks a lot like: > > > > https://lore.kernel.org/all/20260411062152.2092967-1-lgs201920130244@gmail.com/ > > Right, the same issue :) There is a v2: > > https://lore.kernel.org/linux-mm/20260412175428.2613383-1-lgs201920130244@gmail.com/ > > Still pending, though ... If people could use my actual correct email address it might not have been pending :) *grumble*