From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B465C433F5 for ; Wed, 13 Oct 2021 07:11:29 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A301E60E78 for ; Wed, 13 Oct 2021 07:11:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A301E60E78 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.207953.363946 (Exim 4.92) (envelope-from ) id 1maYPp-00027X-2b; Wed, 13 Oct 2021 07:11:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 207953.363946; Wed, 13 Oct 2021 07:11:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1maYPo-00027Q-Vo; Wed, 13 Oct 2021 07:11:04 +0000 Received: by outflank-mailman (input) for mailman id 207953; Wed, 13 Oct 2021 07:11:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1maYPn-00027K-6I for xen-devel@lists.xenproject.org; Wed, 13 Oct 2021 07:11:03 +0000 Received: from mail-io1-xd2c.google.com (unknown [2607:f8b0:4864:20::d2c]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b076813f-9614-4a15-8cb7-a20874ef10d4; Wed, 13 Oct 2021 07:11:02 +0000 (UTC) Received: by mail-io1-xd2c.google.com with SMTP id q205so1667133iod.8 for ; Wed, 13 Oct 2021 00:11:01 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b076813f-9614-4a15-8cb7-a20874ef10d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PuD4x/quwdKwmCZMAPno27Mt5WkSyZcD2cupRATIQmA=; b=hUpeBm07ZhmU+R92qTIFSrBL14OeFHZ6uD4IZbV6GtgXTzhgOqStOEWSiPJEWuGj4t 4zuWiSkqFTm3AGGU2NR38KTYSKWPxOtEcdS4Ai/3r1akHkT61Jp+XPc9Zl1qrzwNyPwA TnX/xusNsfu2j+x4p6dymMk+gwlKDmH0z9qb8RZ1yOpGX8JaH+u2u3i10cFfQzzpQZKA gzhXJSBzjJDyKX/O/RiXSwFRjlfOrTHayIFv4RaRpmQwTkqpQYJmnggmAwOE8fiqTWjc lItwI007UCAJqN+GP5GKmGAqMrKlXFHSwRjzOn5t6E5+kri8uC+0X+pm6KhlPDRrs3ON wktA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PuD4x/quwdKwmCZMAPno27Mt5WkSyZcD2cupRATIQmA=; b=NcV3jJegfe6hKWDUMYA1LoS8Q11mPnQlRU8+p9Cty/g8HW9P51Sa+VUPMXcsG/SJVa 1PPQ/45FkH4uKoyETD5OPawKG056GVhwoJNxpoVcJbUo+dIOMhTkZ0e4/cDEjuJkVsEP kFR+nR9M3pahRH6nqbqH04SVMabMYTc/eaomnTqTYh7rVLM3lzc04+VI9vmOX4xk506D NjwrC79a4w5oOigJKGMMqcjfhcRU9flG2UO9gmRIiVgnODfLLrK+Ri8Z9JGqP84h1sLB i43IBJbca5J45Aup5ejlMVIJ3zTY/Nov9VmLai9DeCzWky1VHuvEV7sSHyYMoYbBUr1J uj4A== X-Gm-Message-State: AOAM530TcDmt4QutRZl9uBqITkLsFB3TQUxqXOKS4dN0d36/6oOvDv8j fxuIOoIxCISfZwF1uIxsIgiKdOk/kmw8Stz+MJmJv5jlhHNQPw== X-Google-Smtp-Source: ABdhPJzyNaV6p60H1ka7FNoMSrAfpLbPjQqSVej3WyYM+u5LpMnq8d8d2K/hoKgv951cKI2obB3JFtyY4qhuLjUoOBw= X-Received: by 2002:a05:6638:9a:: with SMTP id v26mr11895732jao.18.1634109061530; Wed, 13 Oct 2021 00:11:01 -0700 (PDT) MIME-Version: 1.0 References: <20210922161405.140018-1-damien.hedde@greensocs.com> <20210922161405.140018-5-damien.hedde@greensocs.com> In-Reply-To: <20210922161405.140018-5-damien.hedde@greensocs.com> From: Alistair Francis Date: Wed, 13 Oct 2021 17:10:35 +1000 Message-ID: Subject: Re: [RFC PATCH v2 04/16] softmmu/qdev-monitor: add error handling in qdev_set_id To: Damien Hedde Cc: "qemu-devel@nongnu.org Developers" , Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , "open list:X86" , Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , "open list:RISC-V" , =?UTF-8?Q?Daniel_P=2E_Berrang=C3=A9?= , Mark Burton , Edgar Iglesias , Igor Mammedov Content-Type: text/plain; charset="UTF-8" On Thu, Sep 23, 2021 at 2:29 AM Damien Hedde wrote: > > qdev_set_id() is mostly used when the user adds a device (using > -device cli option or device_add qmp command). This commit adds > an error parameter to handle the case where the given id is > already taken. > > Also document the function and add a return value in order to > be able to capture success/failure: the function now returns the > id in case of success, or NULL in case of failure. > > The commit modifies the 2 calling places (qdev-monitor and > xen-legacy-backend) to add the error object parameter. > > Note that the id is, right now, guaranteed to be unique because > all ids came from the "device" QemuOptsList where the id is used > as key. This addition is a preparation for a future commit which > will relax the uniqueness. > > Signed-off-by: Damien Hedde Reviewed-by: Alistair Francis Alistair > --- > include/monitor/qdev.h | 25 +++++++++++++++++++++++- > hw/xen/xen-legacy-backend.c | 3 ++- > softmmu/qdev-monitor.c | 38 +++++++++++++++++++++++++++---------- > 3 files changed, 54 insertions(+), 12 deletions(-) > > diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h > index eaa947d73a..23c31f5296 100644 > --- a/include/monitor/qdev.h > +++ b/include/monitor/qdev.h > @@ -9,6 +9,29 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp); > > int qdev_device_help(QemuOpts *opts); > DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); > -void qdev_set_id(DeviceState *dev, const char *id); > + > +/** > + * qdev_set_id: parent the device and set its id if provided. > + * @dev: device to handle > + * @id: id to be given to the device, or NULL. > + * > + * Returns: the id of the device in case of success; otherwise NULL. > + * > + * @dev must be unrealized, unparented and must not have an id. > + * > + * If @id is non-NULL, this function tries to setup @dev qom path as > + * "/peripheral/id". If @id is already taken, it fails. If it succeeds, > + * the id field of @dev is set to @id (@dev now owns the given @id > + * parameter). > + * > + * If @id is NULL, this function generates a unique name and setups @dev > + * qom path as "/peripheral-anon/name". This name is not set as the id > + * of @dev. > + * > + * Upon success, it returns the id/name (generated or provided). The > + * returned string is owned by the corresponding child property and must > + * not be freed by the caller. > + */ > +const char *qdev_set_id(DeviceState *dev, const char *id, Error **errp); > > #endif > diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c > index dd8ae1452d..f541cfa0e9 100644 > --- a/hw/xen/xen-legacy-backend.c > +++ b/hw/xen/xen-legacy-backend.c > @@ -276,7 +276,8 @@ static struct XenLegacyDevice *xen_be_get_xendev(const char *type, int dom, > xendev = g_malloc0(ops->size); > object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND); > OBJECT(xendev)->free = g_free; > - qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev)); > + qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev), > + &error_fatal); > qdev_realize(DEVICE(xendev), xen_sysbus, &error_fatal); > object_unref(OBJECT(xendev)); > > diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c > index 25275984bd..0007698ff3 100644 > --- a/softmmu/qdev-monitor.c > +++ b/softmmu/qdev-monitor.c > @@ -578,22 +578,34 @@ static BusState *qbus_find(const char *path, Error **errp) > return bus; > } > > -void qdev_set_id(DeviceState *dev, const char *id) > +const char *qdev_set_id(DeviceState *dev, const char *id, Error **errp) > { > + ObjectProperty *prop; > + > + assert(!dev->id && !dev->realized); > + > + /* > + * object_property_[try_]add_child() below will assert the device > + * has no parent > + */ > if (id) { > - dev->id = id; > - } > - > - if (dev->id) { > - object_property_add_child(qdev_get_peripheral(), dev->id, > - OBJECT(dev)); > + prop = object_property_try_add_child(qdev_get_peripheral(), id, > + OBJECT(dev), NULL); > + if (prop) { > + dev->id = id; > + } else { > + error_setg(errp, "Duplicate device ID '%s'", id); > + return NULL; > + } > } else { > static int anon_count; > gchar *name = g_strdup_printf("device[%d]", anon_count++); > - object_property_add_child(qdev_get_peripheral_anon(), name, > - OBJECT(dev)); > + prop = object_property_add_child(qdev_get_peripheral_anon(), name, > + OBJECT(dev)); > g_free(name); > } > + > + return prop->name; > } > > DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) > @@ -677,7 +689,13 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) > } > } > > - qdev_set_id(dev, qemu_opts_id(opts)); > + /* > + * set dev's parent and register its id. > + * If it fails it means the id is already taken. > + */ > + if (!qdev_set_id(dev, qemu_opts_id(opts), errp)) { > + goto err_del_dev; > + } > > /* set properties */ > if (qemu_opt_foreach(opts, set_property, dev, errp)) { > -- > 2.33.0 > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A36F5C433F5 for ; Wed, 13 Oct 2021 07:12:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2A1BE60E78 for ; Wed, 13 Oct 2021 07:12:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2A1BE60E78 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:51352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1maYR1-0005rk-4z for qemu-devel@archiver.kernel.org; Wed, 13 Oct 2021 03:12:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maYPp-0004pv-Bo; Wed, 13 Oct 2021 03:11:05 -0400 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]:33669) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1maYPm-0004e0-Va; Wed, 13 Oct 2021 03:11:04 -0400 Received: by mail-io1-xd2c.google.com with SMTP id n7so1752383iod.0; Wed, 13 Oct 2021 00:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PuD4x/quwdKwmCZMAPno27Mt5WkSyZcD2cupRATIQmA=; b=hUpeBm07ZhmU+R92qTIFSrBL14OeFHZ6uD4IZbV6GtgXTzhgOqStOEWSiPJEWuGj4t 4zuWiSkqFTm3AGGU2NR38KTYSKWPxOtEcdS4Ai/3r1akHkT61Jp+XPc9Zl1qrzwNyPwA TnX/xusNsfu2j+x4p6dymMk+gwlKDmH0z9qb8RZ1yOpGX8JaH+u2u3i10cFfQzzpQZKA gzhXJSBzjJDyKX/O/RiXSwFRjlfOrTHayIFv4RaRpmQwTkqpQYJmnggmAwOE8fiqTWjc lItwI007UCAJqN+GP5GKmGAqMrKlXFHSwRjzOn5t6E5+kri8uC+0X+pm6KhlPDRrs3ON wktA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PuD4x/quwdKwmCZMAPno27Mt5WkSyZcD2cupRATIQmA=; b=upF2L0ojohxLrIj6Q/6kz8pOFOxt1Tebkvl25cSG8+nnaVzu5e8aPSRORhDLJe+1cV Mgk6sg+sGjoe+hg2bzDeWmrylYMQOakKowOgwsq0QmqKfLWcGNopGixDJBJxrUkd4hP8 xbgzN6nPGja6xhMpuvbQovw5cH529DU7Mmvf5aqMDhmYF4KfB26DH/8WXieJ3N5hzIfZ 34mzQI9gS6/y5wGwtSBrS89A0QukXPpwxHHC+4WWZxZabnW7lSxYm/f7isi7HdY5FCFj j3LXNBlJAjWyFIZNHhY7IGWsaDWrGgRJpQecIrAvyPLWopX5hmXp2JNt4bjzDX95ho+X iJMQ== X-Gm-Message-State: AOAM532lK/8/fRKx48u92ISj6j3NmqvkSnXTj4nXdpKY/gxtSFlALX0j /8pzhju5f2DrmRZUBBIVrIi1uFsNFV6a4D6A9WE= X-Google-Smtp-Source: ABdhPJzyNaV6p60H1ka7FNoMSrAfpLbPjQqSVej3WyYM+u5LpMnq8d8d2K/hoKgv951cKI2obB3JFtyY4qhuLjUoOBw= X-Received: by 2002:a05:6638:9a:: with SMTP id v26mr11895732jao.18.1634109061530; Wed, 13 Oct 2021 00:11:01 -0700 (PDT) MIME-Version: 1.0 References: <20210922161405.140018-1-damien.hedde@greensocs.com> <20210922161405.140018-5-damien.hedde@greensocs.com> In-Reply-To: <20210922161405.140018-5-damien.hedde@greensocs.com> From: Alistair Francis Date: Wed, 13 Oct 2021 17:10:35 +1000 Message-ID: Subject: Re: [RFC PATCH v2 04/16] softmmu/qdev-monitor: add error handling in qdev_set_id To: Damien Hedde Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::d2c; envelope-from=alistair23@gmail.com; helo=mail-io1-xd2c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , David Hildenbrand , "qemu-devel@nongnu.org Developers" , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , "Michael S. Tsirkin" , Markus Armbruster , Anthony Perard , =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= , Igor Mammedov , Eduardo Habkost , "Dr. David Alan Gilbert" , Paul Durrant , Eric Auger , "open list:X86" , "open list:RISC-V" , =?UTF-8?Q?Daniel_P=2E_Berrang=C3=A9?= , Mark Burton , Edgar Iglesias , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Thu, Sep 23, 2021 at 2:29 AM Damien Hedde wrote: > > qdev_set_id() is mostly used when the user adds a device (using > -device cli option or device_add qmp command). This commit adds > an error parameter to handle the case where the given id is > already taken. > > Also document the function and add a return value in order to > be able to capture success/failure: the function now returns the > id in case of success, or NULL in case of failure. > > The commit modifies the 2 calling places (qdev-monitor and > xen-legacy-backend) to add the error object parameter. > > Note that the id is, right now, guaranteed to be unique because > all ids came from the "device" QemuOptsList where the id is used > as key. This addition is a preparation for a future commit which > will relax the uniqueness. > > Signed-off-by: Damien Hedde Reviewed-by: Alistair Francis Alistair > --- > include/monitor/qdev.h | 25 +++++++++++++++++++++++- > hw/xen/xen-legacy-backend.c | 3 ++- > softmmu/qdev-monitor.c | 38 +++++++++++++++++++++++++++---------- > 3 files changed, 54 insertions(+), 12 deletions(-) > > diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h > index eaa947d73a..23c31f5296 100644 > --- a/include/monitor/qdev.h > +++ b/include/monitor/qdev.h > @@ -9,6 +9,29 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp); > > int qdev_device_help(QemuOpts *opts); > DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); > -void qdev_set_id(DeviceState *dev, const char *id); > + > +/** > + * qdev_set_id: parent the device and set its id if provided. > + * @dev: device to handle > + * @id: id to be given to the device, or NULL. > + * > + * Returns: the id of the device in case of success; otherwise NULL. > + * > + * @dev must be unrealized, unparented and must not have an id. > + * > + * If @id is non-NULL, this function tries to setup @dev qom path as > + * "/peripheral/id". If @id is already taken, it fails. If it succeeds, > + * the id field of @dev is set to @id (@dev now owns the given @id > + * parameter). > + * > + * If @id is NULL, this function generates a unique name and setups @dev > + * qom path as "/peripheral-anon/name". This name is not set as the id > + * of @dev. > + * > + * Upon success, it returns the id/name (generated or provided). The > + * returned string is owned by the corresponding child property and must > + * not be freed by the caller. > + */ > +const char *qdev_set_id(DeviceState *dev, const char *id, Error **errp); > > #endif > diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c > index dd8ae1452d..f541cfa0e9 100644 > --- a/hw/xen/xen-legacy-backend.c > +++ b/hw/xen/xen-legacy-backend.c > @@ -276,7 +276,8 @@ static struct XenLegacyDevice *xen_be_get_xendev(const char *type, int dom, > xendev = g_malloc0(ops->size); > object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND); > OBJECT(xendev)->free = g_free; > - qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev)); > + qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev), > + &error_fatal); > qdev_realize(DEVICE(xendev), xen_sysbus, &error_fatal); > object_unref(OBJECT(xendev)); > > diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c > index 25275984bd..0007698ff3 100644 > --- a/softmmu/qdev-monitor.c > +++ b/softmmu/qdev-monitor.c > @@ -578,22 +578,34 @@ static BusState *qbus_find(const char *path, Error **errp) > return bus; > } > > -void qdev_set_id(DeviceState *dev, const char *id) > +const char *qdev_set_id(DeviceState *dev, const char *id, Error **errp) > { > + ObjectProperty *prop; > + > + assert(!dev->id && !dev->realized); > + > + /* > + * object_property_[try_]add_child() below will assert the device > + * has no parent > + */ > if (id) { > - dev->id = id; > - } > - > - if (dev->id) { > - object_property_add_child(qdev_get_peripheral(), dev->id, > - OBJECT(dev)); > + prop = object_property_try_add_child(qdev_get_peripheral(), id, > + OBJECT(dev), NULL); > + if (prop) { > + dev->id = id; > + } else { > + error_setg(errp, "Duplicate device ID '%s'", id); > + return NULL; > + } > } else { > static int anon_count; > gchar *name = g_strdup_printf("device[%d]", anon_count++); > - object_property_add_child(qdev_get_peripheral_anon(), name, > - OBJECT(dev)); > + prop = object_property_add_child(qdev_get_peripheral_anon(), name, > + OBJECT(dev)); > g_free(name); > } > + > + return prop->name; > } > > DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) > @@ -677,7 +689,13 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) > } > } > > - qdev_set_id(dev, qemu_opts_id(opts)); > + /* > + * set dev's parent and register its id. > + * If it fails it means the id is already taken. > + */ > + if (!qdev_set_id(dev, qemu_opts_id(opts), errp)) { > + goto err_del_dev; > + } > > /* set properties */ > if (qemu_opt_foreach(opts, set_property, dev, errp)) { > -- > 2.33.0 > >