vDPA/ifcvf: dynamic allocate vq data stores
authorZhu Lingshan <lingshan.zhu@intel.com>
Mon, 12 Jun 2023 15:14:18 +0000 (23:14 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Mon, 3 Jul 2023 16:15:12 +0000 (12:15 -0400)
This commit dynamically allocates the data
stores for the virtqueues based on
virtio_pci_common_cfg.num_queues.

Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com>
Message-Id: <20230612151420.1019504-2-lingshan.zhu@intel.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vdpa/ifcvf/ifcvf_base.c
drivers/vdpa/ifcvf/ifcvf_base.h
drivers/vdpa/ifcvf/ifcvf_main.c

index 1b5da11..f86495a 100644 (file)
@@ -134,6 +134,9 @@ next:
        }
 
        hw->nr_vring = vp_ioread16(&hw->common_cfg->num_queues);
+       hw->vring = kzalloc(sizeof(struct vring_info) * hw->nr_vring, GFP_KERNEL);
+       if (!hw->vring)
+               return -ENOMEM;
 
        for (i = 0; i < hw->nr_vring; i++) {
                vp_iowrite16(i, &hw->common_cfg->queue_select);
index 3110ffc..fa79718 100644 (file)
@@ -74,7 +74,7 @@ struct ifcvf_hw {
        u64 dev_features;
        struct virtio_pci_common_cfg __iomem *common_cfg;
        void __iomem *dev_cfg;
-       struct vring_info vring[IFCVF_MAX_QUEUES];
+       struct vring_info *vring;
        void __iomem * const *base;
        char config_msix_name[256];
        struct vdpa_callback config_cb;
index 6e47ac2..2af0de7 100644 (file)
@@ -830,6 +830,7 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        return 0;
 
 err:
+       kfree(ifcvf_mgmt_dev->vf.vring);
        kfree(ifcvf_mgmt_dev);
        return ret;
 }
@@ -840,6 +841,7 @@ static void ifcvf_remove(struct pci_dev *pdev)
 
        ifcvf_mgmt_dev = pci_get_drvdata(pdev);
        vdpa_mgmtdev_unregister(&ifcvf_mgmt_dev->mdev);
+       kfree(ifcvf_mgmt_dev->vf.vring);
        kfree(ifcvf_mgmt_dev);
 }