* [PATCH 0/2] hw: fix some leaks in xlnx devices
@ 2025-08-26 17:49 Peter Maydell
  2025-08-26 17:49 ` [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit Peter Maydell
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Peter Maydell @ 2025-08-26 17:49 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alistair Francis, Edgar E. Iglesias, Francisco Iglesias
These patches fix some minor leaks in xlnx devices detected
by running 'make check' under ASAN.
thanks
-- PMM
Peter Maydell (2):
  hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit
  hw/display/xlnx_dp: Don't leak dpcd and edid objects
 hw/display/xlnx_dp.c             | 10 +++++++---
 hw/misc/xlnx-versal-cframe-reg.c |  9 +++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)
-- 
2.43.0
^ permalink raw reply	[flat|nested] 10+ messages in thread* [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit 2025-08-26 17:49 [PATCH 0/2] hw: fix some leaks in xlnx devices Peter Maydell @ 2025-08-26 17:49 ` Peter Maydell 2025-08-26 17:56 ` Edgar E. Iglesias ` (2 more replies) 2025-08-26 17:49 ` [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects Peter Maydell 2025-08-29 16:37 ` [PATCH 0/2] hw: fix some leaks in xlnx devices Philippe Mathieu-Daudé 2 siblings, 3 replies; 10+ messages in thread From: Peter Maydell @ 2025-08-26 17:49 UTC (permalink / raw) To: qemu-arm, qemu-devel Cc: Alistair Francis, Edgar E. Iglesias, Francisco Iglesias In the xlnx-versal-cframe-reg device we create a FIFO in instance_init but don't destroy it on deinit, causing ASAN to report a leak in the device-introspect-test: Direct leak of 400 byte(s) in 1 object(s) allocated from: #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c53fecd904ba5fc1f521d7da080a0e4103b) #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) #2 0x5aded850059d in fifo8_create /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../util/fifo8.c:27:18 #3 0x5aded582b9e4 in fifo32_create /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/qemu/fifo32.h:35:5 #4 0x5aded582b326 in cframe_reg_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/misc/xlnx-versal-cframe-reg.c:693:5 Similarly, we don't clean up the g_tree we create: Direct leak of 48 byte(s) in 1 object(s) allocated from: #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c5 3fecd904ba5fc1f521d7da080a0e4103b) #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) #2 0x71fbfaccc799 in g_tree_new_full (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x93799) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d7 5) #3 0x5aded582b21a in cframe_reg_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/misc/xlnx-versal-cframe-reg.c:691:18 Add an instance_finalize method to clean up what we allocated in instance_init. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> --- hw/misc/xlnx-versal-cframe-reg.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/misc/xlnx-versal-cframe-reg.c b/hw/misc/xlnx-versal-cframe-reg.c index 1ce083e2409..95e167b9213 100644 --- a/hw/misc/xlnx-versal-cframe-reg.c +++ b/hw/misc/xlnx-versal-cframe-reg.c @@ -693,6 +693,14 @@ static void cframe_reg_init(Object *obj) fifo32_create(&s->new_f_data, FRAME_NUM_WORDS); } +static void cframe_reg_finalize(Object *obj) +{ + XlnxVersalCFrameReg *s = XLNX_VERSAL_CFRAME_REG(obj); + + fifo32_destroy(&s->new_f_data); + g_tree_destroy(s->cframes); +} + static const VMStateDescription vmstate_cframe = { .name = "cframe", .version_id = 1, @@ -833,6 +841,7 @@ static const TypeInfo cframe_reg_info = { .instance_size = sizeof(XlnxVersalCFrameReg), .class_init = cframe_reg_class_init, .instance_init = cframe_reg_init, + .instance_finalize = cframe_reg_finalize, .interfaces = (const InterfaceInfo[]) { { TYPE_XLNX_CFI_IF }, { } -- 2.43.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit 2025-08-26 17:49 ` [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit Peter Maydell @ 2025-08-26 17:56 ` Edgar E. Iglesias 2025-08-26 19:23 ` Manos Pitsidianakis 2025-08-26 19:43 ` Francisco Iglesias 2 siblings, 0 replies; 10+ messages in thread From: Edgar E. Iglesias @ 2025-08-26 17:56 UTC (permalink / raw) To: Peter Maydell; +Cc: qemu-arm, qemu-devel, Alistair Francis, Francisco Iglesias On Tue, Aug 26, 2025 at 06:49:55PM +0100, Peter Maydell wrote: > In the xlnx-versal-cframe-reg device we create a FIFO in > instance_init but don't destroy it on deinit, causing ASAN > to report a leak in the device-introspect-test: > > Direct leak of 400 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c53fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x5aded850059d in fifo8_create /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../util/fifo8.c:27:18 > #3 0x5aded582b9e4 in fifo32_create /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/qemu/fifo32.h:35:5 > #4 0x5aded582b326 in cframe_reg_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/misc/xlnx-versal-cframe-reg.c:693:5 > > Similarly, we don't clean up the g_tree we create: > Direct leak of 48 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c5 > 3fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x71fbfaccc799 in g_tree_new_full (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x93799) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d7 > 5) > #3 0x5aded582b21a in cframe_reg_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/misc/xlnx-versal-cframe-reg.c:691:18 > > Add an instance_finalize method to clean up what we > allocated in instance_init. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> > --- > hw/misc/xlnx-versal-cframe-reg.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/hw/misc/xlnx-versal-cframe-reg.c b/hw/misc/xlnx-versal-cframe-reg.c > index 1ce083e2409..95e167b9213 100644 > --- a/hw/misc/xlnx-versal-cframe-reg.c > +++ b/hw/misc/xlnx-versal-cframe-reg.c > @@ -693,6 +693,14 @@ static void cframe_reg_init(Object *obj) > fifo32_create(&s->new_f_data, FRAME_NUM_WORDS); > } > > +static void cframe_reg_finalize(Object *obj) > +{ > + XlnxVersalCFrameReg *s = XLNX_VERSAL_CFRAME_REG(obj); > + > + fifo32_destroy(&s->new_f_data); > + g_tree_destroy(s->cframes); > +} > + > static const VMStateDescription vmstate_cframe = { > .name = "cframe", > .version_id = 1, > @@ -833,6 +841,7 @@ static const TypeInfo cframe_reg_info = { > .instance_size = sizeof(XlnxVersalCFrameReg), > .class_init = cframe_reg_class_init, > .instance_init = cframe_reg_init, > + .instance_finalize = cframe_reg_finalize, > .interfaces = (const InterfaceInfo[]) { > { TYPE_XLNX_CFI_IF }, > { } > -- > 2.43.0 > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit 2025-08-26 17:49 ` [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit Peter Maydell 2025-08-26 17:56 ` Edgar E. Iglesias @ 2025-08-26 19:23 ` Manos Pitsidianakis 2025-08-26 19:43 ` Francisco Iglesias 2 siblings, 0 replies; 10+ messages in thread From: Manos Pitsidianakis @ 2025-08-26 19:23 UTC (permalink / raw) To: Peter Maydell Cc: qemu-arm, qemu-devel, Alistair Francis, Edgar E. Iglesias, Francisco Iglesias On Tue, Aug 26, 2025 at 8:51 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > In the xlnx-versal-cframe-reg device we create a FIFO in > instance_init but don't destroy it on deinit, causing ASAN > to report a leak in the device-introspect-test: > > Direct leak of 400 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c53fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x5aded850059d in fifo8_create /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../util/fifo8.c:27:18 > #3 0x5aded582b9e4 in fifo32_create /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/qemu/fifo32.h:35:5 > #4 0x5aded582b326 in cframe_reg_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/misc/xlnx-versal-cframe-reg.c:693:5 > > Similarly, we don't clean up the g_tree we create: > Direct leak of 48 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c5 > 3fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x71fbfaccc799 in g_tree_new_full (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x93799) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d7 > 5) > #3 0x5aded582b21a in cframe_reg_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/misc/xlnx-versal-cframe-reg.c:691:18 > > Add an instance_finalize method to clean up what we > allocated in instance_init. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> > --- > hw/misc/xlnx-versal-cframe-reg.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/hw/misc/xlnx-versal-cframe-reg.c b/hw/misc/xlnx-versal-cframe-reg.c > index 1ce083e2409..95e167b9213 100644 > --- a/hw/misc/xlnx-versal-cframe-reg.c > +++ b/hw/misc/xlnx-versal-cframe-reg.c > @@ -693,6 +693,14 @@ static void cframe_reg_init(Object *obj) > fifo32_create(&s->new_f_data, FRAME_NUM_WORDS); > } > > +static void cframe_reg_finalize(Object *obj) > +{ > + XlnxVersalCFrameReg *s = XLNX_VERSAL_CFRAME_REG(obj); > + > + fifo32_destroy(&s->new_f_data); > + g_tree_destroy(s->cframes); > +} > + > static const VMStateDescription vmstate_cframe = { > .name = "cframe", > .version_id = 1, > @@ -833,6 +841,7 @@ static const TypeInfo cframe_reg_info = { > .instance_size = sizeof(XlnxVersalCFrameReg), > .class_init = cframe_reg_class_init, > .instance_init = cframe_reg_init, > + .instance_finalize = cframe_reg_finalize, > .interfaces = (const InterfaceInfo[]) { > { TYPE_XLNX_CFI_IF }, > { } > -- > 2.43.0 > > Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit 2025-08-26 17:49 ` [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit Peter Maydell 2025-08-26 17:56 ` Edgar E. Iglesias 2025-08-26 19:23 ` Manos Pitsidianakis @ 2025-08-26 19:43 ` Francisco Iglesias 2 siblings, 0 replies; 10+ messages in thread From: Francisco Iglesias @ 2025-08-26 19:43 UTC (permalink / raw) To: Peter Maydell; +Cc: qemu-arm, qemu-devel, Alistair Francis, Edgar E. Iglesias On Tue, Aug 26, 2025 at 06:49:55PM +0100, Peter Maydell wrote: > In the xlnx-versal-cframe-reg device we create a FIFO in > instance_init but don't destroy it on deinit, causing ASAN > to report a leak in the device-introspect-test: > > Direct leak of 400 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c53fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x5aded850059d in fifo8_create /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../util/fifo8.c:27:18 > #3 0x5aded582b9e4 in fifo32_create /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/include/qemu/fifo32.h:35:5 > #4 0x5aded582b326 in cframe_reg_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/misc/xlnx-versal-cframe-reg.c:693:5 > > Similarly, we don't clean up the g_tree we create: > Direct leak of 48 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c5 > 3fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x71fbfaccc799 in g_tree_new_full (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x93799) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d7 > 5) > #3 0x5aded582b21a in cframe_reg_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/misc/xlnx-versal-cframe-reg.c:691:18 > > Add an instance_finalize method to clean up what we > allocated in instance_init. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Francisco Iglesias <francisco.iglesias@amd.com> > --- > hw/misc/xlnx-versal-cframe-reg.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/hw/misc/xlnx-versal-cframe-reg.c b/hw/misc/xlnx-versal-cframe-reg.c > index 1ce083e2409..95e167b9213 100644 > --- a/hw/misc/xlnx-versal-cframe-reg.c > +++ b/hw/misc/xlnx-versal-cframe-reg.c > @@ -693,6 +693,14 @@ static void cframe_reg_init(Object *obj) > fifo32_create(&s->new_f_data, FRAME_NUM_WORDS); > } > > +static void cframe_reg_finalize(Object *obj) > +{ > + XlnxVersalCFrameReg *s = XLNX_VERSAL_CFRAME_REG(obj); > + > + fifo32_destroy(&s->new_f_data); > + g_tree_destroy(s->cframes); > +} > + > static const VMStateDescription vmstate_cframe = { > .name = "cframe", > .version_id = 1, > @@ -833,6 +841,7 @@ static const TypeInfo cframe_reg_info = { > .instance_size = sizeof(XlnxVersalCFrameReg), > .class_init = cframe_reg_class_init, > .instance_init = cframe_reg_init, > + .instance_finalize = cframe_reg_finalize, > .interfaces = (const InterfaceInfo[]) { > { TYPE_XLNX_CFI_IF }, > { } > -- > 2.43.0 > ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects 2025-08-26 17:49 [PATCH 0/2] hw: fix some leaks in xlnx devices Peter Maydell 2025-08-26 17:49 ` [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit Peter Maydell @ 2025-08-26 17:49 ` Peter Maydell 2025-08-26 17:58 ` Edgar E. Iglesias ` (2 more replies) 2025-08-29 16:37 ` [PATCH 0/2] hw: fix some leaks in xlnx devices Philippe Mathieu-Daudé 2 siblings, 3 replies; 10+ messages in thread From: Peter Maydell @ 2025-08-26 17:49 UTC (permalink / raw) To: qemu-arm, qemu-devel Cc: Alistair Francis, Edgar E. Iglesias, Francisco Iglesias In the xnlx_dp_init() function we create the s->dpcd and s->edid objects with qdev_new(); then in xlnx_dp_realize() we realize the dpcd with qdev_realize() and the edid with qdev_realize_and_unref(). This is inconsistent, and both ways result in a memory leak for the instance_init -> deinit lifecycle tested by device-introspect-test: Indirect leak of 1968 byte(s) in 1 object(s) allocated from: #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c5 3fecd904ba5fc1f521d7da080a0e4103b) #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) #2 0x5aded7b9211c in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:767:15 #3 0x5aded7b92240 in object_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:789:12 #4 0x5aded7b773e4 in qdev_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/core/qdev.c:149:19 #5 0x5aded54458be in xlnx_dp_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/display/xlnx_dp.c:1272:20 Direct leak of 344 byte(s) in 1 object(s) allocated from: #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c53fecd904ba5fc1f521d7da080a0e4103b) #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) #2 0x5aded7b9211c in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:767:15 #3 0x5aded7b92240 in object_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:789:12 #4 0x5aded7b773e4 in qdev_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/core/qdev.c:149:19 #5 0x5aded5445a56 in xlnx_dp_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/display/xlnx_dp.c:1275:22 Instead, explicitly object_unref() after we have added the objects as child properties of the device. This means they will automatically be freed when this device is deinited. When we do this, qdev_realize() is the correct way to realize them in xlnx_dp_realize(). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> --- hw/display/xlnx_dp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/display/xlnx_dp.c b/hw/display/xlnx_dp.c index 7c980ee6423..ef73e1815fc 100644 --- a/hw/display/xlnx_dp.c +++ b/hw/display/xlnx_dp.c @@ -1267,14 +1267,18 @@ static void xlnx_dp_init(Object *obj) s->aux_bus = aux_bus_init(DEVICE(obj), "aux"); /* - * Initialize DPCD and EDID.. + * Initialize DPCD and EDID. Once we have added the objects as + * child properties of this device, we can drop the reference we + * hold to them, leaving the child-property as the only reference. */ s->dpcd = DPCD(qdev_new("dpcd")); object_property_add_child(OBJECT(s), "dpcd", OBJECT(s->dpcd)); + object_unref(s->dpcd); s->edid = I2CDDC(qdev_new("i2c-ddc")); i2c_slave_set_address(I2C_SLAVE(s->edid), 0x50); object_property_add_child(OBJECT(s), "edid", OBJECT(s->edid)); + object_unref(s->edid); fifo8_create(&s->rx_fifo, 16); fifo8_create(&s->tx_fifo, 16); @@ -1311,8 +1315,8 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp) qdev_realize(DEVICE(s->dpcd), BUS(s->aux_bus), &error_fatal); aux_map_slave(AUX_SLAVE(s->dpcd), 0x0000); - qdev_realize_and_unref(DEVICE(s->edid), BUS(aux_get_i2c_bus(s->aux_bus)), - &error_fatal); + qdev_realize(DEVICE(s->edid), BUS(aux_get_i2c_bus(s->aux_bus)), + &error_fatal); s->console = graphic_console_init(dev, 0, &xlnx_dp_gfx_ops, s); surface = qemu_console_surface(s->console); -- 2.43.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects 2025-08-26 17:49 ` [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects Peter Maydell @ 2025-08-26 17:58 ` Edgar E. Iglesias 2025-08-26 19:22 ` Manos Pitsidianakis 2025-08-26 19:50 ` Francisco Iglesias 2 siblings, 0 replies; 10+ messages in thread From: Edgar E. Iglesias @ 2025-08-26 17:58 UTC (permalink / raw) To: Peter Maydell; +Cc: qemu-arm, qemu-devel, Alistair Francis, Francisco Iglesias On Tue, Aug 26, 2025 at 06:49:56PM +0100, Peter Maydell wrote: > In the xnlx_dp_init() function we create the s->dpcd and > s->edid objects with qdev_new(); then in xlnx_dp_realize() > we realize the dpcd with qdev_realize() and the edid with > qdev_realize_and_unref(). > > This is inconsistent, and both ways result in a memory > leak for the instance_init -> deinit lifecycle tested > by device-introspect-test: > > Indirect leak of 1968 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c5 > 3fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x5aded7b9211c in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:767:15 > #3 0x5aded7b92240 in object_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:789:12 > #4 0x5aded7b773e4 in qdev_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/core/qdev.c:149:19 > #5 0x5aded54458be in xlnx_dp_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/display/xlnx_dp.c:1272:20 > > Direct leak of 344 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c53fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x5aded7b9211c in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:767:15 > #3 0x5aded7b92240 in object_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:789:12 > #4 0x5aded7b773e4 in qdev_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/core/qdev.c:149:19 > #5 0x5aded5445a56 in xlnx_dp_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/display/xlnx_dp.c:1275:22 > > Instead, explicitly object_unref() after we have added the objects as > child properties of the device. This means they will automatically > be freed when this device is deinited. When we do this, > qdev_realize() is the correct way to realize them in > xlnx_dp_realize(). > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> > --- > hw/display/xlnx_dp.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/hw/display/xlnx_dp.c b/hw/display/xlnx_dp.c > index 7c980ee6423..ef73e1815fc 100644 > --- a/hw/display/xlnx_dp.c > +++ b/hw/display/xlnx_dp.c > @@ -1267,14 +1267,18 @@ static void xlnx_dp_init(Object *obj) > s->aux_bus = aux_bus_init(DEVICE(obj), "aux"); > > /* > - * Initialize DPCD and EDID.. > + * Initialize DPCD and EDID. Once we have added the objects as > + * child properties of this device, we can drop the reference we > + * hold to them, leaving the child-property as the only reference. > */ > s->dpcd = DPCD(qdev_new("dpcd")); > object_property_add_child(OBJECT(s), "dpcd", OBJECT(s->dpcd)); > + object_unref(s->dpcd); > > s->edid = I2CDDC(qdev_new("i2c-ddc")); > i2c_slave_set_address(I2C_SLAVE(s->edid), 0x50); > object_property_add_child(OBJECT(s), "edid", OBJECT(s->edid)); > + object_unref(s->edid); > > fifo8_create(&s->rx_fifo, 16); > fifo8_create(&s->tx_fifo, 16); > @@ -1311,8 +1315,8 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp) > qdev_realize(DEVICE(s->dpcd), BUS(s->aux_bus), &error_fatal); > aux_map_slave(AUX_SLAVE(s->dpcd), 0x0000); > > - qdev_realize_and_unref(DEVICE(s->edid), BUS(aux_get_i2c_bus(s->aux_bus)), > - &error_fatal); > + qdev_realize(DEVICE(s->edid), BUS(aux_get_i2c_bus(s->aux_bus)), > + &error_fatal); > > s->console = graphic_console_init(dev, 0, &xlnx_dp_gfx_ops, s); > surface = qemu_console_surface(s->console); > -- > 2.43.0 > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects 2025-08-26 17:49 ` [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects Peter Maydell 2025-08-26 17:58 ` Edgar E. Iglesias @ 2025-08-26 19:22 ` Manos Pitsidianakis 2025-08-26 19:50 ` Francisco Iglesias 2 siblings, 0 replies; 10+ messages in thread From: Manos Pitsidianakis @ 2025-08-26 19:22 UTC (permalink / raw) To: Peter Maydell Cc: qemu-arm, qemu-devel, Alistair Francis, Edgar E. Iglesias, Francisco Iglesias On Tue, Aug 26, 2025 at 8:51 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > In the xnlx_dp_init() function we create the s->dpcd and > s->edid objects with qdev_new(); then in xlnx_dp_realize() > we realize the dpcd with qdev_realize() and the edid with > qdev_realize_and_unref(). > > This is inconsistent, and both ways result in a memory > leak for the instance_init -> deinit lifecycle tested > by device-introspect-test: > > Indirect leak of 1968 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c5 > 3fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x5aded7b9211c in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:767:15 > #3 0x5aded7b92240 in object_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:789:12 > #4 0x5aded7b773e4 in qdev_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/core/qdev.c:149:19 > #5 0x5aded54458be in xlnx_dp_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/display/xlnx_dp.c:1272:20 > > Direct leak of 344 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c53fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x5aded7b9211c in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:767:15 > #3 0x5aded7b92240 in object_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:789:12 > #4 0x5aded7b773e4 in qdev_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/core/qdev.c:149:19 > #5 0x5aded5445a56 in xlnx_dp_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/display/xlnx_dp.c:1275:22 > > Instead, explicitly object_unref() after we have added the objects as > child properties of the device. This means they will automatically > be freed when this device is deinited. When we do this, > qdev_realize() is the correct way to realize them in > xlnx_dp_realize(). > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> > --- > hw/display/xlnx_dp.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/hw/display/xlnx_dp.c b/hw/display/xlnx_dp.c > index 7c980ee6423..ef73e1815fc 100644 > --- a/hw/display/xlnx_dp.c > +++ b/hw/display/xlnx_dp.c > @@ -1267,14 +1267,18 @@ static void xlnx_dp_init(Object *obj) > s->aux_bus = aux_bus_init(DEVICE(obj), "aux"); > > /* > - * Initialize DPCD and EDID.. > + * Initialize DPCD and EDID. Once we have added the objects as > + * child properties of this device, we can drop the reference we > + * hold to them, leaving the child-property as the only reference. > */ > s->dpcd = DPCD(qdev_new("dpcd")); > object_property_add_child(OBJECT(s), "dpcd", OBJECT(s->dpcd)); > + object_unref(s->dpcd); > > s->edid = I2CDDC(qdev_new("i2c-ddc")); > i2c_slave_set_address(I2C_SLAVE(s->edid), 0x50); > object_property_add_child(OBJECT(s), "edid", OBJECT(s->edid)); > + object_unref(s->edid); > > fifo8_create(&s->rx_fifo, 16); > fifo8_create(&s->tx_fifo, 16); > @@ -1311,8 +1315,8 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp) > qdev_realize(DEVICE(s->dpcd), BUS(s->aux_bus), &error_fatal); > aux_map_slave(AUX_SLAVE(s->dpcd), 0x0000); > > - qdev_realize_and_unref(DEVICE(s->edid), BUS(aux_get_i2c_bus(s->aux_bus)), > - &error_fatal); > + qdev_realize(DEVICE(s->edid), BUS(aux_get_i2c_bus(s->aux_bus)), > + &error_fatal); > > s->console = graphic_console_init(dev, 0, &xlnx_dp_gfx_ops, s); > surface = qemu_console_surface(s->console); > -- Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> > 2.43.0 > > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects 2025-08-26 17:49 ` [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects Peter Maydell 2025-08-26 17:58 ` Edgar E. Iglesias 2025-08-26 19:22 ` Manos Pitsidianakis @ 2025-08-26 19:50 ` Francisco Iglesias 2 siblings, 0 replies; 10+ messages in thread From: Francisco Iglesias @ 2025-08-26 19:50 UTC (permalink / raw) To: Peter Maydell; +Cc: qemu-arm, qemu-devel, Alistair Francis, Edgar E. Iglesias On Tue, Aug 26, 2025 at 06:49:56PM +0100, Peter Maydell wrote: > In the xnlx_dp_init() function we create the s->dpcd and > s->edid objects with qdev_new(); then in xlnx_dp_realize() > we realize the dpcd with qdev_realize() and the edid with > qdev_realize_and_unref(). > > This is inconsistent, and both ways result in a memory > leak for the instance_init -> deinit lifecycle tested > by device-introspect-test: > > Indirect leak of 1968 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c5 > 3fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x5aded7b9211c in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:767:15 > #3 0x5aded7b92240 in object_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:789:12 > #4 0x5aded7b773e4 in qdev_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/core/qdev.c:149:19 > #5 0x5aded54458be in xlnx_dp_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/display/xlnx_dp.c:1272:20 > > Direct leak of 344 byte(s) in 1 object(s) allocated from: > #0 0x5aded4d54e23 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/qemu-system-aarch64+0x24ffe23) (BuildId: 9f1e6c53fecd904ba5fc1f521d7da080a0e4103b) > #1 0x71fbfac9bb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75) > #2 0x5aded7b9211c in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:767:15 > #3 0x5aded7b92240 in object_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../qom/object.c:789:12 > #4 0x5aded7b773e4 in qdev_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/core/qdev.c:149:19 > #5 0x5aded5445a56 in xlnx_dp_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/arm-asan/../../hw/display/xlnx_dp.c:1275:22 > > Instead, explicitly object_unref() after we have added the objects as > child properties of the device. This means they will automatically > be freed when this device is deinited. When we do this, > qdev_realize() is the correct way to realize them in > xlnx_dp_realize(). > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Francisco Iglesias <francisco.iglesias@amd.com> > --- > hw/display/xlnx_dp.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/hw/display/xlnx_dp.c b/hw/display/xlnx_dp.c > index 7c980ee6423..ef73e1815fc 100644 > --- a/hw/display/xlnx_dp.c > +++ b/hw/display/xlnx_dp.c > @@ -1267,14 +1267,18 @@ static void xlnx_dp_init(Object *obj) > s->aux_bus = aux_bus_init(DEVICE(obj), "aux"); > > /* > - * Initialize DPCD and EDID.. > + * Initialize DPCD and EDID. Once we have added the objects as > + * child properties of this device, we can drop the reference we > + * hold to them, leaving the child-property as the only reference. > */ > s->dpcd = DPCD(qdev_new("dpcd")); > object_property_add_child(OBJECT(s), "dpcd", OBJECT(s->dpcd)); > + object_unref(s->dpcd); > > s->edid = I2CDDC(qdev_new("i2c-ddc")); > i2c_slave_set_address(I2C_SLAVE(s->edid), 0x50); > object_property_add_child(OBJECT(s), "edid", OBJECT(s->edid)); > + object_unref(s->edid); > > fifo8_create(&s->rx_fifo, 16); > fifo8_create(&s->tx_fifo, 16); > @@ -1311,8 +1315,8 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp) > qdev_realize(DEVICE(s->dpcd), BUS(s->aux_bus), &error_fatal); > aux_map_slave(AUX_SLAVE(s->dpcd), 0x0000); > > - qdev_realize_and_unref(DEVICE(s->edid), BUS(aux_get_i2c_bus(s->aux_bus)), > - &error_fatal); > + qdev_realize(DEVICE(s->edid), BUS(aux_get_i2c_bus(s->aux_bus)), > + &error_fatal); > > s->console = graphic_console_init(dev, 0, &xlnx_dp_gfx_ops, s); > surface = qemu_console_surface(s->console); > -- > 2.43.0 > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] hw: fix some leaks in xlnx devices 2025-08-26 17:49 [PATCH 0/2] hw: fix some leaks in xlnx devices Peter Maydell 2025-08-26 17:49 ` [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit Peter Maydell 2025-08-26 17:49 ` [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects Peter Maydell @ 2025-08-29 16:37 ` Philippe Mathieu-Daudé 2 siblings, 0 replies; 10+ messages in thread From: Philippe Mathieu-Daudé @ 2025-08-29 16:37 UTC (permalink / raw) To: Peter Maydell, qemu-arm, qemu-devel Cc: Alistair Francis, Edgar E. Iglesias, Francisco Iglesias On 26/8/25 19:49, Peter Maydell wrote: > Peter Maydell (2): > hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit > hw/display/xlnx_dp: Don't leak dpcd and edid objects Series queued, thanks. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-08-30 16:08 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-08-26 17:49 [PATCH 0/2] hw: fix some leaks in xlnx devices Peter Maydell 2025-08-26 17:49 ` [PATCH 1/2] hw/misc/xlnx-versal-cframe-reg: Free FIFO, g_tree on deinit Peter Maydell 2025-08-26 17:56 ` Edgar E. Iglesias 2025-08-26 19:23 ` Manos Pitsidianakis 2025-08-26 19:43 ` Francisco Iglesias 2025-08-26 17:49 ` [PATCH 2/2] hw/display/xlnx_dp: Don't leak dpcd and edid objects Peter Maydell 2025-08-26 17:58 ` Edgar E. Iglesias 2025-08-26 19:22 ` Manos Pitsidianakis 2025-08-26 19:50 ` Francisco Iglesias 2025-08-29 16:37 ` [PATCH 0/2] hw: fix some leaks in xlnx devices Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).