From patchwork Wed Oct 26 16:30:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 687264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3t3xXv16FBz9t0Z for ; Thu, 27 Oct 2016 04:17:35 +1100 (AEDT) Received: from localhost ([::1]:36233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzRpU-00041w-Jj for incoming@patchwork.ozlabs.org; Wed, 26 Oct 2016 13:17:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzR6N-0006Z5-Fb for qemu-devel@nongnu.org; Wed, 26 Oct 2016 12:30:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzR6K-0003QK-N6 for qemu-devel@nongnu.org; Wed, 26 Oct 2016 12:30:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53774) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bzR6K-0003Pw-GE for qemu-devel@nongnu.org; Wed, 26 Oct 2016 12:30:52 -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 BEB4622028; Wed, 26 Oct 2016 16:30:51 +0000 (UTC) Received: from localhost (ovpn-116-163.phx2.redhat.com [10.3.116.163]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9QGUor6007107; Wed, 26 Oct 2016 12:30:51 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 26 Oct 2016 14:30:22 -0200 Message-Id: <1477499426-9550-5-git-send-email-ehabkost@redhat.com> In-Reply-To: <1477499426-9550-1-git-send-email-ehabkost@redhat.com> References: <1477499426-9550-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.25]); Wed, 26 Oct 2016 16:30:51 +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 v3 4/8] 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: Igor Mammedov , Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Reviewed-by: Igor Mammedov 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 36ca5e7..85952e8 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