From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
To: "Philippe Mathieu-Daudé " <philmd@linaro.org>,
qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé " <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>
Subject: Re: [PATCH 1/2] hw/core/qdev.c: add qdev_get_human_name()
Date: Tue, 23 Jan 2024 10:15:25 +0200 [thread overview]
Message-ID: <7pgcr.qacudqer98uf@linaro.org> (raw)
In-Reply-To: <1c9c1750-d9c4-4743-afa4-7fafc1f82ed8@linaro.org>
On Tue, 23 Jan 2024 10:13, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>Hi Manos,
>
>On 23/1/24 09:09, Manos Pitsidianakis wrote:
>> Add a simple method to return some kind of human readable identifier for
>> use in error messages.
>>
>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>> ---
>> hw/core/qdev.c | 10 ++++++++++
>> include/hw/qdev-core.h | 15 +++++++++++++++
>> 2 files changed, 25 insertions(+)
>>
>> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
>> index 43d863b0c5..499f191826 100644
>> --- a/hw/core/qdev.c
>> +++ b/hw/core/qdev.c
>> @@ -879,6 +879,16 @@ Object *qdev_get_machine(void)
>> return dev;
>> }
>>
>> +char *qdev_get_human_name(DeviceState *dev)
>> +{
>> + if (!dev) {
>> + return g_strdup("");
>> + }
>> +
>> + return dev->id ?
>> + g_strdup(dev->id) : object_get_canonical_path(OBJECT(dev));
>> +}
>> +
>> static MachineInitPhase machine_phase;
>>
>> bool phase_check(MachineInitPhase phase)
>> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
>> index 151d968238..a8c742b4a3 100644
>> --- a/include/hw/qdev-core.h
>> +++ b/include/hw/qdev-core.h
>> @@ -993,6 +993,21 @@ const char *qdev_fw_name(DeviceState *dev);
>> void qdev_assert_realized_properly(void);
>> Object *qdev_get_machine(void);
>>
>> +/**
>> + * qdev_get_human_name() - Return a human-readable name for a device
>> + * @dev: The device
>> + *
>> + * .. note::
>> + * This function is intended for user friendly error messages.
>> + *
>> + * Returns: A newly allocated string containing the device id if not null,
>> + * else the object canonical path if not null. If @dev is NULL, it returns an
>> + * allocated empty string.
>
>In which case do we want to call this with NULL?
None I could think of, just future-proofing the NULL case.
>> + *
>> + * Use g_free() to free it.
>> + */
>> +char *qdev_get_human_name(DeviceState *dev);
>> +
>> /* FIXME: make this a link<> */
>> bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp);
>>
>
next prev parent reply other threads:[~2024-01-23 8:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 8:09 [PATCH 0/2] hw/block/block.c: improve confusing error Manos Pitsidianakis
2024-01-23 8:09 ` [PATCH 1/2] hw/core/qdev.c: add qdev_get_human_name() Manos Pitsidianakis
2024-01-23 8:13 ` Philippe Mathieu-Daudé
2024-01-23 8:15 ` Manos Pitsidianakis [this message]
2024-01-23 8:23 ` Philippe Mathieu-Daudé
2024-01-23 8:09 ` [PATCH 2/2] hw/block/block.c: improve confusing blk_check_size_and_read_all() error Manos Pitsidianakis
2024-01-23 8:12 ` Philippe Mathieu-Daudé
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=7pgcr.qacudqer98uf@linaro.org \
--to=manos.pitsidianakis@linaro.org \
--cc=berrange@redhat.com \
--cc=eduardo@habkost.net \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--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).