mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-14 15:54:15 +08:00
cxl/pci: Simplify CDAT retrieval error path
The cdat.table and cdat.length fields in struct cxl_port are set before CDAT retrieval and must therefore be unset on failure. Simplify by setting only on success. Suggested-by: Jonathan Cameron <Jonathan.Cameron@Huawei.com> Link: https://lore.kernel.org/linux-cxl/20230209113422.00007017@Huawei.com/ Signed-off-by: Dave Jiang <dave.jiang@intel.com> [lukas: rebase and rephrase commit message] Signed-off-by: Lukas Wunner <lukas@wunner.de> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Link: https://lore.kernel.org/r/7a5c7104fb6a3016dbaec1c5d0ed34619ea11a0c.1678543498.git.lukas@wunner.de Signed-off-by: Dan Williams <dan.j.williams@intel.com>
This commit is contained in:
parent
cedf8d8a50
commit
7a877c9239
@ -475,10 +475,10 @@ static int cxl_cdat_get_length(struct device *dev,
|
||||
|
||||
static int cxl_cdat_read_table(struct device *dev,
|
||||
struct pci_doe_mb *cdat_doe,
|
||||
struct cxl_cdat *cdat)
|
||||
void *cdat_table, size_t *cdat_length)
|
||||
{
|
||||
size_t length = cdat->length;
|
||||
__le32 *data = cdat->table;
|
||||
size_t length = *cdat_length;
|
||||
__le32 *data = cdat_table;
|
||||
int entry_handle = 0;
|
||||
|
||||
do {
|
||||
@ -522,7 +522,7 @@ static int cxl_cdat_read_table(struct device *dev,
|
||||
} while (entry_handle != CXL_DOE_TABLE_ACCESS_LAST_ENTRY);
|
||||
|
||||
/* Length in CDAT header may exceed concatenation of CDAT entries */
|
||||
cdat->length -= length;
|
||||
*cdat_length -= length;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -542,6 +542,7 @@ void read_cdat_data(struct cxl_port *port)
|
||||
struct cxl_dev_state *cxlds = cxlmd->cxlds;
|
||||
struct pci_dev *pdev = to_pci_dev(cxlds->dev);
|
||||
size_t cdat_length;
|
||||
void *cdat_table;
|
||||
int rc;
|
||||
|
||||
cdat_doe = pci_find_doe_mailbox(pdev, PCI_DVSEC_VENDOR_ID_CXL,
|
||||
@ -558,19 +559,19 @@ void read_cdat_data(struct cxl_port *port)
|
||||
return;
|
||||
}
|
||||
|
||||
port->cdat.table = devm_kzalloc(dev, cdat_length, GFP_KERNEL);
|
||||
if (!port->cdat.table)
|
||||
cdat_table = devm_kzalloc(dev, cdat_length, GFP_KERNEL);
|
||||
if (!cdat_table)
|
||||
return;
|
||||
|
||||
port->cdat.length = cdat_length;
|
||||
rc = cxl_cdat_read_table(dev, cdat_doe, &port->cdat);
|
||||
rc = cxl_cdat_read_table(dev, cdat_doe, cdat_table, &cdat_length);
|
||||
if (rc) {
|
||||
/* Don't leave table data allocated on error */
|
||||
devm_kfree(dev, port->cdat.table);
|
||||
port->cdat.table = NULL;
|
||||
port->cdat.length = 0;
|
||||
devm_kfree(dev, cdat_table);
|
||||
dev_err(dev, "CDAT data read error\n");
|
||||
}
|
||||
|
||||
port->cdat.table = cdat_table;
|
||||
port->cdat.length = cdat_length;
|
||||
}
|
||||
EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user