qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/6] qtest: factor out qtest_install_gpio_out_intercepts


From: Peter Maydell
Subject: Re: [PATCH 4/6] qtest: factor out qtest_install_gpio_out_intercepts
Date: Mon, 24 Jul 2023 17:18:02 +0100

On Sat, 15 Jul 2023 at 00:27, Chris Laplante <chris@laplante.io> wrote:
>
> Simplify the code a bit.
>
> Signed-off-by: Chris Laplante <chris@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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]