From patchwork Tue Oct 11 20:41:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 9371703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3FEC060487 for ; Tue, 11 Oct 2016 20:42:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32C40290E8 for ; Tue, 11 Oct 2016 20:42:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2652A290F1; Tue, 11 Oct 2016 20:42:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C68EC290E8 for ; Tue, 11 Oct 2016 20:42:04 +0000 (UTC) Received: from localhost ([::1]:57926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bu3sB-0000cC-W9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 11 Oct 2016 16:42:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bu3rh-0000bE-L1 for qemu-devel@nongnu.org; Tue, 11 Oct 2016 16:41:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bu3rf-0000RP-Gl for qemu-devel@nongnu.org; Tue, 11 Oct 2016 16:41:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bu3rf-0000RF-AD for qemu-devel@nongnu.org; Tue, 11 Oct 2016 16:41:31 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C8592C05681A; Tue, 11 Oct 2016 20:41:30 +0000 (UTC) Received: from localhost (ovpn-116-77.phx2.redhat.com [10.3.116.77]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9BKfTTK019725; Tue, 11 Oct 2016 16:41:30 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Tue, 11 Oct 2016 17:41:15 -0300 Message-Id: <1476218479-3592-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1476218479-3592-1-git-send-email-ehabkost@redhat.com> References: <1476218479-3592-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 11 Oct 2016 20:41:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/6] qdev: Extract property-default code to qdev_property_set_to_default() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The code that registers qdev properties will be split from the code that initializes default values on instance_init, so move it to a separate function. Signed-off-by: Eduardo Habkost --- hw/core/qdev.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index a914630..178cfa1 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -775,6 +775,34 @@ static void qdev_property_add_legacy(DeviceState *dev, Property *prop, } /** + * qdev_property_set_to_default: + * @dev: Device where the property will be reset + * @prop: The qdev property definition + * @errp: location to store error information + * + * Reset the value of property @prop in @dev to its default value. + * On error, store error in @errp. + */ +static void qdev_property_set_to_default(DeviceState *dev, Property *prop, + Error **errp) +{ + Object *obj = OBJECT(dev); + + if (prop->qtype == QTYPE_NONE) { + return; + } + + if (prop->qtype == QTYPE_QBOOL) { + object_property_set_bool(obj, prop->defval, prop->name, errp); + } else if (prop->info->enum_table) { + object_property_set_str(obj, prop->info->enum_table[prop->defval], + prop->name, errp); + } else if (prop->qtype == QTYPE_QINT) { + object_property_set_int(obj, prop->defval, prop->name, errp); + } +} + +/** * qdev_property_add_static: * @dev: Device to add the property to. * @prop: The qdev property definition. @@ -813,18 +841,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, prop->info->description, &error_abort); - if (prop->qtype == QTYPE_NONE) { - return; - } - - if (prop->qtype == QTYPE_QBOOL) { - object_property_set_bool(obj, prop->defval, prop->name, &error_abort); - } else if (prop->info->enum_table) { - object_property_set_str(obj, prop->info->enum_table[prop->defval], - prop->name, &error_abort); - } else if (prop->qtype == QTYPE_QINT) { - object_property_set_int(obj, prop->defval, prop->name, &error_abort); - } + qdev_property_set_to_default(dev, prop, &error_abort); } /* @qdev_alias_all_properties - Add alias properties to the source object for