diff mbox

[1/3] pci: sorting out type confusion in pci_register_bar().

Message ID 506dcb9fac70af774159f20559c707d5c0cafd17.1284000417.git.yamahata@valinux.co.jp
State New
Headers show

Commit Message

Isaku Yamahata Sept. 9, 2010, 2:48 a.m. UTC
This patch sorts out invalid use of pcibus_t.

In pci_register_bar(), pcibus_t wmask is used.
It should, However, be uint64_t because it is used to set
pci configuration space value(PCIDevice::wmask) by pci_set_quad()
or pci_set_long().
So make its type uint64_t and cast from pcibus_t to int64_t where
necessary.

Maybe for strict type safety conversion functions would
be desirable. Something like pcibus_to_uintN(), uintN_to_pcibus().
But conversions are done only a few place, so it wouldn't be
worthwhile.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/pci.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Comments

Michael S. Tsirkin Sept. 12, 2010, 3:18 p.m. UTC | #1
On Thu, Sep 09, 2010 at 11:48:55AM +0900, Isaku Yamahata wrote:
> This patch sorts out invalid use of pcibus_t.
> 
> In pci_register_bar(), pcibus_t wmask is used.
> It should, However, be uint64_t because it is used to set
> pci configuration space value(PCIDevice::wmask) by pci_set_quad()
> or pci_set_long().
> So make its type uint64_t and cast from pcibus_t to int64_t where
> necessary.


I don't think we need the cast. Applied without the cast.

> Maybe for strict type safety conversion functions would
> be desirable. Something like pcibus_to_uintN(), uintN_to_pcibus().
> But conversions are done only a few place, so it wouldn't be
> worthwhile.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> ---
>  hw/pci.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index f03b83e..8d6b299 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -763,7 +763,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
>  {
>      PCIIORegion *r;
>      uint32_t addr;
> -    pcibus_t wmask;
> +    uint64_t wmask;
>  
>      if ((unsigned int)region_num >= PCI_NUM_REGIONS)
>          return;
> @@ -781,7 +781,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
>      r->type = type;
>      r->map_func = map_func;
>  
> -    wmask = ~(size - 1);
> +    wmask = (uint64_t)(~(size - 1));
>      addr = pci_bar(pci_dev, region_num);
>      if (region_num == PCI_ROM_SLOT) {
>          /* ROM enable bit is writeable */
> -- 
> 1.7.1.1
diff mbox

Patch

diff --git a/hw/pci.c b/hw/pci.c
index f03b83e..8d6b299 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -763,7 +763,7 @@  void pci_register_bar(PCIDevice *pci_dev, int region_num,
 {
     PCIIORegion *r;
     uint32_t addr;
-    pcibus_t wmask;
+    uint64_t wmask;
 
     if ((unsigned int)region_num >= PCI_NUM_REGIONS)
         return;
@@ -781,7 +781,7 @@  void pci_register_bar(PCIDevice *pci_dev, int region_num,
     r->type = type;
     r->map_func = map_func;
 
-    wmask = ~(size - 1);
+    wmask = (uint64_t)(~(size - 1));
     addr = pci_bar(pci_dev, region_num);
     if (region_num == PCI_ROM_SLOT) {
         /* ROM enable bit is writeable */