When devm_kcalloc() fails for priv->tqp_vector after get_vector() has already acquired MSI-X vectors, the error path returns without calling put_vector() to release them, leaving the hclge/hclgevf bookkeeping (num_msi_used, num_msi_left, vector_status[]) inconsistent. Call put_vector() for every acquired vector before returning the error, and reset priv->vector_num to 0 so the count never describes vectors that were already handed back. Fixes: dd38c72604dc ("net: hns3: fix for coalesce configuration lost during reset") Signed-off-by: Jijie Shao --- Changes in v4: - Correct the reason for resetting priv->vector_num. Sashiko pointed out that hns3_nic_dealloc_vector_data() is not reachable after hns3_nic_alloc_vector_data() fails, so the reset is not protecting that path; it keeps the count from describing vectors that were already handed back. v3: https://lore.kernel.org/all/20261030095633.377289-2-shaojijie@huawei.com/ Changes in v3: - Simplify commit message: drop the accumulated-leak consequence paragraph and clarify that the vector_num reset avoids a NULL deref in hns3_nic_dealloc_vector_data(). v2: https://lore.kernel.org/all/20261021121426.3096838-2-shaojijie@huawei.com/ --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index db4f584c4ce1..e2fb5899bba1 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -4851,7 +4851,7 @@ static int hns3_nic_alloc_vector_data(struct hns3_nic_priv *priv) devm_kzalloc_objs(&pdev->dev, *priv->tqp_vector, vector_num); if (!priv->tqp_vector) { ret = -ENOMEM; - goto out; + goto err_put_vector; } for (i = 0; i < priv->vector_num; i++) { @@ -4862,7 +4862,13 @@ static int hns3_nic_alloc_vector_data(struct hns3_nic_priv *priv) hns3_vector_coalesce_init(tqp_vector, priv); } -out: + devm_kfree(&pdev->dev, vector); + return 0; + +err_put_vector: + for (i = 0; i < vector_num; i++) + h->ae_algo->ops->put_vector(h, vector[i].vector); + priv->vector_num = 0; devm_kfree(&pdev->dev, vector); return ret; } -- 2.43.0