From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (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 B7B8C282F0A for ; Tue, 9 Jun 2026 14:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781013883; cv=none; b=VLfUcYIpRWpTnpNynbwH6k5i0nT06KFXpGwxQRXjDbpFalG9ce8Af3E9v3GKFEMSIJCrxSKW2TJT7qGRSyJBT2Ur+wh6Z4u8qG8U0haQPQnUQjV45iMD6cXZe1lbihgaRFOhhdYXGmG7VVQovS4Y1HJWU4iKaL5MSCEcJqusAjE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781013883; c=relaxed/simple; bh=xbR0PRAgzbCw4gzTyzeo+LAXIt8Ht7QDM9EsQXRMHEc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qvQ0/IdtM7dlICQHoM8uySozu+t5SbbE1WYiojGyJ/IKoqYjKmbF7hELAK0rV018cNr21m5jN5f68m3uxMdnt4eDRT1s13LCCjbwPkNmR9UJPdzmt1gk92MW4+qpHM+Lk176JpFvzUumYo4f1IEIpVyY6XeIUHu3Fv/PW/R7f+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=dBp9B3Jy; arc=none smtp.client-ip=95.215.58.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dBp9B3Jy" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781013879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c2X6ceXsUYSApmdLkh3PVusM4XweOQmUdFpOH3H9jJc=; b=dBp9B3Jymr0LeLKSWlvx32Kdjtkw4ksdKB90fajcjVzs2BdPKYQbEUWwCeAN4v7A4bJmxn dPm9v/Re4gl7oEf5/ABo6jAAG9/8emQh2zN/4SleDrwlKjBbN03QzTicHbCHQWbdYWQPGS p0Bd/Wv3HjYSwGtp1ya12t2vfhlM3/c= Date: Tue, 9 Jun 2026 22:04:16 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/huge_memory: fix memory leak when kobject_init_and_add() fails Content-Language: en-US To: ranxiaokai627@163.com Cc: 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 References: <20260609131249.89288-1-ranxiaokai627@163.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT 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 ...