Re: [PATCH V5 27/38] vfio/iommufd: add vfio_device_free_name
On 6/23/2025 9:50 AM, Eric Farman wrote:
On Tue, 2025-06-10 at 08:39 -0700, Steve Sistare wrote:
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
---
include/hw/vfio/vfio-device.h | 1 +
hw/vfio/ap.c | 2 +-
hw/vfio/ccw.c | 2 +-
hw/vfio/device.c | 5 +
hw/vfio/pci.c | 2 +-
hw/vfio/platform.c| 2 +-
6 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index 6eb6f21..321b442 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -227,6 +227,7 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int
index,
/* Returns 0 on success, or a negative errno. */
bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
+void vfio_device_free_name(VFIODevice *vbasedev);
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
DeviceState *dev, bool ram_discard);
diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
index 785c0a0..013bd59 100644
--- a/hw/vfio/ap.c
+++ b/hw/vfio/ap.c
@@ -180,7 +180,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
error:
error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->name);
-g_free(vbasedev->name);
+vfio_device_free_name(vbasedev);
}
static void vfio_ap_unrealize(DeviceState *dev)
^^^
I suspect you want to convert the g_free call of the VFIODevice name here as
well.
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index cea9d6e..903b8b0 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -619,7 +619,7 @@ out_io_notifier_err:
out_region_err:
vfio_device_detach(vbasedev);
out_attach_dev_err:
-g_free(vbasedev->name);
+vfio_device_free_name(vbasedev);
out_unrealize:
if (cdc->unrealize) {
cdc->unrealize(cdev);
Similarly, the matching g_free call in vfio_ccw_unrealize
Yes, thank you. I will do that in the next version.
- Steve
Re: [PATCH V5 27/38] vfio/iommufd: add vfio_device_free_name
On Tue, 2025-06-10 at 08:39 -0700, Steve Sistare wrote:
> 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
> ---
> include/hw/vfio/vfio-device.h | 1 +
> hw/vfio/ap.c | 2 +-
> hw/vfio/ccw.c | 2 +-
> hw/vfio/device.c | 5 +
> hw/vfio/pci.c | 2 +-
> hw/vfio/platform.c| 2 +-
> 6 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
> index 6eb6f21..321b442 100644
> --- a/include/hw/vfio/vfio-device.h
> +++ b/include/hw/vfio/vfio-device.h
> @@ -227,6 +227,7 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int
> index,
>
> /* Returns 0 on success, or a negative errno. */
> bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
> +void vfio_device_free_name(VFIODevice *vbasedev);
> void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
> void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
>DeviceState *dev, bool ram_discard);
> diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
> index 785c0a0..013bd59 100644
> --- a/hw/vfio/ap.c
> +++ b/hw/vfio/ap.c
> @@ -180,7 +180,7 @@ static void vfio_ap_realize(DeviceState *dev, Error
> **errp)
>
> error:
> error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->name);
> -g_free(vbasedev->name);
> +vfio_device_free_name(vbasedev);
> }
>
> static void vfio_ap_unrealize(DeviceState *dev)
^^^
I suspect you want to convert the g_free call of the VFIODevice name here as
well.
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> index cea9d6e..903b8b0 100644
> --- a/hw/vfio/ccw.c
> +++ b/hw/vfio/ccw.c
> @@ -619,7 +619,7 @@ out_io_notifier_err:
> out_region_err:
> vfio_device_detach(vbasedev);
> out_attach_dev_err:
> -g_free(vbasedev->name);
> +vfio_device_free_name(vbasedev);
> out_unrealize:
> if (cdc->unrealize) {
> cdc->unrealize(cdev);
Similarly, the matching g_free call in vfio_ccw_unrealize
Thanks,
Eric
RE: [PATCH V5 27/38] vfio/iommufd: add vfio_device_free_name
>-Original Message- >From: Steve Sistare >Subject: [PATCH V5 27/38] 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 Reviewed-by: Zhenzhong Duan Thanks Zhenzhong
Re: [PATCH V5 27/38] vfio/iommufd: add vfio_device_free_name
On 6/10/25 17:39, Steve Sistare wrote:
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
Reviewed-by: Cédric Le Goater
Thanks,
C.
---
include/hw/vfio/vfio-device.h | 1 +
hw/vfio/ap.c | 2 +-
hw/vfio/ccw.c | 2 +-
hw/vfio/device.c | 5 +
hw/vfio/pci.c | 2 +-
hw/vfio/platform.c| 2 +-
6 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index 6eb6f21..321b442 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -227,6 +227,7 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int
index,
/* Returns 0 on success, or a negative errno. */
bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
+void vfio_device_free_name(VFIODevice *vbasedev);
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
DeviceState *dev, bool ram_discard);
diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
index 785c0a0..013bd59 100644
--- a/hw/vfio/ap.c
+++ b/hw/vfio/ap.c
@@ -180,7 +180,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
error:
error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->name);
-g_free(vbasedev->name);
+vfio_device_free_name(vbasedev);
}
static void vfio_ap_unrealize(DeviceState *dev)
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index cea9d6e..903b8b0 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -619,7 +619,7 @@ out_io_notifier_err:
out_region_err:
vfio_device_detach(vbasedev);
out_attach_dev_err:
-g_free(vbasedev->name);
+vfio_device_free_name(vbasedev);
out_unrealize:
if (cdc->unrealize) {
cdc->unrealize(cdev);
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 71fa9f4..a3603f5 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -317,6 +317,11 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error
**errp)
return true;
}
+void vfio_device_free_name(VFIODevice *vbasedev)
+{
+g_clear_pointer(&vbasedev->name, g_free);
+}
+
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp)
{
ERRP_GUARD();
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index b52c488..b4136432 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2966,7 +2966,7 @@ static void vfio_pci_put_device(VFIOPCIDevice *vdev)
vfio_device_detach(&vdev->vbasedev);
-g_free(vdev->vbasedev.name);
+vfio_device_free_name(&vdev->vbasedev);
g_free(vdev->msix);
}
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 9a21f2e..5c1795a 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -530,7 +530,7 @@ static bool vfio_base_device_init(VFIODevice *vbasedev,
Error **errp)
{
/* @fd takes precedence over @sysfsdev which takes precedence over @host
*/
if (vbasedev->fd < 0 && vbasedev->sysfsdev) {
-g_free(vbasedev->name);
+vfio_device_free_name(vbasedev);
vbasedev->name = g_path_get_basename(vbasedev->sysfsdev);
} else if (vbasedev->fd < 0) {
if (!vbasedev->name || strchr(vbasedev->name, '/')) {
[PATCH V5 27/38] 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
---
include/hw/vfio/vfio-device.h | 1 +
hw/vfio/ap.c | 2 +-
hw/vfio/ccw.c | 2 +-
hw/vfio/device.c | 5 +
hw/vfio/pci.c | 2 +-
hw/vfio/platform.c| 2 +-
6 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index 6eb6f21..321b442 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -227,6 +227,7 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int
index,
/* Returns 0 on success, or a negative errno. */
bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
+void vfio_device_free_name(VFIODevice *vbasedev);
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
DeviceState *dev, bool ram_discard);
diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
index 785c0a0..013bd59 100644
--- a/hw/vfio/ap.c
+++ b/hw/vfio/ap.c
@@ -180,7 +180,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
error:
error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->name);
-g_free(vbasedev->name);
+vfio_device_free_name(vbasedev);
}
static void vfio_ap_unrealize(DeviceState *dev)
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index cea9d6e..903b8b0 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -619,7 +619,7 @@ out_io_notifier_err:
out_region_err:
vfio_device_detach(vbasedev);
out_attach_dev_err:
-g_free(vbasedev->name);
+vfio_device_free_name(vbasedev);
out_unrealize:
if (cdc->unrealize) {
cdc->unrealize(cdev);
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 71fa9f4..a3603f5 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -317,6 +317,11 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error
**errp)
return true;
}
+void vfio_device_free_name(VFIODevice *vbasedev)
+{
+g_clear_pointer(&vbasedev->name, g_free);
+}
+
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp)
{
ERRP_GUARD();
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index b52c488..b4136432 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2966,7 +2966,7 @@ static void vfio_pci_put_device(VFIOPCIDevice *vdev)
vfio_device_detach(&vdev->vbasedev);
-g_free(vdev->vbasedev.name);
+vfio_device_free_name(&vdev->vbasedev);
g_free(vdev->msix);
}
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 9a21f2e..5c1795a 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -530,7 +530,7 @@ static bool vfio_base_device_init(VFIODevice *vbasedev,
Error **errp)
{
/* @fd takes precedence over @sysfsdev which takes precedence over @host */
if (vbasedev->fd < 0 && vbasedev->sysfsdev) {
-g_free(vbasedev->name);
+vfio_device_free_name(vbasedev);
vbasedev->name = g_path_get_basename(vbasedev->sysfsdev);
} else if (vbasedev->fd < 0) {
if (!vbasedev->name || strchr(vbasedev->name, '/')) {
--
1.8.3.1
