virtio_pci: in setup_queue(), only check queue number on v1 devices

* fix #18962
* bus->queue_count wasn't initialized yet so the check could succeed
or not, depending on the init value for memory: on release, 0 mostly,
on nightly, a non-zero value.

Change-Id: Id745932e8171abe3b8b78a3e9b2f2058c9507f7a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8618
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
(cherry picked from commit d866277547)
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8638
This commit is contained in:
Jérôme Duval 2024-12-01 17:52:00 +01:00 committed by waddlesplash
parent 4687fe0566
commit 61c8617edd

View File

@ -417,10 +417,9 @@ setup_queue(void* cookie, uint16 queue, phys_addr_t phy, phys_addr_t phyAvail,
{ {
CALLED(); CALLED();
virtio_pci_sim_info* bus = (virtio_pci_sim_info*)cookie; virtio_pci_sim_info* bus = (virtio_pci_sim_info*)cookie;
if (queue >= bus->queue_count)
return B_BAD_VALUE;
if (bus->virtio1) { if (bus->virtio1) {
if (queue >= bus->queue_count)
return B_BAD_VALUE;
volatile uint16* queueSelect = (uint16*)(bus->commonCfgAddr volatile uint16* queueSelect = (uint16*)(bus->commonCfgAddr
+ offsetof(struct virtio_pci_common_cfg, queue_select)); + offsetof(struct virtio_pci_common_cfg, queue_select));
*queueSelect = queue; *queueSelect = queue;
@ -603,6 +602,7 @@ init_bus(device_node* node, void** bus_cookie)
if (bus == NULL) { if (bus == NULL) {
return B_NO_MEMORY; return B_NO_MEMORY;
} }
memset(bus, 0, sizeof(virtio_pci_sim_info));
pci_device_module_info* pci; pci_device_module_info* pci;
pci_device* device; pci_device* device;
@ -694,7 +694,8 @@ init_bus(device_node* node, void** bus_cookie)
volatile uint16 *queueCount = (uint16*)(bus->commonCfgAddr volatile uint16 *queueCount = (uint16*)(bus->commonCfgAddr
+ offsetof(struct virtio_pci_common_cfg, num_queues)); + offsetof(struct virtio_pci_common_cfg, num_queues));
bus->notifyOffsets = new addr_t[*queueCount]; bus->queue_count = *queueCount;
bus->notifyOffsets = new addr_t[bus->queue_count];
} else { } else {
// legacy interrupt // legacy interrupt