Skip to content

Commit 184053f

Browse files
Steve Sistarelegoater
authored andcommitted
vfio/iommufd: add vfio_device_free_name
Define vfio_device_free_name to free the name created by vfio_device_get_name. A subsequent patch will do more there. No functional change. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Link: https://lore.kernel.org/qemu-devel/1751493538-202042-11-git-send-email-steven.sistare@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
1 parent b9b389b commit 184053f

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

hw/vfio/ap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
265265

266266
error:
267267
error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->name);
268-
g_free(vbasedev->name);
268+
vfio_device_free_name(vbasedev);
269269
}
270270

271271
static void vfio_ap_unrealize(DeviceState *dev)
@@ -275,7 +275,7 @@ static void vfio_ap_unrealize(DeviceState *dev)
275275
vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX);
276276
vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_CFG_CHG_IRQ_INDEX);
277277
vfio_device_detach(&vapdev->vdev);
278-
g_free(vapdev->vdev.name);
278+
vfio_device_free_name(&vapdev->vdev);
279279
}
280280

281281
static const Property vfio_ap_properties[] = {

hw/vfio/ccw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
619619
out_region_err:
620620
vfio_device_detach(vbasedev);
621621
out_attach_dev_err:
622-
g_free(vbasedev->name);
622+
vfio_device_free_name(vbasedev);
623623
out_unrealize:
624624
if (cdc->unrealize) {
625625
cdc->unrealize(cdev);
@@ -637,7 +637,7 @@ static void vfio_ccw_unrealize(DeviceState *dev)
637637
vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
638638
vfio_ccw_put_region(vcdev);
639639
vfio_device_detach(&vcdev->vdev);
640-
g_free(vcdev->vdev.name);
640+
vfio_device_free_name(&vcdev->vdev);
641641

642642
if (cdc->unrealize) {
643643
cdc->unrealize(cdev);

hw/vfio/device.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
333333
return true;
334334
}
335335

336+
void vfio_device_free_name(VFIODevice *vbasedev)
337+
{
338+
g_clear_pointer(&vbasedev->name, g_free);
339+
}
340+
336341
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp)
337342
{
338343
ERRP_GUARD();

hw/vfio/pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2996,7 +2996,7 @@ void vfio_pci_put_device(VFIOPCIDevice *vdev)
29962996

29972997
vfio_device_detach(&vdev->vbasedev);
29982998

2999-
g_free(vdev->vbasedev.name);
2999+
vfio_device_free_name(&vdev->vbasedev);
30003000
g_free(vdev->msix);
30013001
}
30023002

hw/vfio/platform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static bool vfio_base_device_init(VFIODevice *vbasedev, Error **errp)
530530
{
531531
/* @fd takes precedence over @sysfsdev which takes precedence over @host */
532532
if (vbasedev->fd < 0 && vbasedev->sysfsdev) {
533-
g_free(vbasedev->name);
533+
vfio_device_free_name(vbasedev);
534534
vbasedev->name = g_path_get_basename(vbasedev->sysfsdev);
535535
} else if (vbasedev->fd < 0) {
536536
if (!vbasedev->name || strchr(vbasedev->name, '/')) {

include/hw/vfio/vfio-device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int index,
279279

280280
/* Returns 0 on success, or a negative errno. */
281281
bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
282+
void vfio_device_free_name(VFIODevice *vbasedev);
282283
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
283284
void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
284285
DeviceState *dev, bool ram_discard);

0 commit comments

Comments
 (0)