From nobody Mon Nov 25 05:30:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717622179; cv=none; d=zohomail.com; s=zohoarc; b=kq4hzLGYyqve4aXaMOsTylZJc1sIYo2Y3REZPf957UyAtCuDWpvF6OF5veogbCIZJ4lFH+arCtfxGTalxK5KfEeIxmattb3WGBqjMG2CCzH9GHgS2Hw3M0eMyOXB1rNhtP5ZijvVj8V/wb6VkShJ8q0LaLfLTcVFr+ZX59adZB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717622179; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BA7oin0aTWc6AVl6UHRopsqXqPUuD9tfreQpdBVLhl8=; b=R7Ei8pAGFlUASy7qLpY8FffOiNGTiYzeYO/NxF2lfpn+ip6vh3IDdsGnUjG8TiNXKvRx+xO+GcR3ugENjYzlofHs5iu7E6+usw/XgAWhaqbVTgu3s+jf8aNKGkD23aOAy3k6arFx/6luy6gDpOUFX2FnaXT33HtMpneKf5NZO1s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717622179716894.7951736733711; Wed, 5 Jun 2024 14:16:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sExyv-0000ct-2g; Wed, 05 Jun 2024 17:15:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sExyt-0000cC-5H for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:39 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyi-0003Pb-8I for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:36 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-70249faa853so185198b3a.3 for ; Wed, 05 Jun 2024 14:15:27 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622126; x=1718226926; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BA7oin0aTWc6AVl6UHRopsqXqPUuD9tfreQpdBVLhl8=; b=iU0qnl2qfQDmYuo1qAuthBgF8N/Cn0hRqIgb9bretfYubueqser2bEKndADPZqilHi MlimSH5sEkFCGqDkAwCzDlV/QzqGw8isB43cgl7o0YjzbKa9XFp1xpdgYEDltM8zmL/T phxNi2ggH9B+m3yzAc8tI8P/BapNX+oyQYCDmKq528uDRKTf3n9JfRgYc749Wckex38i o7SU2WpgXrSP8jl0WwANhsU69GOVqcyHyxvBBC54tLWgkQrU/vcFiAnVtzzmaDb8BDLo D4sEXUmTQQkFgJWk8FvE8i7EQMssy8R9RWWnIOOI/uIcAs64waaXKIlT9K/wpCOmAntP EqjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622126; x=1718226926; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BA7oin0aTWc6AVl6UHRopsqXqPUuD9tfreQpdBVLhl8=; b=j/y45uxH4EKNrwlsmjChXh9OH8LzVWUJ6ZTRAqbCugl3G0W413U3rNqyTPIG3jPIkq uVCfKBm5sT8O/+Rg1sRZrC9uKOtxmpzsok+lMmuSW6Ns3frIZab6QAptFUi0Ht7RYrYy S1SVNIEuzNpiCQqPwkhCps3SWaU4fwomBCG6snUg3cjGVqUxh0GJoXEAUISvBw3Zo0ZX nUPT5wvsxgtGSDzo9J7vS21Cop7Shbbx3bxhcdsBdn5hEIYv9k2c+C8RCpMa//4yIEEZ Ygc36BF4PqGMnOGNYJEsVsj5LtoDyl4n+Q83NaTYg05KKC5DZk4dB5u+h3ONUY4NJGYY aW3w== X-Gm-Message-State: AOJu0Yys9UyYfvTKSGwp19d+Z/fOInSEjS2j8xh+7J3oMBw71hoTPJKM 6R8ad2GO3mw46Gn2YC3XSAnh4xXXoSyoRmTDsNLtX17nfaHYPRQVku3DDFZv4v2pMWHr5uFSMSF n X-Google-Smtp-Source: AGHT+IEDxkpE0PjbyH28nkbaDNmfBdtYsla0vA+D1i5jzdQV1AU+iq3VSZoa54e6+1yoVnELCugRFg== X-Received: by 2002:a05:6a20:7348:b0:1af:f8e7:76d4 with SMTP id adf61e73a8af0-1b2b6ed9cbemr4875899637.18.1717622126493; Wed, 05 Jun 2024 14:15:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Pierrick Bouvier Subject: [PULL 04/16] hw/mips/malta: Add re-usable rng_seed_hex_new() method Date: Wed, 5 Jun 2024 14:15:09 -0700 Message-Id: <20240605211521.577094-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717622181235100011 From: Philippe Mathieu-Daud=C3=A9 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=C3=A9 [rth: Use qemu_hexdump_line.] Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-7-richard.henderson@linaro.org> --- hw/mips/malta.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/hw/mips/malta.c b/hw/mips/malta.c index af74008c82..664a2ae0a9 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 *pr= om_buf, int index, va_end(ap); } =20 -static void reinitialize_rng_seed(void *opaque) +static GString *rng_seed_hex_new(void) { - char *rng_seed_hex =3D opaque; uint8_t rng_seed[32]; =20 qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); - for (size_t i =3D 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 =3D rng_seed_hex_new(); + memcpy(opaque, hex->str, hex->len); } =20 /* Kernel */ @@ -870,8 +874,6 @@ static uint64_t load_kernel(void) uint32_t *prom_buf; long prom_size; int prom_index =3D 0; - uint8_t rng_seed[32]; - char rng_seed_hex[sizeof(rng_seed) * 2 + 1]; size_t rng_seed_prom_offset; =20 kernel_size =3D 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"); =20 - qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); - for (size_t i =3D 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 =3D 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 =3D rng_seed_hex_new(); + prom_set(prom_buf, prom_index++, "%s", hex->str); + } =20 prom_set(prom_buf, prom_index++, NULL); =20 --=20 2.34.1