Patchwork [2/3] pci: don't ignore invalid parameter for pci_register_bar().

login
register
mail settings
Submitter Isaku Yamahata
Date Sept. 9, 2010, 2:48 a.m.
Message ID <923c10aea223d40b50f1a641becf08b7a647f541.1284000417.git.yamahata@valinux.co.jp>
Download mbox | patch
Permalink /patch/64252/
State New
Headers show

Comments

Isaku Yamahata - Sept. 9, 2010, 2:48 a.m.
Abort when invalid value for region_num is passed to pci_register_bar.
That is caller's bug. Abort instead of silently ignoring invalid value.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/pci.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
Michael S. Tsirkin - Sept. 12, 2010, 3:21 p.m.
On Thu, Sep 09, 2010 at 11:48:56AM +0900, Isaku Yamahata wrote:
> Abort when invalid value for region_num is passed to pci_register_bar.
> That is caller's bug. Abort instead of silently ignoring invalid value.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> ---
>  hw/pci.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)

Applied.

> diff --git a/hw/pci.c b/hw/pci.c
> index 8d6b299..31eba9a 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -765,9 +765,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
>      uint32_t addr;
>      uint64_t wmask;
>  
> -    if ((unsigned int)region_num >= PCI_NUM_REGIONS)
> -        return;
> -
> +    assert(region_num >= 0);
> +    assert(region_num < PCI_NUM_REGIONS);
>      if (size & (size-1)) {
>          fprintf(stderr, "ERROR: PCI region size must be pow2 "
>                      "type=0x%x, size=0x%"FMT_PCIBUS"\n", type, size);
> -- 
> 1.7.1.1

Patch

diff --git a/hw/pci.c b/hw/pci.c
index 8d6b299..31eba9a 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -765,9 +765,8 @@  void pci_register_bar(PCIDevice *pci_dev, int region_num,
     uint32_t addr;
     uint64_t wmask;
 
-    if ((unsigned int)region_num >= PCI_NUM_REGIONS)
-        return;
-
+    assert(region_num >= 0);
+    assert(region_num < PCI_NUM_REGIONS);
     if (size & (size-1)) {
         fprintf(stderr, "ERROR: PCI region size must be pow2 "
                     "type=0x%x, size=0x%"FMT_PCIBUS"\n", type, size);