[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH-for-5.0? 3/3] hw/openrisc/pic_cpu: Use qdev gpio rather than
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH-for-5.0? 3/3] hw/openrisc/pic_cpu: Use qdev gpio rather than qemu_allocate_irqs() |
Date: |
Mon, 13 Apr 2020 23:15:19 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
Hi Stafford,
On 4/13/20 1:33 AM, Stafford Horne wrote:
> On Sun, Apr 12, 2020 at 11:29:43PM +0200, Philippe Mathieu-Daudé wrote:
>> Switch to using the qdev gpio API which is preferred over
>> qemu_allocate_irqs(). Doing so we also stop leaking the
>> allocated memory. One step to eventually deprecate and
>> remove qemu_allocate_irqs() one day.
>>
>> Patch created mechanically using spatch with this script
>> inspired from commit d6ef883d9d7:
>>
>> @@
>> typedef qemu_irq;
>> identifier irqs, handler;
>> expression opaque, count, i;
>> @@
>> - qemu_irq *irqs;
>> ...
>> - irqs = qemu_allocate_irqs(handler, opaque, count);
>> + qdev_init_gpio_in(DEVICE(opaque), handler, count);
>> <+...
>> - irqs[i]
>> + qdev_get_gpio_in(DEVICE(opaque), i)
>> ...+>
>> ?- g_free(irqs);
>>
>> Inspired-by: Peter Maydell <address@hidden>
>> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
>> ---
>> hw/openrisc/pic_cpu.c | 5 ++---
>> 1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/openrisc/pic_cpu.c b/hw/openrisc/pic_cpu.c
>> index 36f9350830..4b0c92f842 100644
>> --- a/hw/openrisc/pic_cpu.c
>> +++ b/hw/openrisc/pic_cpu.c
>> @@ -52,10 +52,9 @@ static void openrisc_pic_cpu_handler(void *opaque, int
>> irq, int level)
>> void cpu_openrisc_pic_init(OpenRISCCPU *cpu)
>> {
>> int i;
>> - qemu_irq *qi;
>> - qi = qemu_allocate_irqs(openrisc_pic_cpu_handler, cpu, NR_IRQS);
>> + qdev_init_gpio_in(DEVICE(cpu), openrisc_pic_cpu_handler, NR_IRQS);
>>
>> for (i = 0; i < NR_IRQS; i++) {
>> - cpu->env.irq[i] = qi[i];
>> + cpu->env.irq[i] = qdev_get_gpio_in(DEVICE(cpu), i);
>> }
>> }
>
> This looks fine to me.
>
> Why do you have the '5.0?' in the subject?
Simply because similar commit d6ef883d9d7 was merged in 5.0-rc1 (and it
fixes a bug reported by Coverity, I'm not sure why Coverity didn't
reported this too).
>
> -Stafford
>