This commit dynamically allocates the data
stores for the virtqueues based on
virtio_pci_common_cfg.num_queues.

Signed-off-by: Zhu Lingshan <lingshan....@intel.com>
---
 drivers/vdpa/ifcvf/ifcvf_base.c | 4 ++++
 drivers/vdpa/ifcvf/ifcvf_base.h | 2 +-
 drivers/vdpa/ifcvf/ifcvf_main.c | 2 ++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/ifcvf/ifcvf_base.c b/drivers/vdpa/ifcvf/ifcvf_base.c
index 5563b3a773c7..3c40caf4aa0b 100644
--- a/drivers/vdpa/ifcvf/ifcvf_base.c
+++ b/drivers/vdpa/ifcvf/ifcvf_base.c
@@ -134,6 +134,9 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev)
        }
 
        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);
@@ -316,6 +319,7 @@ u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid)
 
 int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num)
 {
+
        struct ifcvf_lm_cfg __iomem *ifcvf_lm;
        void __iomem *avail_idx_addr;
        u32 q_pair_id;
diff --git a/drivers/vdpa/ifcvf/ifcvf_base.h b/drivers/vdpa/ifcvf/ifcvf_base.h
index c20d1c40214e..745282239d6d 100644
--- a/drivers/vdpa/ifcvf/ifcvf_base.h
+++ b/drivers/vdpa/ifcvf/ifcvf_base.h
@@ -80,7 +80,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;
diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
index 7f78c47e40d6..c97dde02bbb6 100644
--- a/drivers/vdpa/ifcvf/ifcvf_main.c
+++ b/drivers/vdpa/ifcvf/ifcvf_main.c
@@ -892,6 +892,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;
 }
@@ -902,6 +903,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);
 }
 
-- 
2.39.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reply via email to