* [Qemu-devel] [PATCH] qemu/pci: clarify pci config load routine
@ 2009-10-05 20:46 Michael S. Tsirkin
2009-10-05 22:47 ` [Qemu-devel] " Juan Quintela
0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2009-10-05 20:46 UTC (permalink / raw)
To: qemu-devel, quintela
PCI load routine has to be called with size equal to 256 (otherwise it
will crash in weird ways). So assert this, making code clearer.
Also avoid dynamically sized array on stack - good for portability.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Cc: Juan Quintela <quintela@redhat.com>
---
hw/pci.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index ade778f..196297a 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -193,14 +193,15 @@ int pci_bus_num(PCIBus *s)
static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
{
PCIDevice *s = container_of(pv, PCIDevice, config);
- uint8_t config[size];
+ uint8_t config[PCI_CONFIG_SPACE_SIZE];
int i;
- qemu_get_buffer(f, config, size);
- for (i = 0; i < size; ++i)
+ assert(size == sizeof config);
+ qemu_get_buffer(f, config, sizeof config);
+ for (i = 0; i < sizeof config; ++i)
if ((config[i] ^ s->config[i]) & s->cmask[i] & ~s->wmask[i])
return -EINVAL;
- memcpy(s->config, config, size);
+ memcpy(s->config, config, sizeof config);
pci_update_mappings(s);
--
1.6.5.rc2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Qemu-devel] Re: [PATCH] qemu/pci: clarify pci config load routine
2009-10-05 20:46 [Qemu-devel] [PATCH] qemu/pci: clarify pci config load routine Michael S. Tsirkin
@ 2009-10-05 22:47 ` Juan Quintela
0 siblings, 0 replies; 2+ messages in thread
From: Juan Quintela @ 2009-10-05 22:47 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: qemu-devel
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> PCI load routine has to be called with size equal to 256 (otherwise it
> will crash in weird ways). So assert this,
Agreed with the assert().
> making code clearer.
> Also avoid dynamically sized array on stack - good for portability.
size has the right value, namely sizeof(PCIDevice.config). Only real
advantage is that you are not using a dynamically sized array on the
stack.
I don't care one way or another. And as you are more probable to touch
that code than me, it is up to you :)
Later, Juan.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-10-05 22:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-05 20:46 [Qemu-devel] [PATCH] qemu/pci: clarify pci config load routine Michael S. Tsirkin
2009-10-05 22:47 ` [Qemu-devel] " Juan Quintela
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).