[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 14/24] qdev: use int32_t container for devfn prop
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH v2 14/24] qdev: use int32_t container for devfn property |
Date: |
Wed, 11 Apr 2012 23:30:32 +0200 |
From: Michael Roth <address@hidden>
Valid range for devfn is -1 to 255 (-1 for automatic assignment). We do
not currently validate this due to devfn being stored as a uint32_t.
This can lead to segfaults and other strange behavior.
We could technically just cast it to int32_t to implement the checking,
but this will not work for visitor-based setting where we may do additional
bounds-checking based on target container type, which is int32_t for this
case.
Signed-off-by: Michael Roth <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/pci.c | 2 +-
hw/pci.h | 2 +-
hw/qdev-properties.c | 11 ++++-------
hw/qdev.h | 2 +-
4 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index 4e8e726..6910fac 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1539,7 +1539,7 @@ PCIDevice *pci_create_multifunction(PCIBus *bus, int
devfn, bool multifunction,
DeviceState *dev;
dev = qdev_create(&bus->qbus, name);
- qdev_prop_set_uint32(dev, "addr", devfn);
+ qdev_prop_set_int32(dev, "addr", devfn);
qdev_prop_set_bit(dev, "multifunction", multifunction);
return PCI_DEVICE(dev);
}
diff --git a/hw/pci.h b/hw/pci.h
index 4f19fdb..3edf38a 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -188,7 +188,7 @@ struct PCIDevice {
/* the following fields are read only */
PCIBus *bus;
- uint32_t devfn;
+ int32_t devfn;
char name[64];
PCIIORegion io_regions[PCI_NUM_REGIONS];
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 60fef9a..af7c00a 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -822,7 +822,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void
*opaque,
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
+ int32_t *ptr = qdev_get_prop_ptr(dev, prop);
unsigned int slot, fn, n;
Error *local_err = NULL;
char *str = (char *)"";
@@ -855,7 +855,7 @@ invalid:
static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest,
size_t len)
{
- uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
+ int32_t *ptr = qdev_get_prop_ptr(dev, prop);
if (*ptr == -1) {
return snprintf(dest, len, "<unset>");
@@ -870,11 +870,8 @@ PropertyInfo qdev_prop_pci_devfn = {
.print = print_pci_devfn,
.get = get_int32,
.set = set_pci_devfn,
- /* FIXME: this should be -1...255, but the address is stored
- * into an uint32_t rather than int32_t.
- */
- .min = 0,
- .max = 0xFFFFFFFFULL,
+ .min = -1,
+ .max = 255,
};
/* --- public helpers --- */
diff --git a/hw/qdev.h b/hw/qdev.h
index aea53c8..fc18387 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -264,7 +264,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
#define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
- DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t)
+ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
#define DEFINE_PROP_PTR(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
--
1.7.9.3
- Re: [Qemu-devel] [PATCH v2 05/24] qdev: push "type" property up to Object, (continued)
- [Qemu-devel] [PATCH v2 06/24] qdev: fix -device foo,?, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 08/24] qdev: move bus properties to a separate global, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 07/24] qdev: use object_property_print in info qtree, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 09/24] qdev: do not propagate properties to subclasses, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 11/24] qdev: clean up global properties, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 10/24] qdev: move bus properties to abstract superclasses, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 12/24] qdev: remove qdev_prop_set_defaults, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 13/24] qapi: add Visitor interfaces for uint*_t and int*_t, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 14/24] qdev: use int32_t container for devfn property,
Paolo Bonzini <=
- [Qemu-devel] [PATCH v2 15/24] qdev: switch property accessors to fixed-width visitor interfaces, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 17/24] qdev: remove qdev_prop_exists, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 16/24] qdev: remove PropertyInfo range checking, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 18/24] qdev: push state up to Object, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 23/24] qdev: implement qdev_init on top of realize, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 24/24] qdev: split part of device_finalize to device_unrealize, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 21/24] qom: push static properties to Object, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 20/24] qdev: move bulk of qdev-properties.c to qom/object.c, Paolo Bonzini, 2012/04/11
- [Qemu-devel] [PATCH v2 22/24] qom: add realized property, Paolo Bonzini, 2012/04/11