Skip to content

Commit d858631

Browse files
Robert Richterdavejiang
authored andcommitted
cxl/pci: Moving code in cxl_hdm_decode_init()
Commit 3f9e075 ("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>
1 parent 21339b3 commit d858631

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

drivers/cxl/core/pci.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,6 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
419419
if (!hdm)
420420
return -ENODEV;
421421

422-
root = to_cxl_port(port->dev.parent);
423-
while (!is_cxl_root(root) && is_cxl_port(root->dev.parent))
424-
root = to_cxl_port(root->dev.parent);
425-
if (!is_cxl_root(root)) {
426-
dev_err(dev, "Failed to acquire root port for HDM enable\n");
427-
return -ENODEV;
428-
}
429-
430422
if (!info->mem_enabled) {
431423
rc = devm_cxl_enable_hdm(&port->dev, cxlhdm);
432424
if (rc)
@@ -435,6 +427,14 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
435427
return devm_cxl_enable_mem(&port->dev, cxlds);
436428
}
437429

430+
root = to_cxl_port(port->dev.parent);
431+
while (!is_cxl_root(root) && is_cxl_port(root->dev.parent))
432+
root = to_cxl_port(root->dev.parent);
433+
if (!is_cxl_root(root)) {
434+
dev_err(dev, "Failed to acquire root port for HDM enable\n");
435+
return -ENODEV;
436+
}
437+
438438
for (i = 0, allowed = 0; i < info->ranges; i++) {
439439
struct device *cxld_dev;
440440

0 commit comments

Comments
 (0)