From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGw8k-0003AW-8P for qemu-devel@nongnu.org; Wed, 26 Sep 2012 14:15:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGw8j-0005tI-Aa for qemu-devel@nongnu.org; Wed, 26 Sep 2012 14:15:18 -0400 Received: from sabe.cs.wisc.edu ([128.105.6.20]:41379) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGw8j-0005rK-09 for qemu-devel@nongnu.org; Wed, 26 Sep 2012 14:15:17 -0400 From: "Matt Renzelmann" References: <1348673453-3248-1-git-send-email-mjr@cs.wisc.edu> <1348676771.28860.199.camel@bling.home> <004401cd9c07$0b36d760$21a48620$@cs.wisc.edu> <1348678672.28860.204.camel@bling.home> <005901cd9c0f$4d3f9ef0$e7bedcd0$@cs.wisc.edu> <1348682122.28860.210.camel@bling.home> In-Reply-To: <1348682122.28860.210.camel@bling.home> Date: Wed, 26 Sep 2012 13:05:11 -0500 Message-ID: <005e01cd9c11$7b967f10$72c37d30$@cs.wisc.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-Language: en-us Subject: Re: [Qemu-devel] [PATCH v3] Align PCI capabilities in pci_find_space List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: 'Alex Williamson' Cc: qemu-devel@nongnu.org > > Mismatched uses of "size" here. We need both the end of the range to > search and the size of the sub-range we're looking for. Maybe start, > end, and size. Thanks, > Ah of course, how's this: static int pci_find_space(PCIDevice *pdev, uint32_t start, uint32_t end, uint32_t size) { int offset = start; int i; uint32_t *dword_used = &pdev->used[start]; /* This approach ensures the capability is dword-aligned, as required by the PCI and PCI-E specifications */ for (i = start; i < end; i += 4, dword_used++) { if (*dword_used) offset = i + 4; else if (i - offset + 4 >= size) return offset; } return 0; } static int pci_find_legacy_space(PCIDevice *pdev, uint8_t size) { return pci_find_space(pdev, PCI_CONFIG_HEADER_SIZE, PCI_CONFIG_SPACE_SIZE, size); } static int pci_find_express_space(PCIDevice *pdev, uint16_t size) { assert (pci_config_size(pdev) >= PCIE_CONFIG_SPACE_SIZE); return pci_find_space(pdev, PCI_CONFIG_SPACE_SIZE, PCIE_CONFIG_SPACE_SIZE, size); }