Skip to content

Commit 3f9e075

Browse files
YanfeiXudavejiang
authored andcommitted
cxl/pci: simplify the check of mem_enabled in cxl_hdm_decode_init()
Cases can be divided into two categories which are DVSEC range enabled and not enabled when HDM decoders exist but is not enabled. To avoid checking info->mem_enabled, which indicates the enablement of DVSEC range, every time, we can check !info->mem_enabled once in advance. This simplification can make the code clearer. No functional change intended. Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Yanfei Xu <[email protected]> Reviewed-by: Alison Schofield <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Dave Jiang <[email protected]>
1 parent 99bf0ee commit 3f9e075

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/cxl/core/pci.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,15 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
426426
return -ENODEV;
427427
}
428428

429-
for (i = 0, allowed = 0; info->mem_enabled && i < info->ranges; i++) {
429+
if (!info->mem_enabled) {
430+
rc = devm_cxl_enable_hdm(&port->dev, cxlhdm);
431+
if (rc)
432+
return rc;
433+
434+
return devm_cxl_enable_mem(&port->dev, cxlds);
435+
}
436+
437+
for (i = 0, allowed = 0; i < info->ranges; i++) {
430438
struct device *cxld_dev;
431439

432440
cxld_dev = device_find_child(&root->dev, &info->dvsec_range[i],
@@ -440,7 +448,7 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
440448
allowed++;
441449
}
442450

443-
if (!allowed && info->mem_enabled) {
451+
if (!allowed) {
444452
dev_err(dev, "Range register decodes outside platform defined CXL ranges.\n");
445453
return -ENXIO;
446454
}
@@ -454,14 +462,7 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
454462
* match. If at least one DVSEC range is enabled and allowed, skip HDM
455463
* Decoder Capability Enable.
456464
*/
457-
if (info->mem_enabled)
458-
return 0;
459-
460-
rc = devm_cxl_enable_hdm(&port->dev, cxlhdm);
461-
if (rc)
462-
return rc;
463-
464-
return devm_cxl_enable_mem(&port->dev, cxlds);
465+
return 0;
465466
}
466467
EXPORT_SYMBOL_NS_GPL(cxl_hdm_decode_init, CXL);
467468

0 commit comments

Comments
 (0)