From nobody Thu Dec 18 17:55:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516110535696835.5043030103301; Tue, 16 Jan 2018 05:48:55 -0800 (PST) Received: from localhost ([::1]:36807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebRbU-0002tQ-Rg for importer@patchew.org; Tue, 16 Jan 2018 08:48:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebRNy-0008Fk-UE for qemu-devel@nongnu.org; Tue, 16 Jan 2018 08:34:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebRNv-0002rK-4d for qemu-devel@nongnu.org; Tue, 16 Jan 2018 08:34:42 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:45894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebRNu-0002qb-TD for qemu-devel@nongnu.org; Tue, 16 Jan 2018 08:34:39 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1ebRNt-0002vu-Qu for qemu-devel@nongnu.org; Tue, 16 Jan 2018 13:34:37 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 13:34:11 +0000 Message-Id: <1516109659-1557-17-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516109659-1557-1-git-send-email-peter.maydell@linaro.org> References: <1516109659-1557-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 16/24] sdhci: refactor common sysbus/pci unrealize() into sdhci_common_unrealize() 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Message-id: 20180115182436.2066-7-f4bug@amsat.org Signed-off-by: Peter Maydell --- hw/sd/sdhci.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index cf0c079..bbe4570 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -32,6 +32,7 @@ #include "qemu/bitops.h" #include "hw/sd/sdhci.h" #include "sdhci-internal.h" +#include "qapi/error.h" #include "qemu/log.h" =20 /* host controller debug messages */ @@ -1223,6 +1224,17 @@ static void sdhci_common_realize(SDHCIState *s, Erro= r **errp) SDHC_REGISTERS_MAP_SIZE); } =20 +static void sdhci_common_unrealize(SDHCIState *s, Error **errp) +{ + /* This function is expected to be called only once for each class: + * - SysBus: via DeviceClass->unrealize(), + * - PCI: via PCIDeviceClass->exit(). + * However to avoid double-free and/or use-after-free we still nullify + * this variable (better safe than sorry!). */ + g_free(s->fifo_buffer); + s->fifo_buffer =3D NULL; +} + static bool sdhci_pending_insert_vmstate_needed(void *opaque) { SDHCIState *s =3D opaque; @@ -1317,6 +1329,8 @@ static void sdhci_pci_realize(PCIDevice *dev, Error *= *errp) static void sdhci_pci_exit(PCIDevice *dev) { SDHCIState *s =3D PCI_SDHCI(dev); + + sdhci_common_unrealize(s, &error_abort); sdhci_uninitfn(s); } =20 @@ -1382,12 +1396,20 @@ static void sdhci_sysbus_realize(DeviceState *dev, = Error ** errp) sysbus_init_mmio(sbd, &s->iomem); } =20 +static void sdhci_sysbus_unrealize(DeviceState *dev, Error **errp) +{ + SDHCIState *s =3D SYSBUS_SDHCI(dev); + + sdhci_common_unrealize(s, &error_abort); +} + static void sdhci_sysbus_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 dc->props =3D sdhci_sysbus_properties; dc->realize =3D sdhci_sysbus_realize; + dc->unrealize =3D sdhci_sysbus_unrealize; =20 sdhci_common_class_init(klass, data); } --=20 2.7.4