From patchwork Wed Jan 7 10:49:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 1135 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n07Ak8QE030323 for ; Wed, 7 Jan 2009 02:46:08 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751002AbZAGKth (ORCPT ); Wed, 7 Jan 2009 05:49:37 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751859AbZAGKth (ORCPT ); Wed, 7 Jan 2009 05:49:37 -0500 Received: from mga09.intel.com ([134.134.136.24]:26981 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751002AbZAGKtg (ORCPT ); Wed, 7 Jan 2009 05:49:36 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 07 Jan 2009 02:41:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.37,225,1231142400"; d="scan'208";a="479598833" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.13.47]) by orsmga001.jf.intel.com with ESMTP; 07 Jan 2009 02:48:04 -0800 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1LKVyd-0005xg-Je; Wed, 07 Jan 2009 18:49:31 +0800 From: Sheng Yang To: Avi Kivity Cc: Anthony Liguori , kvm@vger.kernel.org, Sheng Yang Subject: [PATCH 1/6] kvm: Replace force type convert with container_of() Date: Wed, 7 Jan 2009 18:49:26 +0800 Message-Id: <1231325371-22896-2-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.5.6.3 In-Reply-To: <1231325371-22896-1-git-send-email-sheng@linux.intel.com> References: <1231325371-22896-1-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Sheng Yang --- qemu/hw/device-assignment.c | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c index d5eb7b2..f357d17 100644 --- a/qemu/hw/device-assignment.c +++ b/qemu/hw/device-assignment.c @@ -144,7 +144,7 @@ static uint32_t assigned_dev_ioport_readl(void *opaque, uint32_t addr) static void assigned_dev_iomem_map(PCIDevice *pci_dev, int region_num, uint32_t e_phys, uint32_t e_size, int type) { - AssignedDevice *r_dev = (AssignedDevice *) pci_dev; + AssignedDevice *r_dev = container_of(pci_dev, AssignedDevice, dev); AssignedDevRegion *region = &r_dev->v_addrs[region_num]; uint32_t old_ephys = region->e_physbase; uint32_t old_esize = region->e_size; @@ -178,7 +178,7 @@ static void assigned_dev_iomem_map(PCIDevice *pci_dev, int region_num, static void assigned_dev_ioport_map(PCIDevice *pci_dev, int region_num, uint32_t addr, uint32_t size, int type) { - AssignedDevice *r_dev = (AssignedDevice *) pci_dev; + AssignedDevice *r_dev = container_of(pci_dev, AssignedDevice, dev); AssignedDevRegion *region = &r_dev->v_addrs[region_num]; int first_map = (region->e_size == 0); CPUState *env; @@ -227,6 +227,7 @@ static void assigned_dev_pci_write_config(PCIDevice *d, uint32_t address, { int fd; ssize_t ret; + AssignedDevice *pci_dev = container_of(d, AssignedDevice, dev); DEBUG("(%x.%x): address=%04x val=0x%08x len=%d\n", ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7), @@ -248,7 +249,7 @@ static void assigned_dev_pci_write_config(PCIDevice *d, uint32_t address, ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7), (uint16_t) address, val, len); - fd = ((AssignedDevice *)d)->real_device.config_fd; + fd = pci_dev->real_device.config_fd; again: ret = pwrite(fd, &val, len, address); @@ -269,6 +270,7 @@ static uint32_t assigned_dev_pci_read_config(PCIDevice *d, uint32_t address, uint32_t val = 0; int fd; ssize_t ret; + AssignedDevice *pci_dev = container_of(d, AssignedDevice, dev); if ((address >= 0x10 && address <= 0x24) || address == 0x34 || address == 0x3c || address == 0x3d) { @@ -282,7 +284,7 @@ static uint32_t assigned_dev_pci_read_config(PCIDevice *d, uint32_t address, if (address == 0xFC) goto do_log; - fd = ((AssignedDevice *)d)->real_device.config_fd; + fd = pci_dev->real_device.config_fd; again: ret = pread(fd, &val, len, address); @@ -539,16 +541,18 @@ struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus) { int r; AssignedDevice *dev; + PCIDevice *pci_dev; uint8_t e_device, e_intx; struct kvm_assigned_pci_dev assigned_dev_data; DEBUG("Registering real physical device %s (bus=%x dev=%x func=%x)\n", adev->name, adev->bus, adev->dev, adev->func); - dev = (AssignedDevice *) - pci_register_device(bus, adev->name, sizeof(AssignedDevice), - -1, assigned_dev_pci_read_config, - assigned_dev_pci_write_config); + pci_dev = pci_register_device(bus, adev->name, + sizeof(AssignedDevice), -1, assigned_dev_pci_read_config, + assigned_dev_pci_write_config); + dev = container_of(pci_dev, AssignedDevice, dev); + if (NULL == dev) { fprintf(stderr, "%s: Error: Couldn't register real device %s\n", __func__, adev->name);