Patchwork hw/sysbus.c: Remove unnecessary conditionals

login
register
mail settings
Submitter Peter Maydell
Date Dec. 19, 2011, 8:33 p.m.
Message ID <1324326839-28915-1-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/132312/
State New
Headers show

Comments

Peter Maydell - Dec. 19, 2011, 8:33 p.m.
Now that all sysbus MMIO regions are MemoryRegions, mmio[n].memory
is never NULL, and we can remove some unnecessary conditionals.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
A minor tidyup following Benoît's now-applied patches to remove
sysbus_init_mmio_cb2().

 hw/sysbus.c |   18 +++++-------------
 1 files changed, 5 insertions(+), 13 deletions(-)
Anthony Liguori - Dec. 20, 2011, 10:17 p.m.
On 12/19/2011 02:33 PM, Peter Maydell wrote:
> Now that all sysbus MMIO regions are MemoryRegions, mmio[n].memory
> is never NULL, and we can remove some unnecessary conditionals.
>
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>

Applied.  Thanks.

Regards,

Anthony Liguori

> ---
> A minor tidyup following Benoît's now-applied patches to remove
> sysbus_init_mmio_cb2().
>
>   hw/sysbus.c |   18 +++++-------------
>   1 files changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/hw/sysbus.c b/hw/sysbus.c
> index 81a57bd..24f619f 100644
> --- a/hw/sysbus.c
> +++ b/hw/sysbus.c
> @@ -50,17 +50,12 @@ void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr)
>       }
>       if (dev->mmio[n].addr != (target_phys_addr_t)-1) {
>           /* Unregister previous mapping.  */
> -        if (dev->mmio[n].memory) {
> -            memory_region_del_subregion(get_system_memory(),
> -                                        dev->mmio[n].memory);
> -        }
> +        memory_region_del_subregion(get_system_memory(), dev->mmio[n].memory);
>       }
>       dev->mmio[n].addr = addr;
> -    if (dev->mmio[n].memory) {
> -        memory_region_add_subregion(get_system_memory(),
> -                                    addr,
> -                                    dev->mmio[n].memory);
> -    }
> +    memory_region_add_subregion(get_system_memory(),
> +                                addr,
> +                                dev->mmio[n].memory);
>   }
>
>
> @@ -206,10 +201,7 @@ static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
>
>       monitor_printf(mon, "%*sirq %d\n", indent, "", s->num_irq);
>       for (i = 0; i<  s->num_mmio; i++) {
> -        size = 0;
> -        if (s->mmio[i].memory) {
> -            size = memory_region_size(s->mmio[i].memory);
> -        }
> +        size = memory_region_size(s->mmio[i].memory);
>           monitor_printf(mon, "%*smmio " TARGET_FMT_plx "/" TARGET_FMT_plx "\n",
>                          indent, "", s->mmio[i].addr, size);
>       }

Patch

diff --git a/hw/sysbus.c b/hw/sysbus.c
index 81a57bd..24f619f 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -50,17 +50,12 @@  void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr)
     }
     if (dev->mmio[n].addr != (target_phys_addr_t)-1) {
         /* Unregister previous mapping.  */
-        if (dev->mmio[n].memory) {
-            memory_region_del_subregion(get_system_memory(),
-                                        dev->mmio[n].memory);
-        }
+        memory_region_del_subregion(get_system_memory(), dev->mmio[n].memory);
     }
     dev->mmio[n].addr = addr;
-    if (dev->mmio[n].memory) {
-        memory_region_add_subregion(get_system_memory(),
-                                    addr,
-                                    dev->mmio[n].memory);
-    }
+    memory_region_add_subregion(get_system_memory(),
+                                addr,
+                                dev->mmio[n].memory);
 }
 
 
@@ -206,10 +201,7 @@  static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
 
     monitor_printf(mon, "%*sirq %d\n", indent, "", s->num_irq);
     for (i = 0; i < s->num_mmio; i++) {
-        size = 0;
-        if (s->mmio[i].memory) {
-            size = memory_region_size(s->mmio[i].memory);
-        }
+        size = memory_region_size(s->mmio[i].memory);
         monitor_printf(mon, "%*smmio " TARGET_FMT_plx "/" TARGET_FMT_plx "\n",
                        indent, "", s->mmio[i].addr, size);
     }