aboutsummaryrefslogtreecommitdiff
path: root/hw/mem
diff options
context:
space:
mode:
authorJonathan Cameron <Jonathan.Cameron@huawei.com>2023-04-21 14:20:20 +0100
committerMichael S. Tsirkin <mst@redhat.com>2023-05-19 01:36:09 -0400
commit7b22a3218ad0b8388c8bf20d394e3220b2fc8798 (patch)
treef245d8f67b76d44434c91a1f5578423d25655c74 /hw/mem
parent71ba92f3488b64bd5c81e2872c56e88cea21bb95 (diff)
downloadqemu-7b22a3218ad0b8388c8bf20d394e3220b2fc8798.zip
qemu-7b22a3218ad0b8388c8bf20d394e3220b2fc8798.tar.gz
qemu-7b22a3218ad0b8388c8bf20d394e3220b2fc8798.tar.bz2
hw/cxl: cdat: Fix failure to free buffer in erorr paths
The failure paths in CDAT file loading did not clear up properly. Change to using g_auto_free and a local pointer for the buffer to ensure this function has no side effects on error. Also drop some unnecessary checks that can not fail. Cleanup properly after a failure to load a CDAT file. Suggested-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Message-Id: <20230421132020.7408-3-Jonathan.Cameron@huawei.com> Reviewed-by: Fan Ni <fan.ni@samsung.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/mem')
-rw-r--r--hw/mem/cxl_type3.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index abe60b3..7647122 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -593,6 +593,9 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp)
cxl_cstate->cdat.free_cdat_table = ct3_free_cdat_table;
cxl_cstate->cdat.private = ct3d;
cxl_doe_cdat_init(cxl_cstate, errp);
+ if (*errp) {
+ goto err_free_special_ops;
+ }
pcie_cap_deverr_init(pci_dev);
/* Leave a bit of room for expansion */
@@ -605,6 +608,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp)
err_release_cdat:
cxl_doe_cdat_release(cxl_cstate);
+err_free_special_ops:
g_free(regs->special_ops);
err_address_space_free:
address_space_destroy(&ct3d->hostmem_as);