cxl/pci: Moving code in cxl_hdm_decode_init()
authorRobert Richter <rrichter@amd.com>
Fri, 9 May 2025 15:06:47 +0000 (17:06 +0200)
committerDave Jiang <dave.jiang@intel.com>
Fri, 9 May 2025 16:48:25 +0000 (09:48 -0700)
Commit 3f9e07531778 ("cxl/pci: simplify the check of mem_enabled in
cxl_hdm_decode_init()") changed the code flow in this function. The
root port is determined before a check to leave the function. Since
the root port is not used by the check it can be moved to run the
check first. This improves code readability and avoids unnesessary
code execution.

Signed-off-by: Robert Richter <rrichter@amd.com>
Reviewed-by: Gregory Price <gourry@gourry.net>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: "Fabio M. De Francesco" <fabio.m.de.francesco@linux.intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Gregory Price <gourry@gourry.net>
Acked-by: Dan Williams <dan.j.williams@intel.com>
Link: https://patch.msgid.link/20250509150700.2817697-3-rrichter@amd.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/core/pci.c

index 71bfa3bbe43658a42f04ceff0a097184a39f96b2..159674c1c71f3dc686559121d2976ee401525f47 100644 (file)
@@ -419,14 +419,6 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
        if (!hdm)
                return -ENODEV;
 
-       root = to_cxl_port(port->dev.parent);
-       while (!is_cxl_root(root) && is_cxl_port(root->dev.parent))
-               root = to_cxl_port(root->dev.parent);
-       if (!is_cxl_root(root)) {
-               dev_err(dev, "Failed to acquire root port for HDM enable\n");
-               return -ENODEV;
-       }
-
        if (!info->mem_enabled) {
                rc = devm_cxl_enable_hdm(&port->dev, cxlhdm);
                if (rc)
@@ -435,6 +427,14 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
                return devm_cxl_enable_mem(&port->dev, cxlds);
        }
 
+       root = to_cxl_port(port->dev.parent);
+       while (!is_cxl_root(root) && is_cxl_port(root->dev.parent))
+               root = to_cxl_port(root->dev.parent);
+       if (!is_cxl_root(root)) {
+               dev_err(dev, "Failed to acquire root port for HDM enable\n");
+               return -ENODEV;
+       }
+
        for (i = 0, allowed = 0; i < info->ranges; i++) {
                struct device *cxld_dev;