From patchwork Wed Jun 5 21:15:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801634 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36294wrv; Wed, 5 Jun 2024 14:16:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXBz4ubmehd+NzzyMLPFLiF5zftNy5f0pcHJF3BAcb1hkHVnj31aYK3I/0Zkx8QeRoLxlCCGfXNaUw/8ELsgotS X-Google-Smtp-Source: AGHT+IEOlhNd/ZJUuf6H6dzHYq67jc2BzccGvrMEAWhr7a9XW8NnCdBXs9SZmj+UFoeVS6meTf1m X-Received: by 2002:a05:6214:3b86:b0:6ae:24da:ba2b with SMTP id 6a1803df08f44-6b04ccd8285mr6684896d6.60.1717622179623; Wed, 05 Jun 2024 14:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622179; cv=none; d=google.com; s=arc-20160816; b=sEwbvinrbs/FZPY1Lo/gi5QufoyrYvFp5TG2H7vyACN8mrzDEBQTDUioCYEP45rlxk AQnmqSKEJZWj8KsfM0wqyAQRpwlvQ7m/ZisEi4HxpTRwPK4cdsbBnGVmnZrjs51xYN4M IHiDGEM7FfcnZz06f5Za36YxFypxeuqXW+/1dksOMib8XcNQgtHsuIyNrJ2JTKUhecOO UzS8tXJOHQ/3KzGG8d41KYlVbD/EPxAk0uIznbhTr2SaXp/CWdb2Zv+lTc3pQzGcVLuA 9ZVLKMZhXCu2UGbgrksHUF9vxtN2lZOkAWdDeyXS+8a2wy52WAYDe8aZJgYUE3IyZM40 YXmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BA7oin0aTWc6AVl6UHRopsqXqPUuD9tfreQpdBVLhl8=; fh=i/pWNGcx7KiR3ewgypxpPkuORYlkCnVXLqKVm9/UgNc=; b=i3yA3a5TJlwL4PLr0VtqSNKA+5epCsk9Tm6jvVWPrOLJkgoYBoBtPnk9UTNceU4EXU l30WVagAduFobrT6+nCSKrNi40/4Qz4mDycrD21CeR8M17hNgbJMu75DdwhnawHb1/JO 1kC9QGbKtdMdw9b8/CJ24D3nRNAN/1l11O84xlNsR23XjijPKKDFwCVP4E6+hlYxZOzV pI5gjG8WZMS+cL6RBbkdJwMrxYnpC5wLEJ7noEuJWLW6ltPthQI3CBauk0eNHd5d8Mgw vfUEWNqdkLt82wrU+Zotr1OcoHlmLumhREm4RImvSRut9WXSlRRMT/6Db4kCamTKRmIr myyA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iU0qnl2q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-44038a6eb6csi80311cf.153.2024.06.05.14.16.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:16:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iU0qnl2q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé 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é [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 *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);