From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wi3zP-0003FY-6S for qemu-devel@nongnu.org; Wed, 07 May 2014 11:42:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wi3zK-0004qh-4M for qemu-devel@nongnu.org; Wed, 07 May 2014 11:42:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wi3zJ-0004qS-RW for qemu-devel@nongnu.org; Wed, 07 May 2014 11:42:30 -0400 Date: Wed, 7 May 2014 18:37:55 +0300 From: "Michael S. Tsirkin" Message-ID: <1399477052-18612-2-git-send-email-mst@redhat.com> References: <1399477052-18612-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1399477052-18612-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 01/10] acpi/pcihp.c: Rewrite acpi_pcihp_get_bsel using object_property_get_int List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Anthony Liguori , Kirill Batuzov From: Kirill Batuzov 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 Signed-off-by: Michael S. Tsirkin --- hw/acpi/pcihp.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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) -- MST