Skip to content

Commit ddbeac0

Browse files
wei-w-wangmstsirkin
authored andcommitted
virtio_pci: use queue idx instead of array idx to set up the vq
When find_vqs, there will be no vq[i] allocation if its corresponding names[i] is NULL. For example, the caller may pass in names[i] (i=4) with names[2] being NULL because the related feature bit is turned off, so technically there are 3 queues on the device, and name[4] should correspond to the 3rd queue on the device. So we use queue_idx as the queue index, which is increased only when the queue exists. Signed-off-by: Wei Wang <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Wei Wang <[email protected]> Signed-off-by: Wei Wang <[email protected]>
1 parent d1c1dad commit ddbeac0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/virtio/virtio_pci_common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
285285
{
286286
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
287287
u16 msix_vec;
288-
int i, err, nvectors, allocated_vectors;
288+
int i, err, nvectors, allocated_vectors, queue_idx = 0;
289289

290290
vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL);
291291
if (!vp_dev->vqs)
@@ -321,7 +321,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs,
321321
msix_vec = allocated_vectors++;
322322
else
323323
msix_vec = VP_MSIX_VQ_VECTOR;
324-
vqs[i] = vp_setup_vq(vdev, i, callbacks[i], names[i],
324+
vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
325325
ctx ? ctx[i] : false,
326326
msix_vec);
327327
if (IS_ERR(vqs[i])) {
@@ -356,7 +356,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
356356
const char * const names[], const bool *ctx)
357357
{
358358
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
359-
int i, err;
359+
int i, err, queue_idx = 0;
360360

361361
vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL);
362362
if (!vp_dev->vqs)
@@ -374,7 +374,7 @@ static int vp_find_vqs_intx(struct virtio_device *vdev, unsigned nvqs,
374374
vqs[i] = NULL;
375375
continue;
376376
}
377-
vqs[i] = vp_setup_vq(vdev, i, callbacks[i], names[i],
377+
vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
378378
ctx ? ctx[i] : false,
379379
VIRTIO_MSI_NO_VECTOR);
380380
if (IS_ERR(vqs[i])) {

0 commit comments

Comments
 (0)