From nobody Tue Nov 26 20:01:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1705997420; cv=none; d=zohomail.com; s=zohoarc; b=RF4EYhX7YqgOm+bFaWh6HL0u/MmoS0Di69GMd6+YPnxeMdKWwzwL+nhkJ9haLZfLQR8r0IB5SG2ob67SD/VWx1C0hEV/asZZYsRGQg/PMJfYe1X6ykBhlqiF7/Y/iyruVwC0tHX/mpcjdh18rzqbaToWIz7i7uvgVa+Z0VwjgNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705997420; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HkmrsuVbgTF+za7ZMeDRDBZqRcm/2ztx9jMk1UJC/m8=; b=GaDw2ITlbptXtGLMccbMcuJJeh3Kx0zTem1tUXPBKY6IExzIeWNuCmyyTTH4GMJ8SLIK+DrtgUI9lay1FR0/luzJc0Pm+9VgJ5xLRESXi7M0RHG+Sm0PebypUTpG5c5ojLJuuxvMLJUDAtUMdRJi89t4njU1AS18SjtCtpIOu/g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705997420487208.85362342522387; Tue, 23 Jan 2024 00:10:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSBqb-0001Ox-Ah; Tue, 23 Jan 2024 03:09:29 -0500 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 1rSBqY-0001Nu-Bc for qemu-devel@nongnu.org; Tue, 23 Jan 2024 03:09:26 -0500 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rSBqS-0006mg-4M for qemu-devel@nongnu.org; Tue, 23 Jan 2024 03:09:22 -0500 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-558f523c072so4647127a12.2 for ; Tue, 23 Jan 2024 00:09:19 -0800 (PST) Received: from localhost.localdomain (adsl-138.37.6.1.tellas.gr. [37.6.1.138]) by smtp.gmail.com with ESMTPSA id tb21-20020a1709078b9500b00a2f24da8baasm5794069ejc.39.2024.01.23.00.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 00:09:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705997358; x=1706602158; 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=HkmrsuVbgTF+za7ZMeDRDBZqRcm/2ztx9jMk1UJC/m8=; b=UiYaIKIB4tO52m8T1dfwXppozp/PGOyvgrNI2fRTrbGHyaSlPRlBikyKQnBAwTLgjg MEVrXE46HgxQMOpL+5HY2coSeeVJKFESuwOp6IDFedEDgs5Id1lAf7f4WkuxR9HnT/Bb MnDNZMNMKQ5qBJfzyxCjqgA/WP+Xc2FnorWTnkRyVUr174oL++4/yWoFFv+uJveTkSjv boIx+79L+YREW1Pcys21HoPcZ99qVn0rC52NYU1dfsStRMM4mA3hQEjiVIlWS5lvNUGV MVHsEUCPagnv9S1uHxlnIT9+Xc0aS2FHL/GNkZzJ0ybGE245AXp5EoY3xXQtVefPJD4n P2Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705997358; x=1706602158; 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=HkmrsuVbgTF+za7ZMeDRDBZqRcm/2ztx9jMk1UJC/m8=; b=rd0plafXzfZwH5H2re+AolCP//yeN4vP+w8QKesDgkOrjEWhL26YU2/n1mT0qRM5gm YkUS0N+HBMqn8yJwzy+K0xIAP7OQW1mXtzPWqyaEidFAlA4uvk1+qH834+UBTQO1wvC3 FAQQV8COH/nOnQ6OKRz4+Tu47R7vU2tP7NFWmtjVrpQytBoQnOnfQWVYb2WXQc4W4aI0 EcFZQbNvMmNC2QJ6WhbikyKFHJTSv6W8qsya4vrdNvAkhQKdoGg7ESBOEl+MswptycNW yYWnbHxB2gEIQxFaF/AxQPyijXiJysacQmTd5GCGwwCOgoeKTD/6MzjvT92bjcVGRlHi UjVg== X-Gm-Message-State: AOJu0Yxs0muL/s6p8g01QHXVp9NbXGfVhNpT9jFYlAevs33xL8JiQ1B1 Fim5RerOAexwt4AweCFnXvUtVUrEzFaNKZ1egXdZC35c3HMDS8XJUvO8DrW6EbJKg9MvwBFXpCL T/Ls= X-Google-Smtp-Source: AGHT+IGwNQnyGLhF25UbZLdaMt0Q9/tAZqtdtfe62R9H1jtMGBD9Yz8EMeq5zFQ5sRmxMr5h4qcxHg== X-Received: by 2002:a17:907:6899:b0:a2c:8dba:eb1b with SMTP id qy25-20020a170907689900b00a2c8dbaeb1bmr1588204ejc.112.1705997357765; Tue, 23 Jan 2024 00:09:17 -0800 (PST) From: Manos Pitsidianakis To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Subject: [PATCH 1/2] hw/core/qdev.c: add qdev_get_human_name() Date: Tue, 23 Jan 2024 10:09:12 +0200 Message-Id: <15b15d6d4f2a1706b5e2d85ab18e25bcb03e72c2.1705938003.git.manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-ed1-x52c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1705997421769100008 Content-Type: text/plain; charset="utf-8" Add a simple method to return some kind of human readable identifier for use in error messages. Signed-off-by: Manos Pitsidianakis --- 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; } =20 +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; =20 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); =20 +/** + * 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. + * + * 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); =20 --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89