From 61c8617edd9bcc3a55bbe90a6b65ac49a8c84744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sun, 1 Dec 2024 17:52:00 +0100 Subject: [PATCH] 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 Haiku-Format: Haiku-format Bot Reviewed-by: waddlesplash (cherry picked from commit d866277547820acbd16cee21aa6475527f747f94) Reviewed-on: https://review.haiku-os.org/c/haiku/+/8638 --- .../kernel/busses/virtio/virtio_pci/virtio_pci.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/busses/virtio/virtio_pci/virtio_pci.cpp b/src/add-ons/kernel/busses/virtio/virtio_pci/virtio_pci.cpp index 03dd2bd123..863b2fa0f6 100644 --- a/src/add-ons/kernel/busses/virtio/virtio_pci/virtio_pci.cpp +++ b/src/add-ons/kernel/busses/virtio/virtio_pci/virtio_pci.cpp @@ -417,10 +417,9 @@ setup_queue(void* cookie, uint16 queue, phys_addr_t phy, phys_addr_t phyAvail, { CALLED(); virtio_pci_sim_info* bus = (virtio_pci_sim_info*)cookie; - if (queue >= bus->queue_count) - return B_BAD_VALUE; - if (bus->virtio1) { + if (queue >= bus->queue_count) + return B_BAD_VALUE; volatile uint16* queueSelect = (uint16*)(bus->commonCfgAddr + offsetof(struct virtio_pci_common_cfg, queue_select)); *queueSelect = queue; @@ -603,6 +602,7 @@ init_bus(device_node* node, void** bus_cookie) if (bus == NULL) { return B_NO_MEMORY; } + memset(bus, 0, sizeof(virtio_pci_sim_info)); pci_device_module_info* pci; pci_device* device; @@ -694,7 +694,8 @@ init_bus(device_node* node, void** bus_cookie) volatile uint16 *queueCount = (uint16*)(bus->commonCfgAddr + 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 { // legacy interrupt