From nobody Sat Jul 25 22:33:16 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 99918353A7A for ; Mon, 13 Jul 2026 05:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783921331; cv=none; b=qUZafYYbeMaOElt1INL2nP2SM5KxaYPZcdGS3w0QjiM9CamCMQ+Kz8fvBcMZ8hApjAW9D6KADVmHr868wYD/Wl3DpS80u9XPvdfatXU/DYLrEz8Ek2r7GIS4+x4zhUDGzvhBk2juGOFsJrC46cw4kmsJo9CF5FCeM7nrKB1cHW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783921331; c=relaxed/simple; bh=1sLjtToDL0qCCVt47ENbCylxOBHwrsrZswksSq5nH5M=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=gHnMS1gGzou+c8uwhueWdNYHv/0TIV/Qh1wWTO/+Pg2zTEbruDqUSm7WfzSW5D9gFRd/JbQEoUTU2ZZiAMGVK+9JY9vQXODImEbSFG0eUaMtjjNVJM/+opabPN3VbvWuwk6TO2AOsL5Eesck+stOOagtI+LCum2hd1KbpeSXD08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 917e9a207e7d11f1aa26b74ffac11d73-20260713 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:38897b86-6435-4b13-8f83-65f0762bdc75,IP:0,U RL:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:25 X-CID-META: VersionHash:e7bac3a,CLOUDID:23c94f9602a6a63bc4130bd9aea047f2,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|136|850|865|898,TC:nil,Content:0|15| 50,EDM:5,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0, OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 917e9a207e7d11f1aa26b74ffac11d73-20260713 X-User: zenghongling@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 556758284; Mon, 13 Jul 2026 13:42:00 +0800 From: Hongling Zeng To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, liam@infradead.org, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, zhongling0719@126.com, Hongling Zeng Subject: [PATCH v2] mm: huge_memory: Fix kobject cleanup in thpsize_create error Date: Mon, 13 Jul 2026 13:41:54 +0800 Message-Id: <20260713054154.120915-1-zenghongling@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When kobject_init_and_add() fails, the kobject API requires calling kobject_put() to properly clean up the memory, not direct kfree(). According to the kobject API documentation, kobject_init_and_add() calls kobject_init() internally. If the subsequent kobject_add() fails, the kobject has still been initialized and must be cleaned up via the reference count mechanism (kobject_put), not direct kfree(). Direct kfree() leaves the kobject's internal state (including the reference count and kset membership) uncleaned, which can cause: - Memory leaks of kobject internal structures - Potential use-after-free if there are pending references - Inconsistent state with the rest of the error handling code This fix matches the pattern used elsewhere in the kernel and in the same function (err_put label) which correctly uses kobject_put(). Fixes: 3485b88390b0 ("mm: thp: introduce multi-size THP sysfs interface") Signed-off-by: Hongling Zeng Suggested-by: Baolin Wang Acked-by: Zi Yan Reviewed-by: Baolin Wang Reviewed-by: Lorenzo Stoakes (ARM) --- Change in v2: - Use goto err_put instead of kobject_put() + goto err for consistency - Add suggested --- mm/huge_memory.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 2bccb0a53a0a..589f7bf1f19d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -818,10 +818,8 @@ static struct thpsize *thpsize_create(int order, struc= t kobject *parent) =20 ret =3D kobject_init_and_add(&thpsize->kobj, &thpsize_ktype, parent, "hugepages-%lukB", size); - if (ret) { - kfree(thpsize); - goto err; - } + if (ret) + goto err_put; =20 =20 ret =3D sysfs_add_group(&thpsize->kobj, &any_ctrl_attr_grp); --=20 2.25.1