Skip to content

Commit a229989

Browse files
wei-w-wangmstsirkin
authored andcommitted
virtio: don't allocate vqs when names[i] = NULL
Some vqs may not need to be allocated when their related feature bits are disabled. So callers may pass in such vqs with "names = NULL". Then we skip such vq allocations. Signed-off-by: Wei Wang <wei.w.wang@intel.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Wei Wang <wei.w.wang@intel.com> Signed-off-by: Wei Wang <wei.w.wang@intel.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Cc: stable@vger.kernel.org Fixes: 86a5597 ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT")
1 parent ddbeac0 commit a229989

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

drivers/misc/mic/vop/vop_main.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,21 @@ static int vop_find_vqs(struct virtio_device *dev, unsigned nvqs,
394394
struct _vop_vdev *vdev = to_vopvdev(dev);
395395
struct vop_device *vpdev = vdev->vpdev;
396396
struct mic_device_ctrl __iomem *dc = vdev->dc;
397-
int i, err, retry;
397+
int i, err, retry, queue_idx = 0;
398398

399399
/* We must have this many virtqueues. */
400400
if (nvqs > ioread8(&vdev->desc->num_vq))
401401
return -ENOENT;
402402

403403
for (i = 0; i < nvqs; ++i) {
404+
if (!names[i]) {
405+
vqs[i] = NULL;
406+
continue;
407+
}
408+
404409
dev_dbg(_vop_dev(vdev), "%s: %d: %s\n",
405410
__func__, i, names[i]);
406-
vqs[i] = vop_find_vq(dev, i, callbacks[i], names[i],
411+
vqs[i] = vop_find_vq(dev, queue_idx++, callbacks[i], names[i],
407412
ctx ? ctx[i] : false);
408413
if (IS_ERR(vqs[i])) {
409414
err = PTR_ERR(vqs[i]);

drivers/remoteproc/remoteproc_virtio.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,15 @@ static int rproc_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
153153
const bool * ctx,
154154
struct irq_affinity *desc)
155155
{
156-
int i, ret;
156+
int i, ret, queue_idx = 0;
157157

158158
for (i = 0; i < nvqs; ++i) {
159-
vqs[i] = rp_find_vq(vdev, i, callbacks[i], names[i],
159+
if (!names[i]) {
160+
vqs[i] = NULL;
161+
continue;
162+
}
163+
164+
vqs[i] = rp_find_vq(vdev, queue_idx++, callbacks[i], names[i],
160165
ctx ? ctx[i] : false);
161166
if (IS_ERR(vqs[i])) {
162167
ret = PTR_ERR(vqs[i]);

drivers/s390/virtio/virtio_ccw.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -635,16 +635,22 @@ static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
635635
{
636636
struct virtio_ccw_device *vcdev = to_vc_device(vdev);
637637
unsigned long *indicatorp = NULL;
638-
int ret, i;
638+
int ret, i, queue_idx = 0;
639639
struct ccw1 *ccw;
640640

641641
ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
642642
if (!ccw)
643643
return -ENOMEM;
644644

645645
for (i = 0; i < nvqs; ++i) {
646-
vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i],
647-
ctx ? ctx[i] : false, ccw);
646+
if (!names[i]) {
647+
vqs[i] = NULL;
648+
continue;
649+
}
650+
651+
vqs[i] = virtio_ccw_setup_vq(vdev, queue_idx++, callbacks[i],
652+
names[i], ctx ? ctx[i] : false,
653+
ccw);
648654
if (IS_ERR(vqs[i])) {
649655
ret = PTR_ERR(vqs[i]);
650656
vqs[i] = NULL;

drivers/virtio/virtio_mmio.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,20 @@ static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
468468
{
469469
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
470470
unsigned int irq = platform_get_irq(vm_dev->pdev, 0);
471-
int i, err;
471+
int i, err, queue_idx = 0;
472472

473473
err = request_irq(irq, vm_interrupt, IRQF_SHARED,
474474
dev_name(&vdev->dev), vm_dev);
475475
if (err)
476476
return err;
477477

478478
for (i = 0; i < nvqs; ++i) {
479-
vqs[i] = vm_setup_vq(vdev, i, callbacks[i], names[i],
479+
if (!names[i]) {
480+
vqs[i] = NULL;
481+
continue;
482+
}
483+
484+
vqs[i] = vm_setup_vq(vdev, queue_idx++, callbacks[i], names[i],
480485
ctx ? ctx[i] : false);
481486
if (IS_ERR(vqs[i])) {
482487
vm_del_vqs(vdev);

0 commit comments

Comments
 (0)