[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z9QyR3mHw76u_Sq9@gourry-fedora-PF4VCD3F>
Date: Fri, 14 Mar 2025 09:42:31 -0400
From: Gregory Price <gourry@...rry.net>
To: Jonathan Cameron <Jonathan.Cameron@...wei.com>
Cc: Rakie Kim <rakie.kim@...com>, akpm@...ux-foundation.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org,
linux-cxl@...r.kernel.org, joshua.hahnjy@...il.com,
dan.j.williams@...el.com, ying.huang@...ux.alibaba.com,
kernel_team@...ynix.com, honggyu.kim@...com, yunjeong.mun@...com
Subject: Re: [PATCH v2 1/4] mm/mempolicy: Fix memory leaks in
mempolicy_sysfs_init()
On Fri, Mar 14, 2025 at 10:55:00AM +0000, Jonathan Cameron wrote:
> >
> > 1) allocate node_attrs and mempolicy_kobj up front and keep your
> > reordering, this lets us clean up allocations on failure before
> > kobject_init is called
> >
> > 2) after this remove all the other code and just let
> > mempolicy_kobj_release clean up node_attrs
> >
> > 3) Add a (%d) to the error message to differentiate failures
>
> Given how unlikely (and noisy) a memory allocation failure is,
> maybe just drop the printing at all in those paths - allowing
> early returns.
>
> The lifetime rules around node_attrs in here are making readability
> poor. It is implicitly owned by the mempolicy_kobj, but no direct association.
> Maybe just encapsulating the kobject in a structure that contains
> this as a [] array at the end. Then we end up with single allocation of
> stuff that is effectively one thing.
>
Even better recommendation, lets do as Jonathan suggests. <3
~Gregory
Powered by blists - more mailing lists