Skip to content

Commit 793a539

Browse files
davejiangdjbw
authored andcommitted
cxl: Explicitly initialize resources when media is not ready
When media is not ready do not assume that the capacity information from the identify command is valid, i.e. ->total_bytes ->partition_align_bytes ->{volatile,persistent}_only_bytes. Explicitly zero out the capacity resources and exit early. Given zero-init of those fields this patch is functionally equivalent to the prior state, but it improves readability and robustness going forward. Signed-off-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/168506118166.3004974.13523455340007852589.stgit@djiang5-mobl3 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent a70fc4e commit 793a539

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/cxl/core/mbox.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,13 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
11051105
struct device *dev = cxlds->dev;
11061106
int rc;
11071107

1108+
if (!cxlds->media_ready) {
1109+
cxlds->dpa_res = DEFINE_RES_MEM(0, 0);
1110+
cxlds->ram_res = DEFINE_RES_MEM(0, 0);
1111+
cxlds->pmem_res = DEFINE_RES_MEM(0, 0);
1112+
return 0;
1113+
}
1114+
11081115
cxlds->dpa_res =
11091116
(struct resource)DEFINE_RES_MEM(0, cxlds->total_bytes);
11101117

@@ -1118,12 +1125,10 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
11181125
cxlds->persistent_only_bytes, "pmem");
11191126
}
11201127

1121-
if (cxlds->media_ready) {
1122-
rc = cxl_mem_get_partition_info(cxlds);
1123-
if (rc) {
1124-
dev_err(dev, "Failed to query partition information\n");
1125-
return rc;
1126-
}
1128+
rc = cxl_mem_get_partition_info(cxlds);
1129+
if (rc) {
1130+
dev_err(dev, "Failed to query partition information\n");
1131+
return rc;
11271132
}
11281133

11291134
rc = add_dpa_res(dev, &cxlds->dpa_res, &cxlds->ram_res, 0,

0 commit comments

Comments
 (0)