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 <[email protected]> Reviewed-by: Gregory Price <[email protected]> Reviewed-by: Davidlohr Bueso <[email protected]> Reviewed-by: Alison Schofield <[email protected]> Reviewed-by: "Fabio M. De Francesco" <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Tested-by: Gregory Price <[email protected]> Acked-by: Dan Williams <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Dave Jiang <[email protected]>
1 parent 21339b3 commit d858631

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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)