diff mbox series

[6/8] ppc4xx: Pass array index to function instead of pointer into the array

Message ID fa4665529f65d02a924437b18e90686b173676f6.1546394798.git.balaton@eik.bme.hu
State New
Headers show
Series Misc sam460ex related patches | expand

Commit Message

BALATON Zoltan Jan. 2, 2019, 2:06 a.m. UTC
The sdram_set_bcr() function in ppc440_uc.c takes a pointer into an
array then calculates its index from that. It's simpler and easier to
just pass the index which simplifies both the function and its callers.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 hw/ppc/ppc440_uc.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

Comments

David Gibson Jan. 2, 2019, 4:17 a.m. UTC | #1
On Wed, Jan 02, 2019 at 03:06:38AM +0100, BALATON Zoltan wrote:
> The sdram_set_bcr() function in ppc440_uc.c takes a pointer into an
> array then calculates its index from that. It's simpler and easier to
> just pass the index which simplifies both the function and its callers.
> 
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  hw/ppc/ppc440_uc.c | 36 ++++++++++++++++--------------------
>  1 file changed, 16 insertions(+), 20 deletions(-)
> 
> diff --git a/hw/ppc/ppc440_uc.c b/hw/ppc/ppc440_uc.c
> index e46f59fba8..60dbb35eee 100644
> --- a/hw/ppc/ppc440_uc.c
> +++ b/hw/ppc/ppc440_uc.c
> @@ -564,28 +564,26 @@ static target_ulong sdram_size(uint32_t bcr)
>      return size;
>  }
>  
> -static void sdram_set_bcr(ppc440_sdram_t *sdram,
> -                          uint32_t *bcrp, uint32_t bcr, int enabled)
> +static void sdram_set_bcr(ppc440_sdram_t *sdram, int i,
> +                          uint32_t bcr, int enabled)
>  {
> -    unsigned n = bcrp - sdram->bcr;
> -
> -    if (*bcrp & 1) {
> -        /* Unmap RAM */
> +    if (sdram->bcr[i] & 1) {
> +        /* First unmap RAM if enabled */
>          memory_region_del_subregion(get_system_memory(),
> -                                    &sdram->containers[n]);
> -        memory_region_del_subregion(&sdram->containers[n],
> -                                    &sdram->ram_memories[n]);
> -        object_unparent(OBJECT(&sdram->containers[n]));
> +                                    &sdram->containers[i]);
> +        memory_region_del_subregion(&sdram->containers[i],
> +                                    &sdram->ram_memories[i]);
> +        object_unparent(OBJECT(&sdram->containers[i]));
>      }
> -    *bcrp = bcr & 0xFFDEE001;
> +    sdram->bcr[i] = bcr & 0xFFDEE001;
>      if (enabled && (bcr & 1)) {
> -        memory_region_init(&sdram->containers[n], NULL, "sdram-containers",
> +        memory_region_init(&sdram->containers[i], NULL, "sdram-containers",
>                             sdram_size(bcr));
> -        memory_region_add_subregion(&sdram->containers[n], 0,
> -                                    &sdram->ram_memories[n]);
> +        memory_region_add_subregion(&sdram->containers[i], 0,
> +                                    &sdram->ram_memories[i]);
>          memory_region_add_subregion(get_system_memory(),
>                                      sdram_base(bcr),
> -                                    &sdram->containers[n]);
> +                                    &sdram->containers[i]);
>      }
>  }
>  
> @@ -595,12 +593,10 @@ static void sdram_map_bcr(ppc440_sdram_t *sdram)
>  
>      for (i = 0; i < sdram->nbanks; i++) {
>          if (sdram->ram_sizes[i] != 0) {
> -            sdram_set_bcr(sdram,
> -                          &sdram->bcr[i],
> -                          sdram_bcr(sdram->ram_bases[i], sdram->ram_sizes[i]),
> -                          1);
> +            sdram_set_bcr(sdram, i, sdram_bcr(sdram->ram_bases[i],
> +                                              sdram->ram_sizes[i]), 1);
>          } else {
> -            sdram_set_bcr(sdram, &sdram->bcr[i], 0, 0);
> +            sdram_set_bcr(sdram, i, 0, 0);
>          }
>      }
>  }
diff mbox series

Patch

diff --git a/hw/ppc/ppc440_uc.c b/hw/ppc/ppc440_uc.c
index e46f59fba8..60dbb35eee 100644
--- a/hw/ppc/ppc440_uc.c
+++ b/hw/ppc/ppc440_uc.c
@@ -564,28 +564,26 @@  static target_ulong sdram_size(uint32_t bcr)
     return size;
 }
 
-static void sdram_set_bcr(ppc440_sdram_t *sdram,
-                          uint32_t *bcrp, uint32_t bcr, int enabled)
+static void sdram_set_bcr(ppc440_sdram_t *sdram, int i,
+                          uint32_t bcr, int enabled)
 {
-    unsigned n = bcrp - sdram->bcr;
-
-    if (*bcrp & 1) {
-        /* Unmap RAM */
+    if (sdram->bcr[i] & 1) {
+        /* First unmap RAM if enabled */
         memory_region_del_subregion(get_system_memory(),
-                                    &sdram->containers[n]);
-        memory_region_del_subregion(&sdram->containers[n],
-                                    &sdram->ram_memories[n]);
-        object_unparent(OBJECT(&sdram->containers[n]));
+                                    &sdram->containers[i]);
+        memory_region_del_subregion(&sdram->containers[i],
+                                    &sdram->ram_memories[i]);
+        object_unparent(OBJECT(&sdram->containers[i]));
     }
-    *bcrp = bcr & 0xFFDEE001;
+    sdram->bcr[i] = bcr & 0xFFDEE001;
     if (enabled && (bcr & 1)) {
-        memory_region_init(&sdram->containers[n], NULL, "sdram-containers",
+        memory_region_init(&sdram->containers[i], NULL, "sdram-containers",
                            sdram_size(bcr));
-        memory_region_add_subregion(&sdram->containers[n], 0,
-                                    &sdram->ram_memories[n]);
+        memory_region_add_subregion(&sdram->containers[i], 0,
+                                    &sdram->ram_memories[i]);
         memory_region_add_subregion(get_system_memory(),
                                     sdram_base(bcr),
-                                    &sdram->containers[n]);
+                                    &sdram->containers[i]);
     }
 }
 
@@ -595,12 +593,10 @@  static void sdram_map_bcr(ppc440_sdram_t *sdram)
 
     for (i = 0; i < sdram->nbanks; i++) {
         if (sdram->ram_sizes[i] != 0) {
-            sdram_set_bcr(sdram,
-                          &sdram->bcr[i],
-                          sdram_bcr(sdram->ram_bases[i], sdram->ram_sizes[i]),
-                          1);
+            sdram_set_bcr(sdram, i, sdram_bcr(sdram->ram_bases[i],
+                                              sdram->ram_sizes[i]), 1);
         } else {
-            sdram_set_bcr(sdram, &sdram->bcr[i], 0, 0);
+            sdram_set_bcr(sdram, i, 0, 0);
         }
     }
 }