From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 D8F2521CA03 for ; Wed, 15 Jul 2026 06:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784097632; cv=none; b=SNYuBcF5AJ+G7wR7Njkhh2by2Hx9A9MpNrhNHNSZsxSXiIiG8DifU26Cffhdfabq82xEhKskwSn5+hQpU3yHK4aMYgeOEQ4phKdK2fenl7l4cLkL1X83dmQKnjkibOx+uC2SSOyIwUz/Lrgb8OgOHEAzAsgcrmqQjKIjr5TO4SI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784097632; c=relaxed/simple; bh=KGNIAL3y2A/bQurEKoZFR8dazFif4IXo+WcJ933XfMI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=YsGdgj4LV6E/z+Ieibu8PXM1errOy/TI+dY2cjQ87eyaSBhL/biBji82yx4hJ9CSHAd8Ik71cHHiSP37R4d6l3kwVezTwMytkG/tvUn0vmvRENV1wFZadKuzhOoWtI5sHopXP65vmyxgHjPl7/buWrDvQtqdweGaEriDGquOqBI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=GDx0Leos; arc=none smtp.client-ip=115.124.30.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="GDx0Leos" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1784097626; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=JQE2KA2u6LDSaLsz5mL9HbAifq2cSrHUYI76h0zWOLE=; b=GDx0Leoso0PTAuyhLe/6ePSOMeHxelTSjnOnvkIdXGC9/0+VdbeOcjA3ITLB7ETLgJsNMR+39pc16YB8Vie6hJXN8pJBSrhn3Vdm5w5ucSOXHI4LrSTvFvKBRr6Ksb6ZcKZ0uTE0wZLJbwM+kPfDXxZEJhhpKVoofJEbuaNBV9g= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037026112;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0X78A6BJ_1784097623; Received: from 30.74.144.123(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X78A6BJ_1784097623 cluster:ay36) by smtp.aliyun-inc.com; Wed, 15 Jul 2026 14:40:24 +0800 Message-ID: Date: Wed, 15 Jul 2026 14:40:23 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm: huge_memory: Fix kobject cleanup in thpsize_create error To: Hongling Zeng , akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, ziy@nvidia.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 References: <20260713054154.120915-1-zenghongling@kylinos.cn> From: Baolin Wang In-Reply-To: <20260713054154.120915-1-zenghongling@kylinos.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/13/26 1:41 PM, Hongling Zeng wrote: > 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 > > --- LGTM. Reviewed-by: Baolin Wang By the way, I don't think my Suggested-by tag is needed, as it was just a simple comment (But no need to respin).