From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PULL 14/18] qdev: Change PropertyInfo method print() to return malloc'ed string
Date: Tue, 28 Oct 2025 18:34:26 +0100 [thread overview]
Message-ID: <20251028173430.2180057-15-pbonzini@redhat.com> (raw)
In-Reply-To: <20251028173430.2180057-1-pbonzini@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
Simpler (more so after the next commit), and no risk of truncation
because the caller's buffer is too small. Performance doesn't matter;
the method is only used for "info qdev".
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Link: https://lore.kernel.org/r/20251022101420.36059-2-armbru@redhat.com
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/hw/qdev-properties.h | 2 +-
hw/core/qdev-properties-system.c | 7 +++----
hw/core/qdev-properties.c | 9 ++++-----
3 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 0197aa4995e..60b81330097 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -34,7 +34,7 @@ struct PropertyInfo {
const char *description;
const QEnumLookup *enum_table;
bool realized_set_allowed; /* allow setting property on realized device */
- int (*print)(Object *obj, const Property *prop, char *dest, size_t len);
+ char *(*print)(Object *obj, const Property *prop);
void (*set_default_value)(ObjectProperty *op, const Property *prop);
ObjectProperty *(*create)(ObjectClass *oc, const char *name,
const Property *prop);
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index c15371f8cd1..13cc91680b1 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -865,15 +865,14 @@ out:
visit_end_alternate(v, (void **) &alt);
}
-static int print_pci_devfn(Object *obj, const Property *prop, char *dest,
- size_t len)
+static char *print_pci_devfn(Object *obj, const Property *prop)
{
int32_t *ptr = object_field_prop_ptr(obj, prop);
if (*ptr == -1) {
- return snprintf(dest, len, "<unset>");
+ return g_strdup("<unset>");
} else {
- return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7);
+ return g_strdup_printf("%02x.%x", *ptr >> 3, *ptr & 7);
}
}
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index b7e8a89ba5c..422a486969c 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1117,12 +1117,11 @@ static void qdev_get_legacy_property(Object *obj, Visitor *v,
Error **errp)
{
const Property *prop = opaque;
+ char *s;
- char buffer[1024];
- char *ptr = buffer;
-
- prop->info->print(obj, prop, buffer, sizeof(buffer));
- visit_type_str(v, name, &ptr, errp);
+ s = prop->info->print(obj, prop);
+ visit_type_str(v, name, &s, errp);
+ g_free(s);
}
/**
--
2.51.1
next prev parent reply other threads:[~2025-10-28 17:36 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-28 17:34 [PULL 00/18] Miscellaneous changes for 2025-10-28 Paolo Bonzini
2025-10-28 17:34 ` [PULL 01/18] scripts: clean up meson-buildoptions.py Paolo Bonzini
2025-10-28 17:34 ` [PULL 02/18] i386/kvm/cpu: Init SMM cpu address space for hotplugged CPUs Paolo Bonzini
2025-10-29 7:01 ` Zhao Liu
2025-10-30 2:19 ` Xiaoyao Li
2025-10-30 7:36 ` Michael Tokarev
2025-10-30 7:49 ` Xiaoyao Li
2025-10-30 8:03 ` Michael Tokarev
2025-10-28 17:34 ` [PULL 03/18] rcu: Unify force quiescent state Paolo Bonzini
2025-11-03 13:59 ` Regression with the "replay" test on target alpha (was: [PULL 03/18] rcu: Unify force quiescent state) Thomas Huth
2025-11-04 1:45 ` Regression with the "replay" test on target alpha Akihiko Odaki
2025-11-04 7:41 ` Thomas Huth
2025-11-04 8:08 ` Akihiko Odaki
2025-11-04 8:38 ` Thomas Huth
2025-11-04 12:18 ` Paolo Bonzini
2025-11-05 6:29 ` Akihiko Odaki
2025-11-07 7:41 ` Thomas Huth
2025-11-07 7:49 ` Paolo Bonzini
2025-11-14 6:11 ` Thomas Huth
2025-11-18 16:22 ` Paolo Bonzini
2025-10-28 17:34 ` [PULL 04/18] rust: remove useless glib_sys bindings Paolo Bonzini
2025-10-28 17:34 ` [PULL 05/18] rust: only leave leaf crates as workspace members Paolo Bonzini
2025-10-28 17:34 ` [PULL 06/18] qobject: make refcount atomic Paolo Bonzini
2025-10-28 17:34 ` [PULL 07/18] char: rename CharBackend->CharFrontend Paolo Bonzini
2025-10-28 17:34 ` [PULL 08/18] accel/mshv: initialize thread name Paolo Bonzini
2025-10-28 17:34 ` [PULL 09/18] accel/mshv: use return value of handle_pio_str_read Paolo Bonzini
2025-10-28 17:34 ` [PULL 10/18] esp.c: fix esp_cdb_ready() FIFO wraparound limit calculation Paolo Bonzini
2025-10-29 11:42 ` Michael Tokarev
2025-10-28 17:34 ` [PULL 11/18] qtest/am53c974-test: add additional test for cmdfifo overflow Paolo Bonzini
2025-10-28 17:34 ` [PULL 12/18] rust/qemu-macros: Convert bit value to u8 within #[property] Paolo Bonzini
2025-10-28 17:34 ` [PULL 13/18] scsi: make SCSIRequest refcount atomic Paolo Bonzini
2025-10-28 17:34 ` Paolo Bonzini [this message]
2025-10-28 17:34 ` [PULL 15/18] hw/i386/isapc.c: warn rather than reject modern x86 CPU models Paolo Bonzini
2025-10-28 17:34 ` [PULL 16/18] docs/about/deprecated.rst: document isapc deprecation for " Paolo Bonzini
2025-10-28 17:34 ` [PULL 17/18] target/i386: clear CPU_INTERRUPT_SIPI for all accelerators Paolo Bonzini
2025-10-28 17:34 ` [PULL 18/18] rust: migration: allow passing ParentField<> to vmstate_of! Paolo Bonzini
2025-10-29 6:34 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251028173430.2180057-15-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).