From patchwork Wed Apr 10 16:06:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1922128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=uBKqE6xB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VF75h41Hcz1yY8 for ; Thu, 11 Apr 2024 02:07:52 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ruaTZ-0000Sg-L7; Wed, 10 Apr 2024 12:07:07 -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 1ruaTX-0000Ru-66 for qemu-ppc@nongnu.org; Wed, 10 Apr 2024 12:07:03 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ruaTV-0002iN-GB for qemu-ppc@nongnu.org; Wed, 10 Apr 2024 12:07:02 -0400 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a51d3193e54so415036866b.2 for ; Wed, 10 Apr 2024 09:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712765219; x=1713370019; 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=iYu1kmJUzwiQNwtOT3Hu+HqZtkyD9XR4Mu5bcSA+DO0=; b=uBKqE6xB1DFp/3Cl4RBPdgOBXi7v8hIAJH1Blz6plkPcSoURFlI/JYJvWCBauO4oje t3xjuf37JYjmTlXaVKPOT5s+J+FiPTAakrkZj215VL5PTr8j+dgwrz5D1C35rw82Ayfy bCAGHjH1HOhBzDSa0T+jSOxR0CGlemc049QD8ylHUwin0m3V9yR09LXH67B/uMxEfoLp 79fDgWhZy/Wnx8jDkYG2omddV348EgtcybYiBLLb+zBgB38xZIx47gTEqln7hl6zMtzq fZGDRlV3VHkraWXCNpNbUxMRwzWECf92PXkCGTxF+dSQN1yCibV5Jcv4lqo7jkGTwrQJ p/Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712765219; x=1713370019; 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=iYu1kmJUzwiQNwtOT3Hu+HqZtkyD9XR4Mu5bcSA+DO0=; b=XMgBP3MMa/120yc2IX6UJggbF68sNmOq0bSb5KeOjuqyS+F8h0hGLA5M4HvpDI7qUy e74Yh7ywMZJJuAeicHPrqeTpt+AtGy1fF79rcBFrpaYdH2eLv0Qi4grc49RpXFwGulRm McKYDqMCLvYmVsZnN56hotTuHF11vBHcpF5xVmaOaBGyKL2IaFNXhuzjg+SsbjacJml9 0/Wi0o9zbng8eAttrvXIguBScrM9HmfhMy5BpCIttMKdeQwVpxQ/Q1BDtS7Jhx8Ffs7v XzT+TkdvAYKG9ZfAwKfLaotG0d1CodHJRJP9MHpurOrsiDOHH8wFOPgsZzLD2U5+GZGl MMXg== X-Gm-Message-State: AOJu0YxW/aYTc5IV0BK0jYhvuIbT6FeUzzRALHrKTcAsHUfVHlej3qdK q3ppNcD+5Q82lE4GFWx0jCMjFN3PraXJEki3nHcXqf3B5oAO365QaUbqfGxEvI8= X-Google-Smtp-Source: AGHT+IFfyJmXj9qpaTvYnb1Kun5xr+yN68VIsReEgz93N4vNYb8NOrw29uIlr1DtqEaY0QcaS9OWMA== X-Received: by 2002:a17:907:7e97:b0:a51:b0e1:863f with SMTP id qb23-20020a1709077e9700b00a51b0e1863fmr2426735ejc.13.1712765219100; Wed, 10 Apr 2024 09:06:59 -0700 (PDT) Received: from m1x-phil.lan (arl95-h02-176-184-34-173.dsl.sta.abo.bbox.fr. [176.184.34.173]) by smtp.gmail.com with ESMTPSA id t1-20020a1709067c0100b00a46aac377e8sm7089906ejo.54.2024.04.10.09.06.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Apr 2024 09:06:58 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" Subject: [PATCH 07/12] util/hexdump: Have qemu_hexdump_line() return heap allocated buffer Date: Wed, 10 Apr 2024 18:06:08 +0200 Message-ID: <20240410160614.90627-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240410160614.90627-1-philmd@linaro.org> References: <20240410160614.90627-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=philmd@linaro.org; helo=mail-ej1-x630.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 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-ppc@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-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé --- include/qemu/cutils.h | 10 +++++++--- hw/virtio/vhost-vdpa.c | 5 +++-- util/hexdump.c | 12 ++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 70ca4b876b..e8d6b86098 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -254,18 +254,22 @@ int parse_debug_env(const char *name, int max, int initial); /** * qemu_hexdump_line: - * @line: Buffer to be filled by the hexadecimal/ASCII dump * @bufptr: Buffer to dump * @offset: Offset within @bufptr to start the dump * @len: Length of the bytes do dump * @ascii: Replace non-ASCII characters by the dot symbol * * Hexdump a line of a byte buffer into a hexadecimal/ASCII buffer + * + * The caller must use g_free() to free the returned data when it is + * no longer required. + * + * Returns: Hexadecimal/ASCII dump */ #define QEMU_HEXDUMP_LINE_BYTES 16 /* Number of bytes to dump */ #define QEMU_HEXDUMP_LINE_LEN 75 /* Number of characters in line */ -void qemu_hexdump_line(char *line, const void *bufptr, unsigned offset, - unsigned int len, bool ascii); +char *qemu_hexdump_line(const void *bufptr, unsigned offset, + unsigned int len, bool ascii); /* * Hexdump a buffer to a file. An optional string prefix is added to every line diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index cf7cfa3f16..e61af86d9d 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -942,12 +942,13 @@ static void vhost_vdpa_dump_config(struct vhost_dev *dev, const uint8_t *config, uint32_t config_len) { int ofs, len; - char line[QEMU_HEXDUMP_LINE_LEN]; + char *line; for (ofs = 0; ofs < config_len; ofs += 16) { len = config_len - ofs; - qemu_hexdump_line(line, config, ofs, len, false); + line = qemu_hexdump_line(config, ofs, len, false); trace_vhost_vdpa_dump_config(dev, line); + g_free(line); } } diff --git a/util/hexdump.c b/util/hexdump.c index 469083d8c0..b6f70e93bb 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -16,9 +16,10 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" -void qemu_hexdump_line(char *line, const void *bufptr, unsigned offset, - unsigned int len, bool ascii) +char *qemu_hexdump_line(const void *bufptr, unsigned offset, + unsigned int len, bool ascii) { + char linebuf[QEMU_HEXDUMP_LINE_BYTES], *line = linebuf; const char *buf = bufptr; int i, c; @@ -48,18 +49,21 @@ void qemu_hexdump_line(char *line, const void *bufptr, unsigned offset, } } *line = '\0'; + + return g_strdup(linebuf); } void qemu_hexdump(FILE *fp, const char *prefix, const void *bufptr, size_t size) { unsigned int ofs, len; - char line[QEMU_HEXDUMP_LINE_LEN]; + char *line; for (ofs = 0; ofs < size; ofs += QEMU_HEXDUMP_LINE_BYTES) { len = size - ofs; - qemu_hexdump_line(line, bufptr, ofs, len, true); + line = qemu_hexdump_line(bufptr, ofs, len, true); fprintf(fp, "%s: %s\n", prefix, line); + g_free(line); } }