From patchwork Thu Apr 11 10:15:44 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: 787951 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp150036wrm; Thu, 11 Apr 2024 03:21:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVMoW0Pn0gK6IwjuKK3XNQ/WiFvHA462WQJRH5z1nmA1KVrMsmMTNl3KyLyAuvR+eFGCZt7k8G7anhWFlMJojuu X-Google-Smtp-Source: AGHT+IEvxa3cD+utB1G5XE57kzSoggmuIQHowJAS3ekCwYUMb3gGtNE6SMNqUsQDoLDgcBNGDu2W X-Received: by 2002:a05:622a:492:b0:431:2a50:e15 with SMTP id p18-20020a05622a049200b004312a500e15mr5660162qtx.39.1712830883540; Thu, 11 Apr 2024 03:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712830883; cv=none; d=google.com; s=arc-20160816; b=Xjz7owLJtFvbaaI3CUuTdTSY/In49UHZScHrDx6D/EJhNh5LZdiRBrvwKBThd6y13K Le5ycNywiTbngZXUtdB4/Gn6ayDbuvPB1gpPqjP3EvrlhsPehnFj5ko9J9KkcytHMNLu 7Aztl0WQuddDjV9r+RJv4cr7ntQE8JOtChJD2atl8SLp/lwu7yd4RWyDOm+cwUhuOr/y YmCrI9IMYyfM75c/hZVzqVICxU5nY8rSfBQLsKAkMcS1rUxxQtjG88S9Q5uFkA6ofIFz PHs8KOGTfoevUBBDN04mjsKzfuK+e1qZWeZiQN+zRiItP2pmjbiP5waJnzWeFSei0cxI 3QNw== 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=iYu1kmJUzwiQNwtOT3Hu+HqZtkyD9XR4Mu5bcSA+DO0=; fh=wiz1UHo9SeP7cKsyv7qV5qfZpy+eOFaJKdMduwsqX+g=; b=C6T7hzdk5pIoYXLNkEwkoFOWS1N9dsCmbARhfa6l2Y3vNCgax9pjx62U0pakLsn1q6 DTC4dSTaGQABMWrXrAH7pklb7mj7sBmSJzElrtJfkoinuGSre8jWeULnJ8L3XjA0QVbI WS2nbQuEnJojWmyjxEP6iJHzGtJTbotp0OYBptlHzM2YHtgy07U98gtJrBAou0AJMiCN 9WEwHfNUdR9dsMZ3tQGF78nHwnsCxdekVMSj0DSg3m15Qcdy4NL0JPgHRy7CdTJFYRqS +Uk6CUzu5aaoTkrs2FnrjKQImaLDg4Azkmk/G3qKTg5OmSp1722Bu3GY+RE7U/oP8Q+B WNGg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="U6k/BHCw"; 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 a15-20020a05622a02cf00b0043663accfb4si919115qtx.426.2024.04.11.03.21.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Apr 2024 03:21:23 -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="U6k/BHCw"; 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 1rurUv-00067E-Mx; Thu, 11 Apr 2024 06:17:37 -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 1rurU6-0005Hg-Bk for qemu-devel@nongnu.org; Thu, 11 Apr 2024 06:16:47 -0400 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rurU4-0007Xu-FJ for qemu-devel@nongnu.org; Thu, 11 Apr 2024 06:16:46 -0400 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2d700beb6beso82827231fa.2 for ; Thu, 11 Apr 2024 03:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712830602; x=1713435402; 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=U6k/BHCwgJFABigzB8R+bTpGMo28cYY+vNyrudGuDwq1DJYL2lhXDfgjt3muytAsxA vP+xn1te8pMdZ6luDwKbW5odiXZYp8i3Faubm9B9z0Nncgf/b6/72c3I0nr5mkQtEaAP iPADb5sEiJmcuZgoDKuCW0ieFql3hZzaWA+LlZljQpSbih+fAzT+grI7AncvMdHePOdc +28tTx2bHK9S5lhrUXN9VtBdttNbZibdWQELUcrvRhpak0jn5G7nw82GJqiDHdetu9lY MK0LvgZQ9s9Icmkf+raAusEUmFnFeWdbFK6AMlefBCrU9rClOT9Es4CgciEWeWqdnNgD InRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712830602; x=1713435402; 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=cCO5JvbOkDBEXCo56d7DQN6o97lUmvuiMdblLfj10RvD4mLvyqp5DLsB7bnXzkybVi F6onU1Tue8mk6fvi3IBgYn/C9jPxzACbhzED1kxG7OnLa7ksHkM98zcx7q0zohTv2QTz 6jPSp1TwPhorrQgSL+cg3kw28OIbH3+T6tyOJTVLhd5LR+8xAPFreizGkIFj7bswkSaT PpZ/gKfmUb4iCoZUz5BVpO8OnZyX3SCXT+HPW2ri0zSm218tudl09ev5TsvBDnuxt/Rf o4mzqPWjRS6KGf3PDDO0+tu4phgLlwFCF4ho0rlrm52Es+PTkEuHc2NqiGNvXU6TWxNx ttRg== X-Gm-Message-State: AOJu0YyTt7i0b1uy5g+5n5na/Iyf7YtVgy0m/VRT6cM1JnUfxtQ3N21R Zlhheqj2z3etP5D7DEOIapoNMjo7X9k49PBHDPtZljMrEMYK1+0XA8i5Lq+t5A941VUH6Q1feeF +EWk= X-Received: by 2002:a2e:9219:0:b0:2d8:d23a:f440 with SMTP id k25-20020a2e9219000000b002d8d23af440mr2454866ljg.6.1712830602221; Thu, 11 Apr 2024 03:16:42 -0700 (PDT) Received: from localhost.localdomain (137.red-88-29-174.dynamicip.rima-tde.net. [88.29.174.137]) by smtp.gmail.com with ESMTPSA id p5-20020a05600c1d8500b00417e227f40bsm740594wms.3.2024.04.11.03.16.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 Apr 2024 03:16:41 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-ppc@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" Subject: [PATCH v2 08/13] util/hexdump: Have qemu_hexdump_line() return heap allocated buffer Date: Thu, 11 Apr 2024 12:15:44 +0200 Message-ID: <20240411101550.99392-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240411101550.99392-1-philmd@linaro.org> References: <20240411101550.99392-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::231; envelope-from=philmd@linaro.org; helo=mail-lj1-x231.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-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 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); } }