[PATCH 14/89] linux-user/i386: Return const data from get_elf_platform

Richard Henderson posted 89 patches 3 months, 2 weeks ago
Maintainers: Riku Voipio <riku.voipio@iki.fi>, Laurent Vivier <laurent@vivier.eu>, Brian Cain <brian.cain@oss.qualcomm.com>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
[PATCH 14/89] linux-user/i386: Return const data from get_elf_platform
Posted by Richard Henderson 3 months, 2 weeks ago
Rather than modify a static buffer, index into an array
of const data.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/i386/elfload.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/linux-user/i386/elfload.c b/linux-user/i386/elfload.c
index cc75b4f2d9..6a79738786 100644
--- a/linux-user/i386/elfload.c
+++ b/linux-user/i386/elfload.c
@@ -12,13 +12,9 @@ abi_ulong get_elf_hwcap(CPUState *cs)
 
 const char *get_elf_platform(CPUState *cs)
 {
-    static char elf_platform[] = "i386";
+    static const char elf_platform[4][5] = { "i386", "i486", "i586", "i686" };
     int family = object_property_get_int(OBJECT(cs), "family", NULL);
-    if (family > 6) {
-        family = 6;
-    }
-    if (family >= 3) {
-        elf_platform[1] = '0' + family;
-    }
-    return elf_platform;
+
+    family = MAX(MIN(family, 6), 3);
+    return elf_platform[family - 3];
 }
-- 
2.43.0
Re: [PATCH 14/89] linux-user/i386: Return const data from get_elf_platform
Posted by Peter Maydell 3 months, 2 weeks ago
On Wed, 30 Jul 2025 at 01:34, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Rather than modify a static buffer, index into an array
> of const data.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/i386/elfload.c | 12 ++++--------

I was thinking as I reviewed the previous patch that the
implementation of that function was pretty ugly :-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM