diff mbox series

[v3,10/18] hw/isa: Ensure isa_register_portio_list() do not get NULL ISA device

Message ID 20230302224058.43315-11-philmd@linaro.org
State New
Headers show
Series hw/ide: Untangle ISA/PCI abuses of ide_init_ioport() | expand

Commit Message

Philippe Mathieu-Daudé March 2, 2023, 10:40 p.m. UTC
Previous commit removed the single call to isa_register_portio_list()
with dev=NULL. To be sure we won't reintroduce such weird (ab)use,
assert dev is non-NULL.

We can now calls isa_address_space_io() to get the device I/O region.

Note we can then remove the NULL check in isa_init_ioport() because
it is only called in 2 places (and is static to this file):
- isa_register_ioport() which first calls isa_address_space_io(),
  itself asserting dev is not NULL.
- isa_register_portio_list() which also asserts dev is not NULL
  since the previous commit.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/isa/isa-bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Mark Cave-Ayland April 26, 2023, 1:16 p.m. UTC | #1
On 02/03/2023 22:40, Philippe Mathieu-Daudé wrote:

> Previous commit removed the single call to isa_register_portio_list()
> with dev=NULL. To be sure we won't reintroduce such weird (ab)use,
> assert dev is non-NULL.
> 
> We can now calls isa_address_space_io() to get the device I/O region.
> 
> Note we can then remove the NULL check in isa_init_ioport() because
> it is only called in 2 places (and is static to this file):
> - isa_register_ioport() which first calls isa_address_space_io(),
>    itself asserting dev is not NULL.
> - isa_register_portio_list() which also asserts dev is not NULL
>    since the previous commit.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/isa/isa-bus.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c
> index 081bac18ee..9c8224afa5 100644
> --- a/hw/isa/isa-bus.c
> +++ b/hw/isa/isa-bus.c
> @@ -113,7 +113,7 @@ IsaDma *isa_bus_get_dma(ISABus *bus, int nchan)
>   
>   static inline void isa_init_ioport(ISADevice *dev, uint16_t ioport)
>   {
> -    if (dev && (dev->ioport_id == 0 || ioport < dev->ioport_id)) {
> +    if (dev->ioport_id == 0 || ioport < dev->ioport_id) {
>           dev->ioport_id = ioport;
>       }
>   }
> @@ -129,6 +129,7 @@ int isa_register_portio_list(ISADevice *dev,
>                                const MemoryRegionPortio *pio_start,
>                                void *opaque, const char *name)
>   {
> +    assert(dev);
>       assert(piolist && !piolist->owner);
>   
>       if (!isabus) {

Yes!

Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.
diff mbox series

Patch

diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c
index 081bac18ee..9c8224afa5 100644
--- a/hw/isa/isa-bus.c
+++ b/hw/isa/isa-bus.c
@@ -113,7 +113,7 @@  IsaDma *isa_bus_get_dma(ISABus *bus, int nchan)
 
 static inline void isa_init_ioport(ISADevice *dev, uint16_t ioport)
 {
-    if (dev && (dev->ioport_id == 0 || ioport < dev->ioport_id)) {
+    if (dev->ioport_id == 0 || ioport < dev->ioport_id) {
         dev->ioport_id = ioport;
     }
 }
@@ -129,6 +129,7 @@  int isa_register_portio_list(ISADevice *dev,
                              const MemoryRegionPortio *pio_start,
                              void *opaque, const char *name)
 {
+    assert(dev);
     assert(piolist && !piolist->owner);
 
     if (!isabus) {