Commit a9b1ec5f authored by Hao Chen's avatar Hao Chen Committed by Slim6882
Browse files

drivers/perf: hisi: hns3: Actually use devm_add_action_or_reset()

mainline inclusion
from mainline-v6.9-rc1
commit 582c1aeee0a9e73010cf1c4cef338709860deeb0
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I9HCSA
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/will/linux.git/commit/?h=for-next/perf&id=582c1aeee0a9e73010cf1c4cef338709860deeb0



------------------------------------------------------------------------

pci_alloc_irq_vectors() allocates an irq vector. When devm_add_action()
fails, the irq vector is not freed, which leads to a memory leak.

Replace the devm_add_action with devm_add_action_or_reset to ensure
the irq vector can be destroyed when it fails.

Fixes: 66637ab1 ("drivers/perf: hisi: add driver for HNS3 PMU")
Signed-off-by: default avatarHao Chen <chenhao418@huawei.com>
Signed-off-by: default avatarJunhao He <hejunhao3@huawei.com>
Reviewed-by: default avatarJijie Shao <shaojijie@huawei.com>
Acked-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20240425124627.13764-4-hejunhao3@huawei.com


Signed-off-by: default avatarWill Deacon <will@kernel.org>
Signed-off-by: default avatarSlim6882 <yangjunshuo@huawei.com>
parent ab4b395a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1535,7 +1535,7 @@ static int hns3_pmu_irq_register(struct pci_dev *pdev,
		return ret;
	}

	ret = devm_add_action(&pdev->dev, hns3_pmu_free_irq, pdev);
	ret = devm_add_action_or_reset(&pdev->dev, hns3_pmu_free_irq, pdev);
	if (ret) {
		pci_err(pdev, "failed to add free irq action, ret = %d.\n", ret);
		return ret;