[PATCH] hw/loongarch/virt: Remove unused assignment

Bibo Mao posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240612033637.167787-1-maobibo@loongson.cn
Maintainers: Song Gao <gaosong@loongson.cn>
hw/loongarch/virt.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
[PATCH] hw/loongarch/virt: Remove unused assignment
Posted by Bibo Mao 1 month ago
There is abuse usage about local variable gap. Remove
duplicated assignment and solve Coverity reported error.

Resolves: Coverity CID 1546441
Fixes: 3cc451cbce ("hw/loongarch: Refine fwcfg memory map")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 hw/loongarch/virt.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 66cef201ab..2fe08583b8 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -1054,7 +1054,6 @@ static void fw_cfg_add_memory(MachineState *ms)
         memmap_add_entry(base, gap, 1);
         size -= gap;
         base = VIRT_HIGHMEM_BASE;
-        gap = ram_size - VIRT_LOWMEM_SIZE;
     }
 
     if (size) {
@@ -1067,17 +1066,17 @@ static void fw_cfg_add_memory(MachineState *ms)
     }
 
     /* add fw_cfg memory map of other nodes */
-    size = ram_size - numa_info[0].node_mem;
-    gap  = VIRT_LOWMEM_BASE + VIRT_LOWMEM_SIZE;
-    if (base < gap && (base + size) > gap) {
+    if (numa_info[0].node_mem < gap && ram_size > gap) {
         /*
          * memory map for the maining nodes splited into two part
-         *   lowram:  [base, +(gap - base))
-         *   highram: [VIRT_HIGHMEM_BASE, +(size - (gap - base)))
+         * lowram:  [base, +(gap - numa_info[0].node_mem))
+         * highram: [VIRT_HIGHMEM_BASE, +(ram_size - gap))
          */
-        memmap_add_entry(base, gap - base, 1);
-        size -= gap - base;
+        memmap_add_entry(base, gap - numa_info[0].node_mem, 1);
+        size = ram_size - gap;
         base = VIRT_HIGHMEM_BASE;
+    } else {
+        size = ram_size - numa_info[0].node_mem;
     }
 
    if (size)

base-commit: 80e8f0602168f451a93e71cbb1d59e93d745e62e
-- 
2.39.3
Re: [PATCH] hw/loongarch/virt: Remove unused assignment
Posted by gaosong 2 days, 11 hours ago
在 2024/6/12 上午11:36, Bibo Mao 写道:
> There is abuse usage about local variable gap. Remove
> duplicated assignment and solve Coverity reported error.
>
> Resolves: Coverity CID 1546441
> Fixes: 3cc451cbce ("hw/loongarch: Refine fwcfg memory map")
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
>   hw/loongarch/virt.c | 15 +++++++--------
>   1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index 66cef201ab..2fe08583b8 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -1054,7 +1054,6 @@ static void fw_cfg_add_memory(MachineState *ms)
>           memmap_add_entry(base, gap, 1);
>           size -= gap;
>           base = VIRT_HIGHMEM_BASE;
> -        gap = ram_size - VIRT_LOWMEM_SIZE;
>       }
>   
>       if (size) {
> @@ -1067,17 +1066,17 @@ static void fw_cfg_add_memory(MachineState *ms)
>       }
>   
>       /* add fw_cfg memory map of other nodes */
> -    size = ram_size - numa_info[0].node_mem;
> -    gap  = VIRT_LOWMEM_BASE + VIRT_LOWMEM_SIZE;
> -    if (base < gap && (base + size) > gap) {
> +    if (numa_info[0].node_mem < gap && ram_size > gap) {
>           /*
>            * memory map for the maining nodes splited into two part
> -         *   lowram:  [base, +(gap - base))
> -         *   highram: [VIRT_HIGHMEM_BASE, +(size - (gap - base)))
> +         * lowram:  [base, +(gap - numa_info[0].node_mem))
> +         * highram: [VIRT_HIGHMEM_BASE, +(ram_size - gap))
>            */
> -        memmap_add_entry(base, gap - base, 1);
> -        size -= gap - base;
> +        memmap_add_entry(base, gap - numa_info[0].node_mem, 1);
> +        size = ram_size - gap;
>           base = VIRT_HIGHMEM_BASE;
> +    } else {
> +        size = ram_size - numa_info[0].node_mem;
>       }
>   
>      if (size)
>
> base-commit: 80e8f0602168f451a93e71cbb1d59e93d745e62e