On 30/10/23 15:25, Markus Armbruster wrote:
Philippe Mathieu-Daudé <phi...@linaro.org> writes:
Hi Peter,
Cc'ing Markus for QObject.
On 30/10/23 12:48, Peter Maydell wrote:
Convert the hw/input/stellaris_input device to qdev.
The interface uses an array property for the board to specify the
keycodes to use, so the s->keycodes memory is now allocated by the
array-property machinery.
Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <phi...@linaro.org>
Tested-by: Philippe Mathieu-Daudé <phi...@linaro.org>
---
v1->v2: drop private/public comment lines
---
include/hw/input/stellaris_gamepad.h | 22 ++++++++-
hw/arm/stellaris.c | 26 +++++++---
hw/input/stellaris_gamepad.c | 73 +++++++++++++++++++---------
3 files changed, 89 insertions(+), 32 deletions(-)
diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index 96585dd7106..707b0dae375 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -31,6 +31,7 @@
#include "hw/timer/stellaris-gptm.h"
#include "hw/qdev-clock.h"
#include "qom/object.h"
+#include "qapi/qmp/qlist.h"
#define GPIO_A 0
#define GPIO_B 1
@@ -1274,16 +1275,27 @@ static void stellaris_init(MachineState *ms,
stellaris_board_info *board)
sysbus_connect_irq(SYS_BUS_DEVICE(enet), 0, qdev_get_gpio_in(nvic,
42));
}
if (board->peripherals & BP_GAMEPAD) {
- qemu_irq gpad_irq[5];
+ QList *gpad_keycode_list = qlist_new();
I'm trying to understand better qlist_new(), but unfortunately there
is not much documentation. Looking at how the allocated list was
released, I found use of g_autoptr in tests/unit/check-qobject.c,
so I tried:
g_autoptr(QList) gpad_keycode_list = qlist_new();
QObject and its subtypes QDict, QList, QString, ... are reference
counted. qFOO_new() ist to be paired with qFOO_unref() or
qobject_unref().
Your use of g_autoptr(QList) should work.
Peter figured qdev_prop_set_array() takes the ownership, so using
g_autoptr triggers a double-free:
https://lore.kernel.org/qemu-devel/cafeaca_gc8ypm2y94kcu9q_dntf6na+igu-+0jzj+mvpfe_...@mail.gmail.com/