From patchwork Tue Sep 8 16:51:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 53279 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 456CE22B05 for ; Tue, 8 Sep 2015 16:57:01 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf38860163wic.3 for ; Tue, 08 Sep 2015 09:57:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=In8gQHIxa+clhNYPx3mDSPzF0bFQB4tbILPO/J/MMwc=; b=BBFU3QlJ1BiwoVsyN5K5qjF54FlLNqZvPrhNVIKkBx3uh5RSUV2iF+B+6HTa0zrgJM zZ0qwpXc0a7GYDj1dIdbMFNeACa/re6579usVVr5LEn6jG3Km+m6Lbo4Nal8/8b7r+79 nGtJGndyl/JFKwCGhpEnCZO48+CexxfpkpRsDEsnS9yJfoTs5oFpKx1Zdfh4KmoJiTL5 zeiaV7aozmXzjmTNCAo5Hkb8Xr+n7qTtzmBQNP0BTdsEXAt+O3mQ6ddz2TvxF8JyCBig hQoEJQEZlbMUsILFm/JzGT/oZfLmmbinpD8G+ltACDXKWOyVH+OOw1DBgzBH3wnW+NFG 3jjg== X-Gm-Message-State: ALoCoQloFkJDdTp61tAWUCM2it9BYnTWs3KNeFQyK6dVNvcUTxl1cZ16gARF4FXRh8tWgbFrr/0d X-Received: by 10.180.106.197 with SMTP id gw5mr3477474wib.7.1441731420619; Tue, 08 Sep 2015 09:57:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.193 with SMTP id 1ls322934law.30.gmail; Tue, 08 Sep 2015 09:57:00 -0700 (PDT) X-Received: by 10.112.36.196 with SMTP id s4mr24051589lbj.59.1441731420298; Tue, 08 Sep 2015 09:57:00 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id r10si3766358lar.147.2015.09.08.09.57.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Sep 2015 09:57:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lanb10 with SMTP id b10so72933585lan.3 for ; Tue, 08 Sep 2015 09:57:00 -0700 (PDT) X-Received: by 10.152.21.196 with SMTP id x4mr23624564lae.117.1441731420168; Tue, 08 Sep 2015 09:57:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1096814lbq; Tue, 8 Sep 2015 09:56:59 -0700 (PDT) X-Received: by 10.140.19.43 with SMTP id 40mr36296348qgg.67.1441731419042; Tue, 08 Sep 2015 09:56:59 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g123si4524201qhc.125.2015.09.08.09.56.58 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Sep 2015 09:56:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:35819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZMCX-00012l-Si for patch@linaro.org; Tue, 08 Sep 2015 12:56:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZM7T-0002T4-MV for qemu-devel@nongnu.org; Tue, 08 Sep 2015 12:51:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZM7S-0007o1-Ls for qemu-devel@nongnu.org; Tue, 08 Sep 2015 12:51:43 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:35049) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZM7S-0007b2-FJ for qemu-devel@nongnu.org; Tue, 08 Sep 2015 12:51:42 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZZM7I-0001ig-TP for qemu-devel@nongnu.org; Tue, 08 Sep 2015 17:51:32 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 8 Sep 2015 17:51:30 +0100 Message-Id: <1441731092-6513-19-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1441731092-6513-1-git-send-email-peter.maydell@linaro.org> References: <1441731092-6513-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 18/20] ahci.c: Don't assume AHCIState's parent is AHCIPCIState 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Alistair Francis The AHCIState struct can either have AHCIPCIState or SysbusAHCIState as a parent. The ahci_irq_lower() and ahci_irq_raise() functions assume that it is always AHCIPCIState, which is not always the case, which causes a seg fault. Verify what the container of AHCIState is before setting the PCIDevice struct. Signed-off-by: Alistair Francis Acked-by: John Snow Reviewed-by: Peter Crosthwaite Signed-off-by: Peter Maydell --- hw/ide/ahci.c | 13 +++++++------ hw/ide/ahci.h | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 02d85fa..d83efa4 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -121,9 +121,9 @@ static uint32_t ahci_port_read(AHCIState *s, int port, int offset) static void ahci_irq_raise(AHCIState *s, AHCIDevice *dev) { - AHCIPCIState *d = container_of(s, AHCIPCIState, ahci); - PCIDevice *pci_dev = - (PCIDevice *)object_dynamic_cast(OBJECT(d), TYPE_PCI_DEVICE); + DeviceState *dev_state = s->container; + PCIDevice *pci_dev = (PCIDevice *) object_dynamic_cast(OBJECT(dev_state), + TYPE_PCI_DEVICE); DPRINTF(0, "raise irq\n"); @@ -136,9 +136,9 @@ static void ahci_irq_raise(AHCIState *s, AHCIDevice *dev) static void ahci_irq_lower(AHCIState *s, AHCIDevice *dev) { - AHCIPCIState *d = container_of(s, AHCIPCIState, ahci); - PCIDevice *pci_dev = - (PCIDevice *)object_dynamic_cast(OBJECT(d), TYPE_PCI_DEVICE); + DeviceState *dev_state = s->container; + PCIDevice *pci_dev = (PCIDevice *) object_dynamic_cast(OBJECT(dev_state), + TYPE_PCI_DEVICE); DPRINTF(0, "lower irq\n"); @@ -1436,6 +1436,7 @@ void ahci_init(AHCIState *s, DeviceState *qdev, AddressSpace *as, int ports) s->as = as; s->ports = ports; s->dev = g_new0(AHCIDevice, ports); + s->container = qdev; ahci_reg_init(s); /* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */ memory_region_init_io(&s->mem, OBJECT(qdev), &ahci_mem_ops, s, diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h index c055d6b..c9b3805 100644 --- a/hw/ide/ahci.h +++ b/hw/ide/ahci.h @@ -287,6 +287,8 @@ struct AHCIDevice { }; typedef struct AHCIState { + DeviceState *container; + AHCIDevice *dev; AHCIControlRegs control_regs; MemoryRegion mem;