Skip to content

Commit c65efe3

Browse files
weiny2djbw
authored andcommitted
cxl/cdat: Free correct buffer on checksum error
The new 6.7-rc1 kernel now checks the checksum on CDAT data. While using a branch of Fan's DCD qemu work (and specifying DCD devices), the following splat was observed. WARNING: CPU: 1 PID: 1384 at drivers/base/devres.c:1064 devm_kfree+0x4f/0x60 ... RIP: 0010:devm_kfree+0x4f/0x60 ... ? devm_kfree+0x4f/0x60 read_cdat_data+0x1a0/0x2a0 [cxl_core] cxl_port_probe+0xdf/0x200 [cxl_port] ... The issue in qemu is still unknown but the spat is a straight forward bug in the CDAT checksum processing code. Use a CDAT buffer variable to ensure the devm_free() works correctly on error. Fixes: 670e4e8 ("cxl: Add checksum verification to CDAT from CXL") Signed-off-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Fan Ni <fan.ni@samsung.com> Reviewed-by: Robert Richter <rrichter@amd.com> Link: http://lore.kernel.org/r/20231116-fix-cdat-devm-free-v1-1-b148b40707d7@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 6f5c4ec commit c65efe3

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/cxl/core/pci.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ void read_cdat_data(struct cxl_port *port)
620620
struct pci_dev *pdev = NULL;
621621
struct cxl_memdev *cxlmd;
622622
size_t cdat_length;
623-
void *cdat_table;
623+
void *cdat_table, *cdat_buf;
624624
int rc;
625625

626626
if (is_cxl_memdev(uport)) {
@@ -651,16 +651,15 @@ void read_cdat_data(struct cxl_port *port)
651651
return;
652652
}
653653

654-
cdat_table = devm_kzalloc(dev, cdat_length + sizeof(__le32),
655-
GFP_KERNEL);
656-
if (!cdat_table)
654+
cdat_buf = devm_kzalloc(dev, cdat_length + sizeof(__le32), GFP_KERNEL);
655+
if (!cdat_buf)
657656
return;
658657

659-
rc = cxl_cdat_read_table(dev, cdat_doe, cdat_table, &cdat_length);
658+
rc = cxl_cdat_read_table(dev, cdat_doe, cdat_buf, &cdat_length);
660659
if (rc)
661660
goto err;
662661

663-
cdat_table = cdat_table + sizeof(__le32);
662+
cdat_table = cdat_buf + sizeof(__le32);
664663
if (cdat_checksum(cdat_table, cdat_length))
665664
goto err;
666665

@@ -670,7 +669,7 @@ void read_cdat_data(struct cxl_port *port)
670669

671670
err:
672671
/* Don't leave table data allocated on error */
673-
devm_kfree(dev, cdat_table);
672+
devm_kfree(dev, cdat_buf);
674673
dev_err(dev, "Failed to read/validate CDAT.\n");
675674
}
676675
EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL);

0 commit comments

Comments
 (0)