net: hns3: Fixes the out of bounds access in hclge_map_tqp
authorHuazhong Tan <tanhuazhong@huawei.com>
Tue, 1 May 2018 18:55:59 +0000 (19:55 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 1 May 2018 19:08:37 +0000 (15:08 -0400)
This patch fixes the handling of the check when number of vports
are detected to be more than available TPQs. Current handling causes
an out of bounds access in hclge_map_tqp().

Fixes: 7df7dad633e2 ("net: hns3: Refactor the mapping of tqp to vport")
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

index 2066dd734444468ec644179194898193953548be..c9e80ca6d98a88c7ffa717a74afb1b1c8fac95a2 100644 (file)
@@ -1459,8 +1459,11 @@ static int hclge_alloc_vport(struct hclge_dev *hdev)
        /* We need to alloc a vport for main NIC of PF */
        num_vport = hdev->num_vmdq_vport + hdev->num_req_vfs + 1;
 
-       if (hdev->num_tqps < num_vport)
-               num_vport = hdev->num_tqps;
+       if (hdev->num_tqps < num_vport) {
+               dev_err(&hdev->pdev->dev, "tqps(%d) is less than vports(%d)",
+                       hdev->num_tqps, num_vport);
+               return -EINVAL;
+       }
 
        /* Alloc the same number of TQPs for every vport */
        tqp_per_vport = hdev->num_tqps / num_vport;