[PATCH v2 3/9] hw/pcmcia/pxa2xx: Realize sysbus device before accessing it

Philippe Mathieu-Daudé posted 9 patches 1 year, 1 month ago
Maintainers: Peter Maydell <peter.maydell@linaro.org>
There is a newer version of this series
[PATCH v2 3/9] hw/pcmcia/pxa2xx: Realize sysbus device before accessing it
Posted by Philippe Mathieu-Daudé 1 year, 1 month ago
sysbus_mmio_map() should not be called on unrealized device.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/pcmcia/pxa2xx.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/hw/pcmcia/pxa2xx.c b/hw/pcmcia/pxa2xx.c
index fcca7e571b..e7264feb45 100644
--- a/hw/pcmcia/pxa2xx.c
+++ b/hw/pcmcia/pxa2xx.c
@@ -142,15 +142,12 @@ PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
                                       hwaddr base)
 {
     DeviceState *dev;
-    PXA2xxPCMCIAState *s;
 
     dev = qdev_new(TYPE_PXA2XX_PCMCIA);
-    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
-    s = PXA2XX_PCMCIA(dev);
-
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
 
-    return s;
+    return PXA2XX_PCMCIA(dev);
 }
 
 static void pxa2xx_pcmcia_initfn(Object *obj)
-- 
2.41.0


Re: [PATCH v2 3/9] hw/pcmcia/pxa2xx: Realize sysbus device before accessing it
Posted by Thomas Huth 1 year, 1 month ago
On 19/10/2023 15.09, Philippe Mathieu-Daudé wrote:
> sysbus_mmio_map() should not be called on unrealized device.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/pcmcia/pxa2xx.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/pcmcia/pxa2xx.c b/hw/pcmcia/pxa2xx.c
> index fcca7e571b..e7264feb45 100644
> --- a/hw/pcmcia/pxa2xx.c
> +++ b/hw/pcmcia/pxa2xx.c
> @@ -142,15 +142,12 @@ PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
>                                         hwaddr base)
>   {
>       DeviceState *dev;
> -    PXA2xxPCMCIAState *s;
>   
>       dev = qdev_new(TYPE_PXA2XX_PCMCIA);
> -    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
> -    s = PXA2XX_PCMCIA(dev);
> -
>       sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
> +    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
>   
> -    return s;
> +    return PXA2XX_PCMCIA(dev);
>   }
>   
>   static void pxa2xx_pcmcia_initfn(Object *obj)

Reviewed-by: Thomas Huth <thuth@redhat.com>