[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 3/3] hw/core: report an error if invalid gpio is
From: |
Eduardo Habkost |
Subject: |
Re: [Qemu-devel] [PATCH 3/3] hw/core: report an error if invalid gpio is used |
Date: |
Fri, 23 Jun 2017 16:25:00 -0300 |
User-agent: |
Mutt/1.8.0 (2017-02-23) |
On Fri, Jun 23, 2017 at 01:45:57PM -0300, Philippe Mathieu-Daudé wrote:
> then abort calling error_setg()
I don't understand the reasons for this. This commit message says
"what" and "how", but not "why".
>
> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
> ---
> hw/core/qdev.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 849952a8d4..05aaa67cb8 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -448,7 +448,11 @@ qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const
> char *name, int n)
> {
> NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name);
>
> - assert(n >= 0 && n < gpio_list->num_in);
> + assert(n >= 0);
> + if (n >= gpio_list->num_in) {
> + error_setg(&error_abort, "Invalid gpio #%d (of %d) for %s",
> + n, gpio_list->num_in, name ? name : "device");
Why exactly assert() is ok for (n < 0), but not for
(n >= gpio_list->num_io)?
If you have reasons to believe (n >= gpio_list->num_in) can be triggered
by user input, then abort() isn't an appropriate way to handle it.
> + }
> return gpio_list->in[n];
> }
>
> --
> 2.13.1
>
--
Eduardo
- [Qemu-devel] [PATCH 0/3] hw/core: minor fixups, Philippe Mathieu-Daudé, 2017/06/23
- [Qemu-devel] [PATCH 1/3] elf-loader: warn about invalid endianess, Philippe Mathieu-Daudé, 2017/06/23
- [Qemu-devel] [PATCH 2/3] hw/core: fix missing return value in load_image_targphys_as(), Philippe Mathieu-Daudé, 2017/06/23
- [Qemu-devel] [PATCH 3/3] hw/core: report an error if invalid gpio is used, Philippe Mathieu-Daudé, 2017/06/23
- Re: [Qemu-devel] [PATCH 0/3] hw/core: minor fixups, Laszlo Ersek, 2017/06/23
- Re: [Qemu-devel] [PATCH 0/3] hw/core: minor fixups, Alistair Francis, 2017/06/26
- Re: [Qemu-devel] [PATCH 0/3] hw/core: minor fixups, Eduardo Habkost, 2017/06/26