From: Dan Williams <dan.j.williams@intel.com>
To: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Dan Williams <dan.j.williams@intel.com>
Cc: <dave.jiang@intel.com>, Li Zhijian <lizhijian@fujitsu.com>,
<linux-cxl@vger.kernel.org>
Subject: Re: [PATCH] cxl/region: Convert cxl_pmem_region_alloc to scope-based resource management
Date: Wed, 1 May 2024 16:27:15 -0700 [thread overview]
Message-ID: <6632cfd3b6e93_1aefb294f5@dwillia2-mobl3.amr.corp.intel.com.notmuch> (raw)
In-Reply-To: <20240501130251.0000265d@Huawei.com>
Jonathan Cameron wrote:
> On Tue, 30 Apr 2024 14:59:00 -0700
> Dan Williams <dan.j.williams@intel.com> wrote:
>
> > A recent bugfix to cxl_pmem_region_alloc() to fix an
> > error-unwind-memleak [1], highlighted a use case for scope-based resource
> > management.
> >
> > Delete the goto for releasing @cxl_region_rwsem, and return error codes
> > directly from error condition paths.
> >
> > The caller, devm_cxl_add_pmem_region(), is no longer given @cxlr_pmem
> > directly it must retrieve it from @cxlr->cxlr_pmem. This retrieval from
> > @cxlr was already in place for @cxlr->cxl_nvb, and converting
> > cxl_pmem_region_alloc() to return an int makes it less awkward to handle
> > no_free_ptr().
> >
> > Cc: Li Zhijian <lizhijian@fujitsu.com>
> > Reported-by: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
> > Closes: http://lore.kernel.org/r/20240430174540.000039ce@Huawei.com
> > Link: http://lore.kernel.org/r/20240428030748.318985-1-lizhijian@fujitsu.com
> > Signed-off-by: Dan Williams <dan.j.williams@intel.com>
>
> Trivial comments inline Up to Dave or you on whether you want to act on them.
>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
[..]
> > - cxlr_pmem = kzalloc(struct_size(cxlr_pmem, mapping, p->nr_targets),
> > - GFP_KERNEL);
> > - if (!cxlr_pmem) {
> > - cxlr_pmem = ERR_PTR(-ENOMEM);
> > - goto out;
> > - }
> > + struct cxl_pmem_region *cxlr_pmem __free(kfree) = kzalloc(
> > + struct_size(cxlr_pmem, mapping, p->nr_targets), GFP_KERNEL);
>
> That is rather ugly. Maybe bring the kzalloc down onto the second line and
> wrap the GFP_KERNEL (or just go over 80 chars)?
I have made a conscious decision to stop caring about manually making 80
column collisions look nicer or selectively breaking the 80 column limit
rule. For this drivers/cxl/ corner of the kernel, whatever the
.clang-format template allows, works for me.
So if you can propose a .clang-format change that makes things prettier
in this case I would entertain it, but otherwise, life's too short.
Along those lines it would be nice if usages of __free caused the
automatic line break to happen after the "=" sign rather than later at
the arguments to kzalloc() like the above. However, I don't know the
template incantations to achieve that.
[..]
> > @@ -2861,9 +2851,10 @@ static int devm_cxl_add_pmem_region(struct cxl_region *cxlr)
> > struct device *dev;
> > int rc;
> >
> > - cxlr_pmem = cxl_pmem_region_alloc(cxlr);
> > - if (IS_ERR(cxlr_pmem))
> > - return PTR_ERR(cxlr_pmem);
> > + rc = cxl_pmem_region_alloc(cxlr);
> > + if (rc)
> > + return rc;
> > + cxlr_pmem = cxlr->cxlr_pmem;
>
> Is the local variable worth retaining? It's only used twice.
>
> The fact it's a clxr->cxlr* also seems rather like it could be named
> in a more compact fashion inside the cxl_region. Would pmemr
> work for instance?
I am ambivalent about a cxlr_pmem rename. It would need to be a separate
patch to handle the 46 instances of cxlr_pmem.
next prev parent reply other threads:[~2024-05-01 23:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 21:59 [PATCH] cxl/region: Convert cxl_pmem_region_alloc to scope-based resource management Dan Williams
2024-04-30 22:50 ` fan
2024-05-01 12:02 ` Jonathan Cameron
2024-05-01 23:27 ` Dan Williams [this message]
2024-05-09 7:04 ` Zhijian Li (Fujitsu)
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=6632cfd3b6e93_1aefb294f5@dwillia2-mobl3.amr.corp.intel.com.notmuch \
--to=dan.j.williams@intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=dave.jiang@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=lizhijian@fujitsu.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