aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorZhenzhong Duan <zhenzhong.duan@intel.com>2024-05-07 14:42:42 +0800
committerCédric Le Goater <clg@redhat.com>2024-05-16 16:59:20 +0200
commit81987bd58b558be71dc4d8adf163f8c787a1c3e9 (patch)
treecd87bf9d892a49a0aefd6725dbcf9c03689b33c4 /hw
parent11ebce2a5544cacab31e8ff169c6f0ceef37f4e8 (diff)
downloadqemu-81987bd58b558be71dc4d8adf163f8c787a1c3e9.zip
qemu-81987bd58b558be71dc4d8adf163f8c787a1c3e9.tar.gz
qemu-81987bd58b558be71dc4d8adf163f8c787a1c3e9.tar.bz2
vfio/pci: Use g_autofree in vfio_realize
Local pointer name is allocated before vfio_attach_device() call and freed after the call. Same for tmp when calling realpath(). Use 'g_autofree' to avoid the g_free() calls. Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Cédric Le Goater <clg@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/vfio/pci.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index b5d1d39..84f7bff 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2972,12 +2972,13 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
ERRP_GUARD();
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
VFIODevice *vbasedev = &vdev->vbasedev;
- char *tmp, *subsys;
+ char *subsys;
Error *err = NULL;
int i, ret;
bool is_mdev;
char uuid[UUID_STR_LEN];
- char *name;
+ g_autofree char *name = NULL;
+ g_autofree char *tmp = NULL;
if (vbasedev->fd < 0 && !vbasedev->sysfsdev) {
if (!(~vdev->host.domain || ~vdev->host.bus ||
@@ -3008,7 +3009,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
*/
tmp = g_strdup_printf("%s/subsystem", vbasedev->sysfsdev);
subsys = realpath(tmp, NULL);
- g_free(tmp);
is_mdev = subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
free(subsys);
@@ -3029,7 +3029,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
ret = vfio_attach_device(name, vbasedev,
pci_device_iommu_address_space(pdev), errp);
- g_free(name);
if (ret) {
goto error;
}