vfio: memory leak fix and code cleanup
cover vfio: memory leak fix and code cleanup
Hi,
This trivial patchset fixes a incremental memory leak in rare case, and some cleanup on ap/ccw.
This patchset is based on vfio-next.
Thanks
Zhenzhong
Zhenzhong Duan (3):
vfio/pci: Fix a potential memory leak in vfio_listener_region_add vfio/ap: Remove pointless apdev variable
vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW
hw/vfio/ap.c | 9 +++------ hw/vfio/common.c | 2 +- include/hw/s390x/vfio-ccw.h | 2 -- 3 files changed, 4 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 vfio/pci: Fix a potential memory leak in vfio_listener_region_add
When there is an failure in vfio_listener_region_add() and the section belongs to a ram device, there is an inaccurate error report which should never be related to vfio_dma_map failure. The memory holding err is also incrementally leaked in each failure.
Fix it by reporting the real error and free it.
--- hw/vfio/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/common.c +1 -1
@@ -763,7 +763,7 @@ static void vfio_listener_region_add(MemoryListener *listener, fail:if (memory_region_is_ram_device (section->mr)) { -error_report ("failed to vfio_dma_map. pci p2p may not work" ); +error_reportf_err (err,"PCI p2p may not work: " );return ; }/*
Signature · 1 line
2.34.1
PATCH 2/3 vfio/ap: Remove pointless apdev variable
In reply to Zhenzhong DuanNo need to double-cast, call VFIO_AP_DEVICE() on DeviceState.
No functional changes.
--- hw/vfio/ap.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
hw/vfio/ap.c +3 -6
@@ -156,8 +156,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp) {int ret;Error *err =NULL ; -APDevice *apdev =AP_DEVICE (dev); -VFIOAPDevice *vapdev =VFIO_AP_DEVICE (apdev); +VFIOAPDevice *vapdev =VFIO_AP_DEVICE (dev);VFIODevice *vbasedev = &vapdev->vdev; vbasedev->name =g_path_get_basename (vbasedev->sysfsdev);
@@ -195,8 +194,7 @@ error:static void vfio_ap_unrealize (DeviceState *dev) { -APDevice *apdev =AP_DEVICE (dev); -VFIOAPDevice *vapdev =VFIO_AP_DEVICE (apdev); +VFIOAPDevice *vapdev =VFIO_AP_DEVICE (dev);vfio_ap_unregister_irq_notifier (vapdev,VFIO_AP_REQ_IRQ_INDEX );vfio_detach_device (&vapdev->vdev);
@@ -211,8 +209,7 @@ static Property vfio_ap_properties[] = {static void vfio_ap_reset (DeviceState *dev) {int ret; -APDevice *apdev =AP_DEVICE (dev); -VFIOAPDevice *vapdev =VFIO_AP_DEVICE (apdev); +VFIOAPDevice *vapdev =VFIO_AP_DEVICE (dev); ret =ioctl (vapdev->vdev.fd,VFIO_DEVICE_RESET );if (ret) {
Signature · 1 line
2.34.1
Re: [PATCH 2/3] vfio/ap: Remove pointless apdev variable
Quoted 8 lines · Zhenzhong Duan
No need to double-cast, call
VFIO_AP_DEVICE()on DeviceState.No functional changes.
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/ap.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
Re: [PATCH 2/3] vfio/ap: Remove pointless apdev variable
In reply to Zhenzhong DuanQuoted 43 lines · Zhenzhong Duan
No need to double-cast, call
VFIO_AP_DEVICE()on DeviceState.No functional changes.
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/ap.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)hw/vfio/ap.c +3
-6@@ -156,8 +156,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp) {int ret;Error *err =NULL ; -APDevice *apdev =AP_DEVICE (dev); -VFIOAPDevice *vapdev =VFIO_AP_DEVICE (apdev); +VFIOAPDevice *vapdev =VFIO_AP_DEVICE (dev);VFIODevice *vbasedev = &vapdev->vdev; vbasedev->name =g_path_get_basename (vbasedev->sysfsdev);@@ -195,8 +194,7 @@ error:static void vfio_ap_unrealize (DeviceState *dev) { -APDevice *apdev =AP_DEVICE (dev); -VFIOAPDevice *vapdev =VFIO_AP_DEVICE (apdev); +VFIOAPDevice *vapdev =VFIO_AP_DEVICE (dev);vfio_ap_unregister_irq_notifier (vapdev,VFIO_AP_REQ_IRQ_INDEX );vfio_detach_device (&vapdev->vdev);@@ -211,8 +209,7 @@ static Property vfio_ap_properties[] = {static void vfio_ap_reset (DeviceState *dev) {int ret; -APDevice *apdev =AP_DEVICE (dev); -VFIOAPDevice *vapdev =VFIO_AP_DEVICE (apdev); +VFIOAPDevice *vapdev =VFIO_AP_DEVICE (dev); ret =ioctl (vapdev->vdev.fd,VFIO_DEVICE_RESET );if (ret) {
PATCH 3/3 vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW
In reply to Zhenzhong DuanNo functional changes.
--- include/hw/s390x/vfio-ccw.h | 2 -- 1 file changed, 2 deletions(-)
include/hw/s390x/vfio-ccw.h +0 -2
@@ -22,6 +22,4 @@#define TYPE_VFIO_CCW "vfio-ccw" OBJECT_DECLARE_SIMPLE_TYPE(VFIOCCWDevice, VFIO_CCW) -#define TYPE_VFIO_CCW "vfio-ccw" -#endif
Signature · 1 line
2.34.1
Re: [PATCH 3/3] vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW
Quoted 6 lines · Zhenzhong Duan
No functional changes.
Signed-off-by Zhenzhong Duan <[email protected]>--- include/hw/s390x/vfio-ccw.h | 2 -- 1 file changed, 2 deletions(-)
Re: [PATCH 3/3] vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW
In reply to Zhenzhong DuanQuoted 3 lines · Zhenzhong Duan
No functional changes.
Signed-off-by Zhenzhong Duan <[email protected]>
I see Cedric has already queued this, but FWIW:
Quoted 16 lines
---
include/hw/s390x/vfio-ccw.h | 2 --1 file changed, 2 deletions(-)include/hw/s390x/vfio- renamed from include/hw/s390x/vfio-ccw.h +0
-0
ccw.h
index63a909eb7e..4209d27657100644include/hw/s390x/vfio-ccw.h +0
-0@@ -22,6 +22,4 @@ #define TYPE_VFIO_CCW "vfio-ccw" OBJECT_DECLARE_SIMPLE_TYPE(VFIOCCWDevice, VFIO_CCW)include/hw/s390x/vfio-ccw.h +0
-2-#define TYPE_VFIO_CCW "vfio-ccw" -#endif
Re: [PATCH 3/3] vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW
Quoted 8 lines · Eric Farman
Quoted 3 lines · Zhenzhong Duan
No functional changes.
Signed-off-by Zhenzhong Duan <[email protected]>I see Cedric has already queued this, but FWIW:
Reviewed-by Eric Farman <[email protected]>
I will take the new tags when I rebase.
Thanks,
C.
Quoted 18 lines
Quoted 17 lines
--- include/hw/s390x/vfio-ccw.h | 2 -- 1 file changed, 2 deletions(-)include/hw/s390x/vfio- renamed from include/hw/s390x/vfio-ccw.h +0
-0
ccw.h
index63a909eb7e..4209d27657100644include/hw/s390x/vfio-ccw.h +0
-2@@ -22,6 +22,4 @@ #define TYPE_VFIO_CCW "vfio-ccw" OBJECT_DECLARE_SIMPLE_TYPE(VFIOCCWDevice, VFIO_CCW) -#define TYPE_VFIO_CCW "vfio-ccw" - #endif
Quoted 6 lines · Zhenzhong Duan
Hi,
This trivial patchset fixes a incremental memory leak in rare case, and some cleanup on ap/ccw.
This patchset is based on vfio-next.
Will this apply on the future v5 of Eric ?
Thanks,
C.
Quoted 14 lines
Thanks
ZhenzhongZhenzhong Duan (3):
vfio/pci: Fix a potential memory leak invfio_listener_region_addvfio/ap: Remove pointless apdev variable
vfio/ccw: Remove redundant definition ofTYPE_VFIO_CCWhw/vfio/ap.c | 9 +++------ hw/vfio/common.c | 2 +- include/hw/s390x/vfio-ccw.h | 2 -- 3 files changed, 4 insertions(+), 9 deletions(-)
Quoted 8 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, October 9, 2023 2:32 PM
Subject: Re: [PATCH 0/3] vfio: memory leak fix and code cleanupOn 10/9/23 04:20, Zhenzhong Duan wrote:
Quoted 8 lines
Quoted 6 lines
Hi,
This trivial patchset fixes a incremental memory leak in rare case, and some cleanup on ap/ccw.
This patchset is based on vfio-next.
Will this apply on the future v5 of Eric ?
I think so, though this patchset is applied on v4 of Eric. Let me know if you want a new version without basing on the prerequisite patchset, it’s easy to rebase.
Thanks
Zhenzhong
Quoted 6 lines · Zhenzhong Duan
Hi,
This trivial patchset fixes a incremental memory leak in rare case, and some cleanup on ap/ccw.
This patchset is based on vfio-next.
Applied on vfio-next.
Thanks,
C.