diff mbox

[1/5] target-mips: fix compiler warnings (clang 5)

Message ID 20170304185652.10675-2-f4bug@amsat.org
State Accepted, archived
Headers show

Commit Message

Philippe Mathieu-Daudé March 4, 2017, 6:56 p.m. UTC
static code analyzer complain:

target/mips/helper.c:453:5: warning: Function call argument is an uninitialized value
    qemu_log_mask(CPU_LOG_MMU,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~

'physical' and 'prot' are uninitialized if 'ret' is not TLBRET_MATCH.

Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 target/mips/helper.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Yongbok Kim March 13, 2017, 2:59 p.m. UTC | #1
On 04/03/2017 18:56, Philippe Mathieu-Daudé wrote:
> static code analyzer complain:
> 
> target/mips/helper.c:453:5: warning: Function call argument is an uninitialized value
>     qemu_log_mask(CPU_LOG_MMU,
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> 'physical' and 'prot' are uninitialized if 'ret' is not TLBRET_MATCH.
> 
> Reported-by: Clang Static Analyzer
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  target/mips/helper.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/target/mips/helper.c b/target/mips/helper.c
> index d2e77958fd..e359ca3b44 100644
> --- a/target/mips/helper.c
> +++ b/target/mips/helper.c
> @@ -450,10 +450,18 @@ int mips_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
>      access_type = ACCESS_INT;
>      ret = get_physical_address(env, &physical, &prot,
>                                 address, rw, access_type);
> -    qemu_log_mask(CPU_LOG_MMU,
> -             "%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx
> -             " prot %d\n",
> -             __func__, address, ret, physical, prot);
> +    switch (ret) {
> +    case TLBRET_MATCH:
> +        qemu_log_mask(CPU_LOG_MMU,
> +                      "%s address=%" VADDR_PRIx " physical " TARGET_FMT_plx
> +                      " prot %d\n", __func__, address, physical, prot);
> +        break;
> +    default:
> +        qemu_log_mask(CPU_LOG_MMU,
> +                      "%s address=%" VADDR_PRIx " ret %d\n", __func__, address,
> +                      ret);
> +        break;
> +    }
>      if (ret == TLBRET_MATCH) {
>          tlb_set_page(cs, address & TARGET_PAGE_MASK,
>                       physical & TARGET_PAGE_MASK, prot | PAGE_EXEC,
> 

Reviewed-by: Yongbok Kim <yongbok.kim@imgtec.com>
diff mbox

Patch

diff --git a/target/mips/helper.c b/target/mips/helper.c
index d2e77958fd..e359ca3b44 100644
--- a/target/mips/helper.c
+++ b/target/mips/helper.c
@@ -450,10 +450,18 @@  int mips_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
     access_type = ACCESS_INT;
     ret = get_physical_address(env, &physical, &prot,
                                address, rw, access_type);
-    qemu_log_mask(CPU_LOG_MMU,
-             "%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx
-             " prot %d\n",
-             __func__, address, ret, physical, prot);
+    switch (ret) {
+    case TLBRET_MATCH:
+        qemu_log_mask(CPU_LOG_MMU,
+                      "%s address=%" VADDR_PRIx " physical " TARGET_FMT_plx
+                      " prot %d\n", __func__, address, physical, prot);
+        break;
+    default:
+        qemu_log_mask(CPU_LOG_MMU,
+                      "%s address=%" VADDR_PRIx " ret %d\n", __func__, address,
+                      ret);
+        break;
+    }
     if (ret == TLBRET_MATCH) {
         tlb_set_page(cs, address & TARGET_PAGE_MASK,
                      physical & TARGET_PAGE_MASK, prot | PAGE_EXEC,