From patchwork Thu Apr 24 14:15:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Batuzov X-Patchwork-Id: 342584 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 423C614015B for ; Fri, 25 Apr 2014 11:38:26 +1000 (EST) Received: from localhost ([::1]:53094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdV5r-0003K3-SX for incoming@patchwork.ozlabs.org; Thu, 24 Apr 2014 21:38:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdUk5-0006TW-Bo for qemu-devel@nongnu.org; Thu, 24 Apr 2014 21:16:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WdKRm-0007yU-2B for qemu-devel@nongnu.org; Thu, 24 Apr 2014 10:16:25 -0400 Received: from smtp.ispras.ru ([83.149.199.79]:35104) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdKRl-0007jp-PU for qemu-devel@nongnu.org; Thu, 24 Apr 2014 10:16:17 -0400 Received: from bulbul.intra.ispras.ru (unknown [83.149.199.91]) by smtp.ispras.ru (Postfix) with ESMTP id 84F72224AA; Thu, 24 Apr 2014 18:16:05 +0400 (MSK) From: Kirill Batuzov To: qemu-devel@nongnu.org Date: Thu, 24 Apr 2014 18:15:56 +0400 Message-Id: <1398348959-23048-2-git-send-email-batuzovk@ispras.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398348959-23048-1-git-send-email-batuzovk@ispras.ru> References: <1398348959-23048-1-git-send-email-batuzovk@ispras.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 83.149.199.79 Cc: Igor Mammedov , "Michael S . Tsirkin" , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Kirill Batuzov Subject: [Qemu-devel] [PATCH v2 1/4] acpi/pcihp.c: Rewrite acpi_pcihp_get_bsel using object_property_get_int X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org acpi_pcihp_get_bsel implements functionality of object_property_get_int for specific property named ACPI_PCIHP_PROP_BSEL, but fails to decrement object's reference counter properly. Rewriting it using generic object_property_get_int serves two purposes: reducing code duplication and fixing memory leak. Signed-off-by: Kirill Batuzov Reviewed-by: Michael S. Tsirkin --- hw/acpi/pcihp.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) v1 -> v2: Keep acpi_pcihp_get_bsel, but rewrite it using object_property_get_int and validate returned value. diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index f80c480..3b143b3 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -63,16 +63,18 @@ typedef struct AcpiPciHpFind { static int acpi_pcihp_get_bsel(PCIBus *bus) { - QObject *o = object_property_get_qobject(OBJECT(bus), - ACPI_PCIHP_PROP_BSEL, NULL); - int64_t bsel = -1; - if (o) { - bsel = qint_get_int(qobject_to_qint(o)); - } - if (bsel < 0) { + Error *local_err = NULL; + int64_t bsel = object_property_get_int(OBJECT(bus), ACPI_PCIHP_PROP_BSEL, + &local_err); + + if (local_err || bsel < 0 || bsel >= ACPI_PCIHP_MAX_HOTPLUG_BUS) { + if (local_err) { + error_free(local_err); + } return -1; + } else { + return bsel; } - return bsel; } static void acpi_pcihp_test_hotplug_bus(PCIBus *bus, void *opaque)