aboutsummaryrefslogtreecommitdiff
path: root/hw/mips/malta.c
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé <philmd@linaro.org>2024-04-12 00:33:25 -0700
committerRichard Henderson <richard.henderson@linaro.org>2024-06-05 12:14:20 -0700
commit3a8ff3667187459427eef5c6b1cdb950c563e094 (patch)
treee42dc07bd4ea46cb31894bad9e09c41651e92efa /hw/mips/malta.c
parent10e4927bc4c5ad673e12c0731e6150050cf327de (diff)
downloadqemu-3a8ff3667187459427eef5c6b1cdb950c563e094.zip
qemu-3a8ff3667187459427eef5c6b1cdb950c563e094.tar.gz
qemu-3a8ff3667187459427eef5c6b1cdb950c563e094.tar.bz2
hw/mips/malta: Add re-usable rng_seed_hex_new() method
sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1. Extract common code from reinitialize_rng_seed and load_kernel to rng_seed_hex_new. Using qemu_hexdump_line both fixes the deprecation warning and simplifies the code base. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> [rth: Use qemu_hexdump_line.] Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Message-Id: <20240412073346.458116-7-richard.henderson@linaro.org>
Diffstat (limited to 'hw/mips/malta.c')
-rw-r--r--hw/mips/malta.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/hw/mips/malta.c b/hw/mips/malta.c
index af74008..664a2ae 100644
--- a/hw/mips/malta.c
+++ b/hw/mips/malta.c
@@ -26,6 +26,7 @@
#include "qemu/units.h"
#include "qemu/bitops.h"
#include "qemu/datadir.h"
+#include "qemu/cutils.h"
#include "qemu/guest-random.h"
#include "hw/clock.h"
#include "hw/southbridge/piix.h"
@@ -850,15 +851,18 @@ static void G_GNUC_PRINTF(3, 4) prom_set(uint32_t *prom_buf, int index,
va_end(ap);
}
-static void reinitialize_rng_seed(void *opaque)
+static GString *rng_seed_hex_new(void)
{
- char *rng_seed_hex = opaque;
uint8_t rng_seed[32];
qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
- for (size_t i = 0; i < sizeof(rng_seed); ++i) {
- sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]);
- }
+ return qemu_hexdump_line(NULL, rng_seed, sizeof(rng_seed), 0, 0);
+}
+
+static void reinitialize_rng_seed(void *opaque)
+{
+ g_autoptr(GString) hex = rng_seed_hex_new();
+ memcpy(opaque, hex->str, hex->len);
}
/* Kernel */
@@ -870,8 +874,6 @@ static uint64_t load_kernel(void)
uint32_t *prom_buf;
long prom_size;
int prom_index = 0;
- uint8_t rng_seed[32];
- char rng_seed_hex[sizeof(rng_seed) * 2 + 1];
size_t rng_seed_prom_offset;
kernel_size = load_elf(loaderparams.kernel_filename, NULL,
@@ -946,14 +948,13 @@ static uint64_t load_kernel(void)
prom_set(prom_buf, prom_index++, "modetty0");
prom_set(prom_buf, prom_index++, "38400n8r");
- qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
- for (size_t i = 0; i < sizeof(rng_seed); ++i) {
- sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]);
- }
prom_set(prom_buf, prom_index++, "rngseed");
rng_seed_prom_offset = prom_index * ENVP_ENTRY_SIZE +
sizeof(uint32_t) * ENVP_NB_ENTRIES;
- prom_set(prom_buf, prom_index++, "%s", rng_seed_hex);
+ {
+ g_autoptr(GString) hex = rng_seed_hex_new();
+ prom_set(prom_buf, prom_index++, "%s", hex->str);
+ }
prom_set(prom_buf, prom_index++, NULL);