mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-26 03:21:50 -06:00
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>
This commit is contained in:
parent
11ebce2a55
commit
81987bd58b
1 changed files with 3 additions and 4 deletions
|
@ -2972,12 +2972,13 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
||||||
ERRP_GUARD();
|
ERRP_GUARD();
|
||||||
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
|
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
|
||||||
VFIODevice *vbasedev = &vdev->vbasedev;
|
VFIODevice *vbasedev = &vdev->vbasedev;
|
||||||
char *tmp, *subsys;
|
char *subsys;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
bool is_mdev;
|
bool is_mdev;
|
||||||
char uuid[UUID_STR_LEN];
|
char uuid[UUID_STR_LEN];
|
||||||
char *name;
|
g_autofree char *name = NULL;
|
||||||
|
g_autofree char *tmp = NULL;
|
||||||
|
|
||||||
if (vbasedev->fd < 0 && !vbasedev->sysfsdev) {
|
if (vbasedev->fd < 0 && !vbasedev->sysfsdev) {
|
||||||
if (!(~vdev->host.domain || ~vdev->host.bus ||
|
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);
|
tmp = g_strdup_printf("%s/subsystem", vbasedev->sysfsdev);
|
||||||
subsys = realpath(tmp, NULL);
|
subsys = realpath(tmp, NULL);
|
||||||
g_free(tmp);
|
|
||||||
is_mdev = subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
|
is_mdev = subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
|
||||||
free(subsys);
|
free(subsys);
|
||||||
|
|
||||||
|
@ -3029,7 +3029,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
||||||
|
|
||||||
ret = vfio_attach_device(name, vbasedev,
|
ret = vfio_attach_device(name, vbasedev,
|
||||||
pci_device_iommu_address_space(pdev), errp);
|
pci_device_iommu_address_space(pdev), errp);
|
||||||
g_free(name);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue