qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Li Qiang <liq3ea@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm@nongnu.org, Qemu Developers <qemu-devel@nongnu.org>
Subject: Re: [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device
Date: Sun, 12 Jul 2020 08:22:08 +0800	[thread overview]
Message-ID: <CAKXe6SKv_QAeo4g+2n4uYO2cztDvV06adPShT6KEqzBGRJs9BQ@mail.gmail.com> (raw)
In-Reply-To: <20200628214230.2592-3-peter.maydell@linaro.org>

Peter Maydell <peter.maydell@linaro.org> 于2020年6月29日周一 上午5:43写道:
>
> Replace the free-floating set of IRQs and palmte_onoff_gpios()
> function with a simple QOM device that encapsulates this
> behaviour.
>
> This fixes Coverity issue CID 1421944, which points out that
> the memory returned by qemu_allocate_irqs() is leaked.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Li Qiang <liq3ea@gmail.com>

> ---
>  hw/arm/palm.c | 61 +++++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 52 insertions(+), 9 deletions(-)
>
> diff --git a/hw/arm/palm.c b/hw/arm/palm.c
> index 569836178f6..e7bc9ea4c6a 100644
> --- a/hw/arm/palm.c
> +++ b/hw/arm/palm.c
> @@ -124,6 +124,21 @@ static void palmte_button_event(void *opaque, int keycode)
>                          !(keycode & 0x80));
>  }
>
> +/*
> + * Encapsulation of some GPIO line behaviour for the Palm board
> + *
> + * QEMU interface:
> + *  + unnamed GPIO inputs 0..6: for the various miscellaneous input lines
> + */
> +
> +#define TYPE_PALM_MISC_GPIO "palm-misc-gpio"
> +#define PALM_MISC_GPIO(obj) \
> +    OBJECT_CHECK(PalmMiscGPIOState, (obj), TYPE_PALM_MISC_GPIO)
> +
> +typedef struct PalmMiscGPIOState {
> +    SysBusDevice parent_obj;
> +} PalmMiscGPIOState;
> +
>  static void palmte_onoff_gpios(void *opaque, int line, int level)
>  {
>      switch (line) {
> @@ -151,23 +166,44 @@ static void palmte_onoff_gpios(void *opaque, int line, int level)
>      }
>  }
>
> +static void palm_misc_gpio_init(Object *obj)
> +{
> +    DeviceState *dev = DEVICE(obj);
> +
> +    qdev_init_gpio_in(dev, palmte_onoff_gpios, 7);
> +}
> +
> +static const TypeInfo palm_misc_gpio_info = {
> +    .name = TYPE_PALM_MISC_GPIO,
> +    .parent = TYPE_SYS_BUS_DEVICE,
> +    .instance_size = sizeof(PalmMiscGPIOState),
> +    .instance_init = palm_misc_gpio_init,
> +    /*
> +     * No class init required: device has no internal state so does not
> +     * need to set up reset or vmstate, and has no realize method.
> +     */
> +};
> +
>  static void palmte_gpio_setup(struct omap_mpu_state_s *cpu)
>  {
> -    qemu_irq *misc_gpio;
> +    DeviceState *misc_gpio;
> +
> +    misc_gpio = sysbus_create_simple(TYPE_PALM_MISC_GPIO, -1, NULL);
>
>      omap_mmc_handlers(cpu->mmc,
>                      qdev_get_gpio_in(cpu->gpio, PALMTE_MMC_WP_GPIO),
>                      qemu_irq_invert(omap_mpuio_in_get(cpu->mpuio)
>                              [PALMTE_MMC_SWITCH_GPIO]));
>
> -    misc_gpio = qemu_allocate_irqs(palmte_onoff_gpios, cpu, 7);
> -    qdev_connect_gpio_out(cpu->gpio, PALMTE_MMC_POWER_GPIO,     misc_gpio[0]);
> -    qdev_connect_gpio_out(cpu->gpio, PALMTE_SPEAKER_GPIO,       misc_gpio[1]);
> -    qdev_connect_gpio_out(cpu->gpio, 11,                        misc_gpio[2]);
> -    qdev_connect_gpio_out(cpu->gpio, 12,                        misc_gpio[3]);
> -    qdev_connect_gpio_out(cpu->gpio, 13,                        misc_gpio[4]);
> -    omap_mpuio_out_set(cpu->mpuio, 1,                           misc_gpio[5]);
> -    omap_mpuio_out_set(cpu->mpuio, 3,                           misc_gpio[6]);
> +    qdev_connect_gpio_out(cpu->gpio, PALMTE_MMC_POWER_GPIO,
> +                          qdev_get_gpio_in(misc_gpio, 0));
> +    qdev_connect_gpio_out(cpu->gpio, PALMTE_SPEAKER_GPIO,
> +                          qdev_get_gpio_in(misc_gpio, 1));
> +    qdev_connect_gpio_out(cpu->gpio, 11, qdev_get_gpio_in(misc_gpio, 2));
> +    qdev_connect_gpio_out(cpu->gpio, 12, qdev_get_gpio_in(misc_gpio, 3));
> +    qdev_connect_gpio_out(cpu->gpio, 13, qdev_get_gpio_in(misc_gpio, 4));
> +    omap_mpuio_out_set(cpu->mpuio, 1, qdev_get_gpio_in(misc_gpio, 5));
> +    omap_mpuio_out_set(cpu->mpuio, 3, qdev_get_gpio_in(misc_gpio, 6));
>
>      /* Reset some inputs to initial state.  */
>      qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_USBDETECT_GPIO));
> @@ -276,3 +312,10 @@ static void palmte_machine_init(MachineClass *mc)
>  }
>
>  DEFINE_MACHINE("cheetah", palmte_machine_init)
> +
> +static void palm_register_types(void)
> +{
> +    type_register_static(&palm_misc_gpio_info);
> +}
> +
> +type_init(palm_register_types)
> --
> 2.20.1
>
>


  reply	other threads:[~2020-07-12  0:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-28 21:42 [PATCH 0/2] hw/arm/palm.c: Fix Coverity issue CID 1421944 Peter Maydell
2020-06-28 21:42 ` [PATCH 1/2] hw/arm/palm.c: Detabify Peter Maydell
2020-07-12  0:18   ` Li Qiang
2020-07-13 10:49   ` Philippe Mathieu-Daudé
2020-06-28 21:42 ` [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device Peter Maydell
2020-07-12  0:22   ` Li Qiang [this message]
2020-07-13  8:57   ` Philippe Mathieu-Daudé
2020-07-13 10:05     ` Peter Maydell
2020-07-13 10:21       ` Philippe Mathieu-Daudé
2020-07-13 10:31         ` Peter Maydell
2020-07-13 10:52           ` Philippe Mathieu-Daudé
2020-07-11 18:33 ` [PATCH 0/2] hw/arm/palm.c: Fix Coverity issue CID 1421944 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKXe6SKv_QAeo4g+2n4uYO2cztDvV06adPShT6KEqzBGRJs9BQ@mail.gmail.com \
    --to=liq3ea@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).