Skip to contentSkip to conversation

disas/nanomips: Format string fixes

PATCH Applied Philippe Mathieu-Daudé 4 participants 13 messages Nov 1, 2022 – Nov 7, 2022

lore
Share & tools
lore
#0 lore raw

cover disas/nanomips: Format string fixes

Fix invalid string formats reported by Stefan:
https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (5):
disas/nanomips: Fix invalid PRId64 format calling img_format() disas/nanomips: Fix invalid PRIx64 format calling img_format() disas/nanomips: Use G_GNUC_PRINTF to avoid invalid string formats disas/nanomips: Remove headers already included by "qemu/osdep.h"
MAINTAINERS: Inherit from nanoMIPS

 MAINTAINERS      |  8 +-------
 disas/nanomips.c | 44 +++++++++++++++++++++++---------------------
 2 files changed, 24 insertions(+), 28 deletions(-)
Signature · 1 line
2.37.3
#1 lore raw

PATCH 1/5 disas/nanomips: Fix invalid PRId64 format calling img_format()

Fix warnings such:

disas/nanomips.c:3251:64: warning: format specifies type 'char *' but the argument has type 'int64' (aka 'long long') [-Wformat]

    return img_format("CACHE 0x%" PRIx64 ", %s(%s)", op_value, s_value, rs);
                                            ~~                 ^~~~~~~
                                            %lld
Fixes 4066c152b3 ("disas/nanomips: Remove IMMEDIATE functions")
---
 disas/nanomips.c | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)
disas/nanomips.c +20 -15
index 9647f1a8e3..6466c80dc5 100644
@@ -3252,7 +3252,8 @@ static char *CACHE(uint64 instruction, Dis_info *info)
 
     const char *rs = GPR(rs_value, info);
 
-    return img_format("CACHE 0x%" PRIx64 ", %s(%s)", op_value, s_value, rs);
+    return img_format("CACHE 0x%" PRIx64 ", %" PRId64 "(%s)",
+                      op_value, s_value, rs);
 }
 
 
@@ -3274,7 +3275,8 @@ static char *CACHEE(uint64 instruction, Dis_info *info)
 
     const char *rs = GPR(rs_value, info);
 
-    return img_format("CACHEE 0x%" PRIx64 ", %s(%s)", op_value, s_value, rs);
+    return img_format("CACHEE 0x%" PRIx64 ", %" PRId64 "(%s)",
+                      op_value, s_value, rs);
 }
 
 
@@ -5173,7 +5175,7 @@ static char *DADDIU_48_(uint64 instruction, Dis_info *info)
 
     const char *rt = GPR(rt_value, info);
 
-    return img_format("DADDIU %s, %s", rt, s_value);
+    return img_format("DADDIU %s, %" PRId64, rt, s_value);
 }
 
 
@@ -11859,7 +11861,7 @@ static char *PREF_S9_(uint64 instruction, Dis_info *info)
 
     const char *rs = GPR(rs_value, info);
 
-    return img_format("PREF 0x%" PRIx64 ", %s(%s)",
+    return img_format("PREF 0x%" PRIx64 ", %" PRId64 "(%s)",
                       hint_value, s_value, rs);
 }
 
@@ -11905,7 +11907,8 @@ static char *PREFE(uint64 instruction, Dis_info *info)
 
     const char *rs = GPR(rs_value, info);
 
-    return img_format("PREFE 0x%" PRIx64 ", %s(%s)", hint_value, s_value, rs);
+    return img_format("PREFE 0x%" PRIx64 ", %" PRId64 "(%s)",
+                      hint_value, s_value, rs);
 }
 
 
@@ -12079,7 +12082,7 @@ static char *REPL_PH(uint64 instruction, Dis_info *info)
 
     const char *rt = GPR(rt_value, info);
 
-    return img_format("REPL.PH %s, %s", rt, s_value);
+    return img_format("REPL.PH %s, %" PRId64, rt, s_value);
 }
 
 
@@ -12613,7 +12616,7 @@ static char *SB_S9_(uint64 instruction, Dis_info *info)
     const char *rt = GPR(rt_value, info);
     const char *rs = GPR(rs_value, info);
 
-    return img_format("SB %s, %s(%s)", rt, s_value, rs);
+    return img_format("SB %s, %" PRId64 "(%s)", rt, s_value, rs);
 }
 
 
@@ -12659,7 +12662,7 @@ static char *SBE(uint64 instruction, Dis_info *info)
     const char *rt = GPR(rt_value, info);
     const char *rs = GPR(rs_value, info);
 
-    return img_format("SBE %s, %s(%s)", rt, s_value, rs);
+    return img_format("SBE %s, %" PRId64 "(%s)", rt, s_value, rs);
 }
 
 
@@ -12706,7 +12709,7 @@ static char *SC(uint64 instruction, Dis_info *info)
     const char *rt = GPR(rt_value, info);
     const char *rs = GPR(rs_value, info);
 
-    return img_format("SC %s, %s(%s)", rt, s_value, rs);
+    return img_format("SC %s, %" PRId64 "(%s)", rt, s_value, rs);
 }
 
 
@@ -12729,7 +12732,7 @@ static char *SCD(uint64 instruction, Dis_info *info)
     const char *rt = GPR(rt_value, info);
     const char *rs = GPR(rs_value, info);
 
-    return img_format("SCD %s, %s(%s)", rt, s_value, rs);
+    return img_format("SCD %s, %" PRId64 "(%s)", rt, s_value, rs);
 }
 
 
@@ -12776,7 +12779,7 @@ static char *SCE(uint64 instruction, Dis_info *info)
     const char *rt = GPR(rt_value, info);
     const char *rs = GPR(rs_value, info);
 
-    return img_format("SCE %s, %s(%s)", rt, s_value, rs);
+    return img_format("SCE %s, %" PRId64 "(%s)", rt, s_value, rs);
 }
 
 
@@ -12868,7 +12871,7 @@ static char *SD_S9_(uint64 instruction, Dis_info *info)
     const char *rt = GPR(rt_value, info);
     const char *rs = GPR(rs_value, info);
 
-    return img_format("SD %s, %s(%s)", rt, s_value, rs);
+    return img_format("SD %s, %" PRId64 "(%s)", rt, s_value, rs);
 }
 
 
@@ -12973,7 +12976,7 @@ static char *SDC1_S9_(uint64 instruction, Dis_info *info)
     const char *ft = FPR(ft_value, info);
     const char *rs = GPR(rs_value, info);
 
-    return img_format("SDC1 %s, %s(%s)", ft, s_value, rs);
+    return img_format("SDC1 %s, %" PRId64 "(%s)", ft, s_value, rs);
 }
 
 
@@ -13066,7 +13069,8 @@ static char *SDC2(uint64 instruction, Dis_info *info)
 
     const char *rs = GPR(rs_value, info);
 
-    return img_format("SDC2 CP%" PRIu64 ", %s(%s)", cs_value, s_value, rs);
+    return img_format("SDC2 CP%" PRIu64 ", %" PRId64 "(%s)",
+                      cs_value, s_value, rs);
 }
 
 
@@ -13091,7 +13095,8 @@ static char *SDM(uint64 instruction, Dis_info *info)
     const char *rs = GPR(rs_value, info);
     uint64 count3 = encode_count3_from_count(count3_value);
 
-    return img_format("SDM %s, %s(%s), 0x%" PRIx64, rt, s_value, rs, count3);
+    return img_format("SDM %s, %" PRId64 "(%s), 0x%" PRIx64,
+                      rt, s_value, rs, count3);
 }
 
 
Signature · 1 line
2.37.3
Reviewed-by Stefan Weil on v1 1/5
#2 lore raw

Re: [PATCH 1/5] disas/nanomips: Fix invalid PRId64 format calling img_format()

Am 01.11.22 um 12:44 schrieb Philippe Mathieu-Daudé:

Quoted 11 lines

Fix warnings such:

   disas/nanomips.c:3251:64: warning: format specifies type 'char *' but the argument has type 'int64' (aka 'long long') [-Wformat]
     return img_format("CACHE 0x%" PRIx64 ", %s(%s)", op_value, s_value, rs);
                                             ~~                 ^~~~~~~
                                             %lld
Fixes 4066c152b3 ("disas/nanomips: Remove IMMEDIATE functions")

---

Quoted 147 lines
  disas/nanomips.c | 35 ++++++++++++++++++++---------------
  1 file changed, 20 insertions(+), 15 deletions(-)
disas/nanomips.c +20 -15
index 9647f1a8e3..6466c80dc5 100644
@@ -3252,7 +3252,8 @@ static char *CACHE(uint64 instruction, Dis_info *info)
 
      const char *rs = GPR(rs_value, info);
 
-    return img_format("CACHE 0x%" PRIx64 ", %s(%s)", op_value, s_value, rs);
+    return img_format("CACHE 0x%" PRIx64 ", %" PRId64 "(%s)",
+                      op_value, s_value, rs);
  }
 
 
@@ -3274,7 +3275,8 @@ static char *CACHEE(uint64 instruction, Dis_info *info)
 
      const char *rs = GPR(rs_value, info);
 
-    return img_format("CACHEE 0x%" PRIx64 ", %s(%s)", op_value, s_value, rs);
+    return img_format("CACHEE 0x%" PRIx64 ", %" PRId64 "(%s)",
+                      op_value, s_value, rs);
  }
 
 
@@ -5173,7 +5175,7 @@ static char *DADDIU_48_(uint64 instruction, Dis_info *info)
 
      const char *rt = GPR(rt_value, info);
 
-    return img_format("DADDIU %s, %s", rt, s_value);
+    return img_format("DADDIU %s, %" PRId64, rt, s_value);
  }
 
 
@@ -11859,7 +11861,7 @@ static char *PREF_S9_(uint64 instruction, Dis_info *info)
 
      const char *rs = GPR(rs_value, info);
 
-    return img_format("PREF 0x%" PRIx64 ", %s(%s)",
+    return img_format("PREF 0x%" PRIx64 ", %" PRId64 "(%s)",
                        hint_value, s_value, rs);
  }
 
@@ -11905,7 +11907,8 @@ static char *PREFE(uint64 instruction, Dis_info *info)
 
      const char *rs = GPR(rs_value, info);
 
-    return img_format("PREFE 0x%" PRIx64 ", %s(%s)", hint_value, s_value, rs);
+    return img_format("PREFE 0x%" PRIx64 ", %" PRId64 "(%s)",
+                      hint_value, s_value, rs);
  }
 
 
@@ -12079,7 +12082,7 @@ static char *REPL_PH(uint64 instruction, Dis_info *info)
 
      const char *rt = GPR(rt_value, info);
 
-    return img_format("REPL.PH %s, %s", rt, s_value);
+    return img_format("REPL.PH %s, %" PRId64, rt, s_value);
  }
 
 
@@ -12613,7 +12616,7 @@ static char *SB_S9_(uint64 instruction, Dis_info *info)
      const char *rt = GPR(rt_value, info);
      const char *rs = GPR(rs_value, info);
 
-    return img_format("SB %s, %s(%s)", rt, s_value, rs);
+    return img_format("SB %s, %" PRId64 "(%s)", rt, s_value, rs);
  }
 
 
@@ -12659,7 +12662,7 @@ static char *SBE(uint64 instruction, Dis_info *info)
      const char *rt = GPR(rt_value, info);
      const char *rs = GPR(rs_value, info);
 
-    return img_format("SBE %s, %s(%s)", rt, s_value, rs);
+    return img_format("SBE %s, %" PRId64 "(%s)", rt, s_value, rs);
  }
 
 
@@ -12706,7 +12709,7 @@ static char *SC(uint64 instruction, Dis_info *info)
      const char *rt = GPR(rt_value, info);
      const char *rs = GPR(rs_value, info);
 
-    return img_format("SC %s, %s(%s)", rt, s_value, rs);
+    return img_format("SC %s, %" PRId64 "(%s)", rt, s_value, rs);
  }
 
 
@@ -12729,7 +12732,7 @@ static char *SCD(uint64 instruction, Dis_info *info)
      const char *rt = GPR(rt_value, info);
      const char *rs = GPR(rs_value, info);
 
-    return img_format("SCD %s, %s(%s)", rt, s_value, rs);
+    return img_format("SCD %s, %" PRId64 "(%s)", rt, s_value, rs);
  }
 
 
@@ -12776,7 +12779,7 @@ static char *SCE(uint64 instruction, Dis_info *info)
      const char *rt = GPR(rt_value, info);
      const char *rs = GPR(rs_value, info);
 
-    return img_format("SCE %s, %s(%s)", rt, s_value, rs);
+    return img_format("SCE %s, %" PRId64 "(%s)", rt, s_value, rs);
  }
 
 
@@ -12868,7 +12871,7 @@ static char *SD_S9_(uint64 instruction, Dis_info *info)
      const char *rt = GPR(rt_value, info);
      const char *rs = GPR(rs_value, info);
 
-    return img_format("SD %s, %s(%s)", rt, s_value, rs);
+    return img_format("SD %s, %" PRId64 "(%s)", rt, s_value, rs);
  }
 
 
@@ -12973,7 +12976,7 @@ static char *SDC1_S9_(uint64 instruction, Dis_info *info)
      const char *ft = FPR(ft_value, info);
      const char *rs = GPR(rs_value, info);
 
-    return img_format("SDC1 %s, %s(%s)", ft, s_value, rs);
+    return img_format("SDC1 %s, %" PRId64 "(%s)", ft, s_value, rs);
  }
 
 
@@ -13066,7 +13069,8 @@ static char *SDC2(uint64 instruction, Dis_info *info)
 
      const char *rs = GPR(rs_value, info);
 
-    return img_format("SDC2 CP%" PRIu64 ", %s(%s)", cs_value, s_value, rs);
+    return img_format("SDC2 CP%" PRIu64 ", %" PRId64 "(%s)",
+                      cs_value, s_value, rs);
  }
 
 
@@ -13091,7 +13095,8 @@ static char *SDM(uint64 instruction, Dis_info *info)
      const char *rs = GPR(rs_value, info);
      uint64 count3 = encode_count3_from_count(count3_value);
 
-    return img_format("SDM %s, %s(%s), 0x%" PRIx64, rt, s_value, rs, count3);
+    return img_format("SDM %s, %" PRId64 "(%s), 0x%" PRIx64,
+                      rt, s_value, rs, count3);
  }
 
 
#3 lore raw

PATCH 2/5 disas/nanomips: Fix invalid PRIx64 format calling img_format()

In reply to Philippe Mathieu-Daudé

Fix:

disas/nanomips.c:12231:62: warning: format specifies type 'char *' but the argument has type 'uint64' (aka 'unsigned long long') [-Wformat]

    return img_format("RESTOREF 0x%" PRIx64 ", %s", u_value, count_value);
                                               ~~            ^~~~~~~~~~~
                                               %llu
Fixes 4066c152b3 ("disas/nanomips: Remove IMMEDIATE functions")
---
 disas/nanomips.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
disas/nanomips.c +2 -1
index 6466c80dc5..e4b21e7c45 100644
@@ -12235,7 +12235,8 @@ static char *RESTOREF(uint64 instruction, Dis_info *info)
     uint64 u_value = extract_u_11_10_9_8_7_6_5_4_3__s3(instruction);
 
 
-    return img_format("RESTOREF 0x%" PRIx64 ", %s", u_value, count_value);
+    return img_format("RESTOREF 0x%" PRIx64 ", 0x%" PRIx64,
+                      u_value, count_value);
 }
 
 
Signature · 1 line
2.37.3
Reviewed-by Stefan Weil on v1 2/5
#4 lore raw

Re: [PATCH 2/5] disas/nanomips: Fix invalid PRIx64 format calling img_format()

Am 01.11.22 um 12:44 schrieb Philippe Mathieu-Daudé:

Quoted 19 lines

Fix:

   disas/nanomips.c:12231:62: warning: format specifies type 'char *' but the argument has type 'uint64' (aka 'unsigned long long') [-Wformat]
     return img_format("RESTOREF 0x%" PRIx64 ", %s", u_value, count_value);
                                                ~~            ^~~~~~~~~~~
                                                %llu
Fixes 4066c152b3 ("disas/nanomips: Remove IMMEDIATE functions")
---
  disas/nanomips.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
disas/nanomips.c +0 -0
index 6466c80dc5..e4b21e7c45 100644

disas/nanomips.c static char *RESTOREF(uint64 instruction, Dis_info *info) · line 12240

Quoted 7 lines
disas/nanomips.c +2 -1
@@ -12235,7 +12235,8 @@ static char *RESTOREF(uint64 instruction, Dis_info *info)
      uint64 u_value = extract_u_11_10_9_8_7_6_5_4_3__s3(instruction);
 
 
-    return img_format("RESTOREF 0x%" PRIx64 ", %s", u_value, count_value);
+    return img_format("RESTOREF 0x%" PRIx64 ", 0x%" PRIx64,
+                      u_value, count_value);
  }
#5 lore raw

PATCH 3/5 disas/nanomips: Use G_GNUC_PRINTF to avoid invalid string formats

In reply to Philippe Mathieu-Daudé
---
 disas/nanomips.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
disas/nanomips.c +1 -1
index e4b21e7c45..3f45447292 100644
@@ -95,7 +95,7 @@ typedef struct Pool {
 #define IMGASSERTONCE(test)
 
 
-static char *img_format(const char *format, ...)
+static char * G_GNUC_PRINTF(1, 2) img_format(const char *format, ...)
 {
     char *buffer;
     va_list args;
Signature · 1 line
2.37.3
Reviewed-by Stefan Weil on v1 3/5
#6 lore raw

Re: [PATCH 3/5] disas/nanomips: Use G_GNUC_PRINTF to avoid invalid string formats

Am 01.11.22 um 12:44 schrieb Philippe Mathieu-Daudé:

Quoted 11 lines
---
  disas/nanomips.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
disas/nanomips.c +0 -0
index e4b21e7c45..3f45447292 100644

disas/nanomips.c typedef struct Pool { · line 101

Quoted 8 lines
disas/nanomips.c +1 -1
@@ -95,7 +95,7 @@ typedef struct Pool {
  #define IMGASSERTONCE(test)
 
 
-static char *img_format(const char *format, ...)
+static char * G_GNUC_PRINTF(1, 2) img_format(const char *format, ...)
  {
      char *buffer;
      va_list args;
#7 lore raw

PATCH 4/5 disas/nanomips: Remove headers already included by "qemu/osdep.h"

In reply to Philippe Mathieu-Daudé
---
 disas/nanomips.c | 4 ----
 1 file changed, 4 deletions(-)
disas/nanomips.c +0 -4
index 3f45447292..821d4f8832 100644
@@ -30,10 +30,6 @@
 #include "qemu/osdep.h"
 #include "disas/dis-asm.h"
 
-#include <string.h>
-#include <stdio.h>
-#include <stdarg.h>
-
 typedef int64_t int64;
 typedef uint64_t uint64;
 typedef uint32_t uint32;
Signature · 1 line
2.37.3
Reviewed-by Stefan Weil on v1 4/5
#8 lore raw

Re: [PATCH 4/5] disas/nanomips: Remove headers already included by "qemu/osdep.h"

Am 01.11.22 um 12:44 schrieb Philippe Mathieu-Daudé:

Quoted 10 lines
---
  disas/nanomips.c | 4 ----
  1 file changed, 4 deletions(-)
disas/nanomips.c +0 -0
index 3f45447292..821d4f8832 100644

disas/nanomips.c line 35

Quoted 10 lines
disas/nanomips.c +0 -4
@@ -30,10 +30,6 @@
  #include "qemu/osdep.h"
  #include "disas/dis-asm.h"
 
-#include <string.h>
-#include <stdio.h>
-#include <stdarg.h>
-
  typedef int64_t int64;
  typedef uint64_t uint64;
  typedef uint32_t uint32;

Removing those three typedefs and replacing the related types would also be good (in another patch).

#9 lore raw

PATCH 5/5 MAINTAINERS: Inherit from nanoMIPS

In reply to Philippe Mathieu-Daudé

6 months ago Stefan Pejic stepped in as nanoMIPS maintainer (see commit a 8e0e23445a "target/mips: Undeprecate nanoMIPS ISA support in QEMU"), however today his email is bouncing:

** Message blocked **

Your message to [email protected] has been blocked. See technical details below for more information.

The response from the remote server was:
550 5.4.1 Recipient address rejected: Access denied. AS(201806281) [DBAEUR03FT030.eop-EUR03.prod.protection.outlook.com]

To avoid unmaintained code, I feel forced to merge this code back with the generic MIPS section.

Historical references:
- https://lore.kernel.org/qemu-devel/TY0PR03MB679726901BD6C6BE40114A2FE2A79@TY0PR03MB6797.apcprd03.prod.outlook.com/
- https://lore.kernel.org/qemu-devel/[email protected]/

Message-Id: <[email protected]>

---
 MAINTAINERS | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
MAINTAINERS +1 -7
index c41d8d65e2..0fa3c92b29 100644
@@ -237,16 +237,10 @@ R: Jiaxun Yang <[email protected]>
 R: Aleksandar Rikalo <[email protected]>
 S: Odd Fixes
 F: target/mips/
-F: disas/mips.c
+F: disas/*mips.c
 F: docs/system/cpu-models-mips.rst.inc
 F: tests/tcg/mips/
 
-MIPS TCG CPUs (nanoMIPS ISA)
-M: Stefan Pejic <[email protected]>
-S: Maintained
-F: disas/nanomips.*
-F: target/mips/tcg/*nanomips*
-
 NiosII TCG CPUs
 M: Chris Wulff <[email protected]>
 M: Marek Vasut <[email protected]>
Signature · 1 line
2.37.3
Tested-by on v1 5/5
#10 lore raw

Re: [PATCH 5/5] MAINTAINERS: Inherit from nanoMIPS

Quoted 10 lines · Philippe Mathieu-Daudé

6 months ago Stefan Pejic stepped in as nanoMIPS maintainer (see commit a 8e0e23445a "target/mips: Undeprecate nanoMIPS ISA support in QEMU"), however today his email is bouncing:

** Message blocked **

Your message to [email protected] has been blocked. See technical details below for more information.

The response from the remote server was:

   550 5.4.1 Recipient address rejected: Access denied. AS(201806281) [DBAEUR03FT030.eop-EUR03.prod.protection.outlook.com]

I saw the same bounce message when I CC:-ed him recently, thus:

Reviewed-by on the v1 series
#11 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Fix invalid string formats reported by Stefan:
https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (5):
disas/nanomips: Fix invalid PRId64 format calling img_format() disas/nanomips: Fix invalid PRIx64 format calling img_format() disas/nanomips: Use G_GNUC_PRINTF to avoid invalid string formats disas/nanomips: Remove headers already included by "qemu/osdep.h"
MAINTAINERS: Inherit from nanoMIPS

Quoted 4 lines
  MAINTAINERS      |  8 +-------
  disas/nanomips.c | 44 +++++++++++++++++++++++---------------------
  2 files changed, 24 insertions(+), 28 deletions(-)

r~

#12 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Fix invalid string formats reported by Stefan:
https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (5):
disas/nanomips: Fix invalid PRId64 format calling img_format() disas/nanomips: Fix invalid PRIx64 format calling img_format() disas/nanomips: Use G_GNUC_PRINTF to avoid invalid string formats disas/nanomips: Remove headers already included by "qemu/osdep.h"
MAINTAINERS: Inherit from nanoMIPS

Queued to mips-fixes.