From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Li Ming <ming4.li@intel.com>
Cc: <dave@stgolabs.net>, <dave.jiang@intel.com>,
<alison.schofield@intel.com>, <vishal.l.verma@intel.com>,
<ira.weiny@intel.com>, <dan.j.williams@intel.com>,
<linux-cxl@vger.kernel.org>
Subject: Re: [PATCH v2 2/3] cxl/port: Use scoped_guard()/guard() to drop device_lock() for cxl_port
Date: Tue, 27 Aug 2024 12:55:22 +0100 [thread overview]
Message-ID: <20240827125522.00007262@Huawei.com> (raw)
In-Reply-To: <20240826083058.1509232-2-ming4.li@intel.com>
On Mon, 26 Aug 2024 08:30:57 +0000
Li Ming <ming4.li@intel.com> wrote:
> A device_lock() and device_unlock() pair can be replaced by a cleanup
> helper scoped_guard() or guard(), that can enhance code readability. In
> CXL subsystem, still use device_lock() and device_unlock() pairs for cxl
> port resource protection, most of them can be replaced by a
> scoped_guard() or a guard() simply.
>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Li Ming <ming4.li@intel.com>
Hi Li Ming,
The advantages of previous patch become clearer here. So
overall I think I'm convinced it's worth making the change.
Follow on comment below,
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
> index b50dda6610e3..7b87b5142fa7 100644
> --- a/drivers/cxl/core/port.c
> +++ b/drivers/cxl/core/port.c
> @@ -1561,40 +1556,38 @@ static int add_port_attach_ep(struct cxl_memdev *cxlmd,
> return -EAGAIN;
> }
>
> - device_lock(&parent_port->dev);
> - if (!parent_port->dev.driver) {
> - dev_warn(&cxlmd->dev,
> - "port %s:%s disabled, failed to enumerate CXL.mem\n",
> - dev_name(&parent_port->dev), dev_name(uport_dev));
> - port = ERR_PTR(-ENXIO);
> - goto out;
> - }
As per comment in previous patch, I'd pull the instantiation of
port down here. That way constructor and destructor are at least nearby
and the ordering is more what I'd expect.
> + scoped_guard(device, &parent_port->dev) {
> + if (!parent_port->dev.driver) {
> + dev_warn(&cxlmd->dev,
> + "port %s:%s disabled, failed to enumerate CXL.mem\n",
> + dev_name(&parent_port->dev), dev_name(uport_dev));
> + return -ENXIO;
> + }
> +
> + port = find_cxl_port_at(parent_port, dport_dev, &dport);
> + if (!port) {
> + component_reg_phys = find_component_registers(uport_dev);
> + port = devm_cxl_add_port(&parent_port->dev, uport_dev,
> + component_reg_phys, parent_dport);
> + if (IS_ERR(port))
> + return PTR_ERR(port);
>
> - port = find_cxl_port_at(parent_port, dport_dev, &dport);
> - if (!port) {
> - component_reg_phys = find_component_registers(uport_dev);
> - port = devm_cxl_add_port(&parent_port->dev, uport_dev,
> - component_reg_phys, parent_dport);
> - /* retry find to pick up the new dport information */
> - if (!IS_ERR(port))
> + /* retry find to pick up the new dport information */
> port = find_cxl_port_at(parent_port, dport_dev, &dport);
> + if (!port)
> + return -ENXIO;
> + }
> }
> -out:
> - device_unlock(&parent_port->dev);
>
> - if (IS_ERR(port))
> - rc = PTR_ERR(port);
> - else {
> - dev_dbg(&cxlmd->dev, "add to new port %s:%s\n",
> - dev_name(&port->dev), dev_name(port->uport_dev));
> - rc = cxl_add_ep(dport, &cxlmd->dev);
> - if (rc == -EBUSY) {
> - /*
> - * "can't" happen, but this error code means
> - * something to the caller, so translate it.
> - */
> - rc = -ENXIO;
> - }
> + dev_dbg(&cxlmd->dev, "add to new port %s:%s\n",
> + dev_name(&port->dev), dev_name(port->uport_dev));
> + rc = cxl_add_ep(dport, &cxlmd->dev);
> + if (rc == -EBUSY) {
> + /*
> + * "can't" happen, but this error code means
> + * something to the caller, so translate it.
> + */
> + rc = -ENXIO;
> }
>
> return rc;
next prev parent reply other threads:[~2024-08-27 11:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-26 8:30 [PATCH v2 1/3] cxl/port: Use __free() to drop put_device() for cxl_port Li Ming
2024-08-26 8:30 ` [PATCH v2 2/3] cxl/port: Use scoped_guard()/guard() to drop device_lock() " Li Ming
2024-08-27 11:55 ` Jonathan Cameron [this message]
2024-08-26 8:30 ` [PATCH v2 3/3] cxl/port: Refactor __devm_cxl_add_port() to drop goto pattern Li Ming
2024-08-27 12:05 ` Jonathan Cameron
2024-08-28 1:33 ` Li, Ming4
2024-08-27 11:48 ` [PATCH v2 1/3] cxl/port: Use __free() to drop put_device() for cxl_port Jonathan Cameron
2024-08-28 1:27 ` Li, Ming4
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=20240827125522.00007262@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=ming4.li@intel.com \
--cc=vishal.l.verma@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox