On Sat, 15 Jul 2023 at 00:27, Chris Laplante <ch...@laplante.io> wrote: > > Simplify the code a bit. > > Signed-off-by: Chris Laplante <ch...@laplante.io> > --- > softmmu/qtest.c | 23 +++++++++++------------ > 1 file changed, 11 insertions(+), 12 deletions(-) > > diff --git a/softmmu/qtest.c b/softmmu/qtest.c > index 74482ce3cd..051bbf4177 100644 > --- a/softmmu/qtest.c > +++ b/softmmu/qtest.c > @@ -365,6 +365,15 @@ void qtest_set_command_cb(bool (*pc_cb)(CharBackend > *chr, gchar **words)) > process_command_cb = pc_cb; > } > > +static void qtest_install_gpio_out_intercepts(DeviceState *dev, const char > *name, int n) > +{ > + qemu_irq *disconnected = g_new0(qemu_irq, 1); > + qemu_irq icpt = qemu_allocate_irq(qtest_irq_handler, > + disconnected, n); > + > + *disconnected = qdev_intercept_gpio_out(dev, icpt,name, n); > +} > + > static void qtest_process_command(CharBackend *chr, gchar **words) > { > const gchar *command; > @@ -421,23 +430,13 @@ static void qtest_process_command(CharBackend *chr, > gchar **words) > if (is_outbound) { > if (is_named) { > if (ngl->name && strcmp(ngl->name, words[2]) == 0) { > - qemu_irq *disconnected = g_new0(qemu_irq, 1); > - qemu_irq icpt = qemu_allocate_irq(qtest_irq_handler, > - disconnected, 0); > - > - *disconnected = qdev_intercept_gpio_out(dev, icpt, > - ngl->name, > 0); > + qtest_install_gpio_out_intercepts(dev, ngl->name, 0); > break; > } > } else if (!ngl->name) { > int i; > for (i = 0; i < ngl->num_out; ++i) { > - qemu_irq *disconnected = g_new0(qemu_irq, 1); > - qemu_irq icpt = qemu_allocate_irq(qtest_irq_handler, > - disconnected, i); > - > - *disconnected = qdev_intercept_gpio_out(dev, icpt, > - ngl->name, > i); > + qtest_install_gpio_out_intercepts(dev, ngl->name, i); > }
I think you should put this patch before patch 2 -- create the new function first, and then you can directly use it, rather than first creating the duplicate code and then getting rid of it. thanks -- PMM