* [PATCH 0/2] hw/arm/palm.c: Fix Coverity issue CID 1421944 @ 2020-06-28 21:42 Peter Maydell 2020-06-28 21:42 ` [PATCH 1/2] hw/arm/palm.c: Detabify Peter Maydell ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Peter Maydell @ 2020-06-28 21:42 UTC (permalink / raw) To: qemu-arm, qemu-devel As for spitz and tosa, fix the Coverity issue CID 1421944 which points out that memory returned from qemu_allocate_irqs() is leaked by encapsulating the GPIO handling into a simple device. As with the other series, detabify the file first. thanks -- PMM Peter Maydell (2): hw/arm/palm.c: Detabify hw/arm/palm.c: Encapsulate misc GPIO handling in a device hw/arm/palm.c | 111 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 34 deletions(-) -- 2.20.1 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/2] hw/arm/palm.c: Detabify 2020-06-28 21:42 [PATCH 0/2] hw/arm/palm.c: Fix Coverity issue CID 1421944 Peter Maydell @ 2020-06-28 21:42 ` 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-11 18:33 ` [PATCH 0/2] hw/arm/palm.c: Fix Coverity issue CID 1421944 Peter Maydell 2 siblings, 2 replies; 12+ messages in thread From: Peter Maydell @ 2020-06-28 21:42 UTC (permalink / raw) To: qemu-arm, qemu-devel Remove hard-tabs from palm.c. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> --- hw/arm/palm.c | 64 +++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/hw/arm/palm.c b/hw/arm/palm.c index 97ca105d297..569836178f6 100644 --- a/hw/arm/palm.c +++ b/hw/arm/palm.c @@ -61,21 +61,21 @@ static const MemoryRegionOps static_ops = { /* Palm Tunsgten|E support */ /* Shared GPIOs */ -#define PALMTE_USBDETECT_GPIO 0 -#define PALMTE_USB_OR_DC_GPIO 1 -#define PALMTE_TSC_GPIO 4 -#define PALMTE_PINTDAV_GPIO 6 -#define PALMTE_MMC_WP_GPIO 8 -#define PALMTE_MMC_POWER_GPIO 9 -#define PALMTE_HDQ_GPIO 11 -#define PALMTE_HEADPHONES_GPIO 14 -#define PALMTE_SPEAKER_GPIO 15 +#define PALMTE_USBDETECT_GPIO 0 +#define PALMTE_USB_OR_DC_GPIO 1 +#define PALMTE_TSC_GPIO 4 +#define PALMTE_PINTDAV_GPIO 6 +#define PALMTE_MMC_WP_GPIO 8 +#define PALMTE_MMC_POWER_GPIO 9 +#define PALMTE_HDQ_GPIO 11 +#define PALMTE_HEADPHONES_GPIO 14 +#define PALMTE_SPEAKER_GPIO 15 /* MPU private GPIOs */ -#define PALMTE_DC_GPIO 2 -#define PALMTE_MMC_SWITCH_GPIO 4 -#define PALMTE_MMC1_GPIO 6 -#define PALMTE_MMC2_GPIO 7 -#define PALMTE_MMC3_GPIO 11 +#define PALMTE_DC_GPIO 2 +#define PALMTE_MMC_SWITCH_GPIO 4 +#define PALMTE_MMC1_GPIO 6 +#define PALMTE_MMC2_GPIO 7 +#define PALMTE_MMC3_GPIO 11 static MouseTransformInfo palmte_pointercal = { .x = 320, @@ -100,17 +100,17 @@ static struct { int column; } palmte_keymap[0x80] = { [0 ... 0x7f] = { -1, -1 }, - [0x3b] = { 0, 0 }, /* F1 -> Calendar */ - [0x3c] = { 1, 0 }, /* F2 -> Contacts */ - [0x3d] = { 2, 0 }, /* F3 -> Tasks List */ - [0x3e] = { 3, 0 }, /* F4 -> Note Pad */ - [0x01] = { 4, 0 }, /* Esc -> Power */ - [0x4b] = { 0, 1 }, /* Left */ - [0x50] = { 1, 1 }, /* Down */ - [0x48] = { 2, 1 }, /* Up */ - [0x4d] = { 3, 1 }, /* Right */ - [0x4c] = { 4, 1 }, /* Centre */ - [0x39] = { 4, 1 }, /* Spc -> Centre */ + [0x3b] = { 0, 0 }, /* F1 -> Calendar */ + [0x3c] = { 1, 0 }, /* F2 -> Contacts */ + [0x3d] = { 2, 0 }, /* F3 -> Tasks List */ + [0x3e] = { 3, 0 }, /* F4 -> Note Pad */ + [0x01] = { 4, 0 }, /* Esc -> Power */ + [0x4b] = { 0, 1 }, /* Left */ + [0x50] = { 1, 1 }, /* Down */ + [0x48] = { 2, 1 }, /* Up */ + [0x4d] = { 3, 1 }, /* Right */ + [0x4c] = { 4, 1 }, /* Centre */ + [0x39] = { 4, 1 }, /* Spc -> Centre */ }; static void palmte_button_event(void *opaque, int keycode) @@ -161,13 +161,13 @@ static void palmte_gpio_setup(struct omap_mpu_state_s *cpu) [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, 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]); /* Reset some inputs to initial state. */ qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_USBDETECT_GPIO)); -- 2.20.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/arm/palm.c: Detabify 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é 1 sibling, 0 replies; 12+ messages in thread From: Li Qiang @ 2020-07-12 0:18 UTC (permalink / raw) To: Peter Maydell; +Cc: qemu-arm, Qemu Developers Peter Maydell <peter.maydell@linaro.org> 于2020年6月29日周一 上午5:45写道: > > Remove hard-tabs from palm.c. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Li Qiang <liq3ea@gmail.com> > --- > hw/arm/palm.c | 64 +++++++++++++++++++++++++-------------------------- > 1 file changed, 32 insertions(+), 32 deletions(-) > > diff --git a/hw/arm/palm.c b/hw/arm/palm.c > index 97ca105d297..569836178f6 100644 > --- a/hw/arm/palm.c > +++ b/hw/arm/palm.c > @@ -61,21 +61,21 @@ static const MemoryRegionOps static_ops = { > /* Palm Tunsgten|E support */ > > /* Shared GPIOs */ > -#define PALMTE_USBDETECT_GPIO 0 > -#define PALMTE_USB_OR_DC_GPIO 1 > -#define PALMTE_TSC_GPIO 4 > -#define PALMTE_PINTDAV_GPIO 6 > -#define PALMTE_MMC_WP_GPIO 8 > -#define PALMTE_MMC_POWER_GPIO 9 > -#define PALMTE_HDQ_GPIO 11 > -#define PALMTE_HEADPHONES_GPIO 14 > -#define PALMTE_SPEAKER_GPIO 15 > +#define PALMTE_USBDETECT_GPIO 0 > +#define PALMTE_USB_OR_DC_GPIO 1 > +#define PALMTE_TSC_GPIO 4 > +#define PALMTE_PINTDAV_GPIO 6 > +#define PALMTE_MMC_WP_GPIO 8 > +#define PALMTE_MMC_POWER_GPIO 9 > +#define PALMTE_HDQ_GPIO 11 > +#define PALMTE_HEADPHONES_GPIO 14 > +#define PALMTE_SPEAKER_GPIO 15 > /* MPU private GPIOs */ > -#define PALMTE_DC_GPIO 2 > -#define PALMTE_MMC_SWITCH_GPIO 4 > -#define PALMTE_MMC1_GPIO 6 > -#define PALMTE_MMC2_GPIO 7 > -#define PALMTE_MMC3_GPIO 11 > +#define PALMTE_DC_GPIO 2 > +#define PALMTE_MMC_SWITCH_GPIO 4 > +#define PALMTE_MMC1_GPIO 6 > +#define PALMTE_MMC2_GPIO 7 > +#define PALMTE_MMC3_GPIO 11 > > static MouseTransformInfo palmte_pointercal = { > .x = 320, > @@ -100,17 +100,17 @@ static struct { > int column; > } palmte_keymap[0x80] = { > [0 ... 0x7f] = { -1, -1 }, > - [0x3b] = { 0, 0 }, /* F1 -> Calendar */ > - [0x3c] = { 1, 0 }, /* F2 -> Contacts */ > - [0x3d] = { 2, 0 }, /* F3 -> Tasks List */ > - [0x3e] = { 3, 0 }, /* F4 -> Note Pad */ > - [0x01] = { 4, 0 }, /* Esc -> Power */ > - [0x4b] = { 0, 1 }, /* Left */ > - [0x50] = { 1, 1 }, /* Down */ > - [0x48] = { 2, 1 }, /* Up */ > - [0x4d] = { 3, 1 }, /* Right */ > - [0x4c] = { 4, 1 }, /* Centre */ > - [0x39] = { 4, 1 }, /* Spc -> Centre */ > + [0x3b] = { 0, 0 }, /* F1 -> Calendar */ > + [0x3c] = { 1, 0 }, /* F2 -> Contacts */ > + [0x3d] = { 2, 0 }, /* F3 -> Tasks List */ > + [0x3e] = { 3, 0 }, /* F4 -> Note Pad */ > + [0x01] = { 4, 0 }, /* Esc -> Power */ > + [0x4b] = { 0, 1 }, /* Left */ > + [0x50] = { 1, 1 }, /* Down */ > + [0x48] = { 2, 1 }, /* Up */ > + [0x4d] = { 3, 1 }, /* Right */ > + [0x4c] = { 4, 1 }, /* Centre */ > + [0x39] = { 4, 1 }, /* Spc -> Centre */ > }; > > static void palmte_button_event(void *opaque, int keycode) > @@ -161,13 +161,13 @@ static void palmte_gpio_setup(struct omap_mpu_state_s *cpu) > [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, 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]); > > /* Reset some inputs to initial state. */ > qemu_irq_lower(qdev_get_gpio_in(cpu->gpio, PALMTE_USBDETECT_GPIO)); > -- > 2.20.1 > > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/arm/palm.c: Detabify 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é 1 sibling, 0 replies; 12+ messages in thread From: Philippe Mathieu-Daudé @ 2020-07-13 10:49 UTC (permalink / raw) To: Peter Maydell, qemu-arm, qemu-devel On 6/28/20 11:42 PM, Peter Maydell wrote: > Remove hard-tabs from palm.c. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> > --- > hw/arm/palm.c | 64 +++++++++++++++++++++++++-------------------------- > 1 file changed, 32 insertions(+), 32 deletions(-) Using 'git-diff -w': Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device 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-06-28 21:42 ` Peter Maydell 2020-07-12 0:22 ` Li Qiang 2020-07-13 8:57 ` Philippe Mathieu-Daudé 2020-07-11 18:33 ` [PATCH 0/2] hw/arm/palm.c: Fix Coverity issue CID 1421944 Peter Maydell 2 siblings, 2 replies; 12+ messages in thread From: Peter Maydell @ 2020-06-28 21:42 UTC (permalink / raw) To: qemu-arm, qemu-devel 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> --- 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 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device 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 2020-07-13 8:57 ` Philippe Mathieu-Daudé 1 sibling, 0 replies; 12+ messages in thread From: Li Qiang @ 2020-07-12 0:22 UTC (permalink / raw) To: Peter Maydell; +Cc: qemu-arm, Qemu Developers 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 > > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device 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 @ 2020-07-13 8:57 ` Philippe Mathieu-Daudé 2020-07-13 10:05 ` Peter Maydell 1 sibling, 1 reply; 12+ messages in thread From: Philippe Mathieu-Daudé @ 2020-07-13 8:57 UTC (permalink / raw) To: Peter Maydell, qemu-arm, qemu-devel; +Cc: Eduardo Habkost Hi Peter, On 6/28/20 11:42 PM, Peter Maydell wrote: > 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> > --- > 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); Why not make it a generic container in the MachineState and create the container in hw/core/machine.c::machine_initfn()? > > 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) > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device 2020-07-13 8:57 ` Philippe Mathieu-Daudé @ 2020-07-13 10:05 ` Peter Maydell 2020-07-13 10:21 ` Philippe Mathieu-Daudé 0 siblings, 1 reply; 12+ messages in thread From: Peter Maydell @ 2020-07-13 10:05 UTC (permalink / raw) To: Philippe Mathieu-Daudé; +Cc: qemu-arm, QEMU Developers, Eduardo Habkost On Mon, 13 Jul 2020 at 09:57, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: > Why not make it a generic container in the MachineState and create > the container in hw/core/machine.c::machine_initfn()? I don't think we create containers like that for any other machine, do we? thanks -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device 2020-07-13 10:05 ` Peter Maydell @ 2020-07-13 10:21 ` Philippe Mathieu-Daudé 2020-07-13 10:31 ` Peter Maydell 0 siblings, 1 reply; 12+ messages in thread From: Philippe Mathieu-Daudé @ 2020-07-13 10:21 UTC (permalink / raw) To: Peter Maydell; +Cc: qemu-arm, QEMU Developers, Eduardo Habkost On 7/13/20 12:05 PM, Peter Maydell wrote: > On Mon, 13 Jul 2020 at 09:57, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: >> Why not make it a generic container in the MachineState and create >> the container in hw/core/machine.c::machine_initfn()? > > I don't think we create containers like that for any other > machine, do we? No but maybe we could. Most boards have some GPIO/LED/reset switch button. Do all machines have a NUMA memory device? Do all machines have a dtb? Do all machines use NVDIMM devices? I think we have more machines using GPIOs than machine using NVDIMM. Anyway I don't mind, I was just trying to figure where this container belong on QOM. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device 2020-07-13 10:21 ` Philippe Mathieu-Daudé @ 2020-07-13 10:31 ` Peter Maydell 2020-07-13 10:52 ` Philippe Mathieu-Daudé 0 siblings, 1 reply; 12+ messages in thread From: Peter Maydell @ 2020-07-13 10:31 UTC (permalink / raw) To: Philippe Mathieu-Daudé; +Cc: qemu-arm, QEMU Developers, Eduardo Habkost On Mon, 13 Jul 2020 at 11:21, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: > > On 7/13/20 12:05 PM, Peter Maydell wrote: > > On Mon, 13 Jul 2020 at 09:57, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: > >> Why not make it a generic container in the MachineState and create > >> the container in hw/core/machine.c::machine_initfn()? > > > > I don't think we create containers like that for any other > > machine, do we? > > No but maybe we could. Most boards have some GPIO/LED/reset switch > button. Do all machines have a NUMA memory device? Do all machines > have a dtb? Do all machines use NVDIMM devices? I think we have > more machines using GPIOs than machine using NVDIMM. Anyway I don't > mind, I was just trying to figure where this container belong on QOM. I think that if machines were qdev objects with the usual reset/gpio/etc capabilities, I might have just implemented this as part of the machine object; but they aren't, and it didn't really seem like the right approach to create an ad-hoc "container that sort of corresponds to the whole machine". Also, since these machines are largely orphan I tend to favour smaller-scale interventions that push them in a better direction rather than more sweeping changes. thanks -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device 2020-07-13 10:31 ` Peter Maydell @ 2020-07-13 10:52 ` Philippe Mathieu-Daudé 0 siblings, 0 replies; 12+ messages in thread From: Philippe Mathieu-Daudé @ 2020-07-13 10:52 UTC (permalink / raw) To: Peter Maydell; +Cc: qemu-arm, QEMU Developers, Eduardo Habkost On 7/13/20 12:31 PM, Peter Maydell wrote: > On Mon, 13 Jul 2020 at 11:21, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: >> >> On 7/13/20 12:05 PM, Peter Maydell wrote: >>> On Mon, 13 Jul 2020 at 09:57, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote: >>>> Why not make it a generic container in the MachineState and create >>>> the container in hw/core/machine.c::machine_initfn()? >>> >>> I don't think we create containers like that for any other >>> machine, do we? >> >> No but maybe we could. Most boards have some GPIO/LED/reset switch >> button. Do all machines have a NUMA memory device? Do all machines >> have a dtb? Do all machines use NVDIMM devices? I think we have >> more machines using GPIOs than machine using NVDIMM. Anyway I don't >> mind, I was just trying to figure where this container belong on QOM. > > I think that if machines were qdev objects with the usual > reset/gpio/etc capabilities, I might have just implemented > this as part of the machine object; but they aren't, and > it didn't really seem like the right approach to create an > ad-hoc "container that sort of corresponds to the whole > machine". Also, since these machines are largely orphan > I tend to favour smaller-scale interventions that push them > in a better direction rather than more sweeping changes. Fair enough. There is something that bugs me in the MachineClass, but this is not this series fault. I guess by adding such containers in machines, we'll eventually figure out what is the best QOM design for it. Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/2] hw/arm/palm.c: Fix Coverity issue CID 1421944 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-06-28 21:42 ` [PATCH 2/2] hw/arm/palm.c: Encapsulate misc GPIO handling in a device Peter Maydell @ 2020-07-11 18:33 ` Peter Maydell 2 siblings, 0 replies; 12+ messages in thread From: Peter Maydell @ 2020-07-11 18:33 UTC (permalink / raw) To: qemu-arm, QEMU Developers On Sun, 28 Jun 2020 at 22:42, Peter Maydell <peter.maydell@linaro.org> wrote: > > As for spitz and tosa, fix the Coverity issue CID 1421944 which > points out that memory returned from qemu_allocate_irqs() is leaked > by encapsulating the GPIO handling into a simple device. > As with the other series, detabify the file first. > > thanks > -- PMM > > Peter Maydell (2): > hw/arm/palm.c: Detabify > hw/arm/palm.c: Encapsulate misc GPIO handling in a device > > hw/arm/palm.c | 111 ++++++++++++++++++++++++++++++++++---------------- > 1 file changed, 77 insertions(+), 34 deletions(-) > ping for code review, anybody? thanks -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2020-07-13 10:53 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
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).