From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sd1Do-0004s8-1u for qemu-devel@nongnu.org; Fri, 08 Jun 2012 11:35:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sd1Dk-0005Re-N3 for qemu-devel@nongnu.org; Fri, 08 Jun 2012 11:35:31 -0400 Received: from cantor2.suse.de ([195.135.220.15]:55344 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sd1Dk-0005RF-DT for qemu-devel@nongnu.org; Fri, 08 Jun 2012 11:35:28 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Fri, 8 Jun 2012 17:35:10 +0200 Message-Id: <1339169713-31205-6-git-send-email-afaerber@suse.de> In-Reply-To: <1339169713-31205-1-git-send-email-afaerber@suse.de> References: <1339169713-31205-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 5/8] qdev: Use int32_t container for devfn property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , "Michael S. Tsirkin" , Michael Roth , Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= From: Michael Roth 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 addition= al bounds-checking based on target container type, which is int32_t for this case. Signed-off-by: Michael Roth Signed-off-by: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- 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 c1ebdde..127b7ac 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1537,7 +1537,7 @@ PCIDevice *pci_create_multifunction(PCIBus *bus, in= t devfn, bool multifunction, DeviceState *dev; =20 dev =3D 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 c3cacce..7f223c0 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -197,7 +197,7 @@ struct PCIDevice { =20 /* the following fields are read only */ PCIBus *bus; - uint32_t devfn; + int32_t devfn; char name[64]; PCIIORegion io_regions[PCI_NUM_REGIONS]; =20 diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index b7b5597..d109f89 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -824,7 +824,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, vo= id *opaque, { DeviceState *dev =3D DEVICE(obj); Property *prop =3D opaque; - uint32_t *ptr =3D qdev_get_prop_ptr(dev, prop); + int32_t *ptr =3D qdev_get_prop_ptr(dev, prop); unsigned int slot, fn, n; Error *local_err =3D NULL; char *str; @@ -860,7 +860,7 @@ invalid: =20 static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest,= size_t len) { - uint32_t *ptr =3D qdev_get_prop_ptr(dev, prop); + int32_t *ptr =3D qdev_get_prop_ptr(dev, prop); =20 if (*ptr =3D=3D -1) { return snprintf(dest, len, ""); @@ -875,11 +875,8 @@ PropertyInfo qdev_prop_pci_devfn =3D { .print =3D print_pci_devfn, .get =3D get_int32, .set =3D set_pci_devfn, - /* FIXME: this should be -1...255, but the address is stored - * into an uint32_t rather than int32_t. - */ - .min =3D 0, - .max =3D 0xFFFFFFFFULL, + .min =3D -1, + .max =3D 255, }; =20 /* --- blocksize --- */ diff --git a/hw/qdev.h b/hw/qdev.h index 4e90119..d07da45 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -267,7 +267,7 @@ extern PropertyInfo qdev_prop_blocksize; #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) =20 #define DEFINE_PROP_PTR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) --=20 1.7.7