From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Hongling Zeng <zenghongling@kylinos.cn>,
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
Subject: Re: [PATCH v2] mm: huge_memory: Fix kobject cleanup in thpsize_create error
Date: Wed, 15 Jul 2026 14:40:23 +0800 [thread overview]
Message-ID: <cdcdf136-325a-477f-aaf4-71d466bb96fb@linux.alibaba.com> (raw)
In-Reply-To: <20260713054154.120915-1-zenghongling@kylinos.cn>
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 <zenghongling@kylinos.cn>
> Suggested-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>
> ---
LGTM.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
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).
prev parent reply other threads:[~2026-07-15 6:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 5:41 [PATCH v2] mm: huge_memory: Fix kobject cleanup in thpsize_create error Hongling Zeng
2026-07-14 10:54 ` Lorenzo Stoakes (ARM)
2026-07-15 1:03 ` Zi Yan
2026-07-15 6:40 ` Baolin Wang [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=cdcdf136-325a-477f-aaf4-71d466bb96fb@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--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=zenghongling@kylinos.cn \
--cc=zhongling0719@126.com \
--cc=ziy@nvidia.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