]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: hns3: fix a wrong checking in the hclge_tx_buffer_calc()
authorHuazhong Tan <tanhuazhong@huawei.com>
Sat, 2 Feb 2019 14:39:32 +0000 (22:39 +0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 2 Feb 2019 16:24:08 +0000 (08:24 -0800)
Only the TC is enabled, we need to check whether the buffer is enough,
otherwise it may lead to a wrong -ENOMEM case.

Fixes: 9ffe79a9c2ee ("net: hns3: Support for dynamically assigning tx buffer to TC")
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

index a037dc5e36b7855f0decbcdbb4c1eb3c6dc9bcb5..5f6fc23fab5df63d61e01e8476f683b101666afc 100644 (file)
@@ -1506,13 +1506,14 @@ static int hclge_tx_buffer_calc(struct hclge_dev *hdev,
        for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
                struct hclge_priv_buf *priv = &buf_alloc->priv_buf[i];
 
-               if (total_size < hdev->tx_buf_size)
-                       return -ENOMEM;
+               if (hdev->hw_tc_map & BIT(i)) {
+                       if (total_size < hdev->tx_buf_size)
+                               return -ENOMEM;
 
-               if (hdev->hw_tc_map & BIT(i))
                        priv->tx_buf_size = hdev->tx_buf_size;
-               else
+               } else {
                        priv->tx_buf_size = 0;
+               }
 
                total_size -= priv->tx_buf_size;
        }