From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Dan Williams <dan.j.williams@intel.com>,
akpm@linux-foundation.org, Li Zhijian <lizhijian@fujitsu.com>,
linux-cxl@vger.kernel.org, mika.westerberg@linux.intel.com,
ilpo.jarvinen@linux.intel.com, bhelgaas@google.com,
huang.ying.caritas@gmail.com
Subject: Re: [PATCH] resource: Fix resource leak in get_free_mem_region()
Date: Fri, 14 Mar 2025 16:44:18 +0200 [thread overview]
Message-ID: <Z9RAwm7zNZ796z1a@smile.fi.intel.com> (raw)
In-Reply-To: <20250314114901.00000b99@huawei.com>
On Fri, Mar 14, 2025 at 11:49:01AM +0000, Jonathan Cameron wrote:
> On Tue, 04 Mar 2025 18:22:53 -0800
> Dan Williams <dan.j.williams@intel.com> wrote:
...
> > + struct region_devres *dr __free(kfree) = NULL;
> > + struct resource *res;
> > +
> Avoid split of the constructor / destructor with a ternary though
> error check is worse... Hmm.
>
> struct region_devres *dr __free(kfree) =
> dev ? devres_alloc(devm_region_release, sizeof(*dr), GFP_KERNEL) : NULL;
> if (dev && !dr)
> return ERR_PTR(-ENOMEM);
>
> So on balance up to you,
I'm against ternary, it looks unreadable in this case.
...
> but at very least put that __free(kfree) direclty
> above the set.
This I am neutral about. Any thing works for me.
The rest you suggested is +1 from me.
> > + if (dev) {
> > + dr = devres_alloc(devm_region_release,
> > + sizeof(struct region_devres), GFP_KERNEL);
> > + if (!dr)
> > + return ERR_PTR(-ENOMEM);
> > + }
> > +
> > + res = __get_free_mem_region(base, size, align, name, desc, flags);
> > +
> Probably no blank line here would be nicer.
>
> > + if (IS_ERR(res) || !dr)
>
> This conflates error and don't care if error cases and briefly
> made me scratch my head.
>
> Maybe though it increase indent don't do early
> return on the !dr case.
>
> if (IS_ERR(res))
> return res;
>
> if (dr) {
> dr->parent = base;
>
> ...
>
> }
>
> return res;
>
> > + return res;
> > +
> > + dr->parent = base;
> > + dr->start = res->start;
> > + dr->n = resource_size(res);
> > +
> > + /* See 'struct region_devres' definition for details */
> > + if ((flags & GFR_REQUEST_REGION) == 0)
> > + dr->res = res;
> > +
> > + devres_add(dev, no_free_ptr(dr));
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-03-14 14:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-05 2:22 [PATCH] resource: Fix resource leak in get_free_mem_region() Dan Williams
2025-03-05 2:54 ` Zhijian Li (Fujitsu)
2025-03-05 3:06 ` Dan Williams
2025-03-05 10:22 ` Andy Shevchenko
2025-03-14 11:49 ` Jonathan Cameron
2025-03-14 14:44 ` Andy Shevchenko [this message]
2025-06-04 6:06 ` Zhijian Li (Fujitsu)
2025-06-04 6:31 ` Andrew Morton
-- strict thread matches above, loose matches on Subject: below --
2025-03-04 4:34 Li Zhijian
2025-03-04 9:22 ` Mika Westerberg
2025-03-04 9:44 ` Zhijian Li (Fujitsu)
2025-03-04 10:03 ` Mika Westerberg
2025-03-04 12:09 ` Andy Shevchenko
2025-03-04 23:43 ` Dan Williams
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=Z9RAwm7zNZ796z1a@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=bhelgaas@google.com \
--cc=dan.j.williams@intel.com \
--cc=huang.ying.caritas@gmail.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=lizhijian@fujitsu.com \
--cc=mika.westerberg@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.