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 8944B1F936 for ; Wed, 10 Jun 2026 00:28:56 +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=1781051337; cv=none; b=vDaXlUtXqPKI9buHGyMrAV+R+K5nk6O0OGmbL53vyDeWQzt5GnB/uPiUUHwN8j7DkSltc6GdaJpBMU37Jy2sgh2rFeSYJNEJST2ws/TkFd+iBqCSpsXIq8XnhtwoNdh7nhuuFE/HPZVZAy/56T402qEiO49NMPQAP7+gk+EVCPs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781051337; c=relaxed/simple; bh=q/+S9dXU6ZkmZ9sAbtbMhvWJ5NUKt14zlQ0+AqkhyJc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d8VMT0H8mspCY5YnfHM/CFkhzbAZDWguv17oRdcOqKdbdcKY1clw+fslYAXZNH3Ir8qOQNesklyJkbYmFCZkS932Ff42hezS6Tt3mfABy1PnbyPEIApUtPYvVFhR2x1ADXJ+jkOn2XswJU4uWOe5wvuKUqN7N87QKGuewt1drWo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j7FsShf2; 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="j7FsShf2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 438871F00893; Wed, 10 Jun 2026 00:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781051336; bh=4E4UY4FfWUNC2nK0Dr4oLj0xnMk5zECoJncsDnalNtw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j7FsShf2j4vEawnYKBXki4gjQLNiBbfrl7pW8mNu/dcG6VuRCm/D1a/aa6lA/ESkI QVzgWuKLiwkKfkYaAoXAKTOAmg7eWokZ5sFGN/CFiDYoeQyIxDFa3Y6Erqa1le2QXO 26eVOIETmn77ObZTc/4Ja33Aj8YNZ9EW8fmYhh5Yl7K4ZZGqgh6gc2TRuOYONwJjfZ eegMU3yx2BvxvHc3uhgr/oXeg9J/Biss+RDdJoAaGip/rkXLLKyUjO0r3CAQBHtTBc THLxgr/18vwkM6Zo87bbeEa0e7uZ7n8tt8TMDMLQjgBOxz0RY2SlfeaeT99HiljVGG qPK9cdG2u49AA== From: SeongJae Park To: Lance Yang Cc: SeongJae Park , ranxiaokai627@163.com, linux-mm@kvack.org, ziy@nvidia.com, ljs@kernel.org, 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, Guangshuo Li Subject: Re: [PATCH] mm/huge_memory: fix memory leak when kobject_init_and_add() fails Date: Tue, 9 Jun 2026 17:28:45 -0700 Message-ID: <20260610002846.77541-1-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit + Guangshuo On Tue, 9 Jun 2026 22:04:16 +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 ... I added the author of the patch (Guangshuo) to the recipients list of this mail, because they may better to aware of this. Thanks, SJ