mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Zi Yan" <ziy@nvidia.com>
To: "Hongling Zeng" <zenghongling@kylinos.cn>,
	<akpm@linux-foundation.org>, <david@kernel.org>, <ljs@kernel.org>,
	<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>, <stable@vger.kernel.org>
Subject: Re: [PATCH] mm: huge_memory: Fix kobject cleanup in thpsize_create error
Date: Tue, 14 Jul 2026 21:05:52 -0400	[thread overview]
Message-ID: <DJYQPL4G92KL.K1QTSHQ0JSU0@nvidia.com> (raw)
In-Reply-To: <DJYQMTVRAHNG.1DTTNWHH4006X@nvidia.com>

On Tue Jul 14, 2026 at 9:02 PM EDT, Zi Yan wrote:
> On Sat Jul 11, 2026 at 4:46 AM EDT, 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")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
>> ---
>>  mm/huge_memory.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
> LGTM.
>
> Acked-by: Zi Yan <ziy@nvidia.com>

Oops, forgot that V2 was sent and missed Baolin's comment. Sorry for the
noise.


-- 
Best Regards,
Yan, Zi


      reply	other threads:[~2026-07-15  1:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-11  8:46 Hongling Zeng
2026-07-13  4:00 ` Baolin Wang
2026-07-15  1:02 ` Zi Yan
2026-07-15  1:05   ` Zi Yan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DJYQPL4G92KL.K1QTSHQ0JSU0@nvidia.com \
    --to=ziy@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=zenghongling@kylinos.cn \
    --cc=zhongling0719@126.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®