accel/amdxdna: fix IRQ vector leak in aie2_init()
PATCH 1/1 accel/amdxdna: fix IRQ vector leak in aie2_init()
aie2_init() allocates MSI-X vectors with pci_alloc_irq_vectors() before creating the PSP handle, starting the hardware and initializing the resolver.
When aie2m_psp_create(), aie2_hw_start() or xrsm_init() fails after IRQ vectors have been allocated successfully, the function releases the firmware and unwinds hardware state, but fails to free the allocated IRQ vectors.
The issue was identified by a static analysis tool I developed and confirmed by manual review. Add a dedicated error path to free the IRQ vectors after pci_alloc_irq_vectors() succeeds.
--- drivers/accel/amdxdna/aie2_pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/accel/amdxdna/aie2_pci.c +4 -2
@@ -591,14 +591,14 @@ static int aie2_init(struct amdxdna_dev *xdna)if (!ndev->psp_hdl) {XDNA_ERR (xdna,"failed to create psp" ); ret = -ENOMEM ; - goto release_fw; + goto free_irq_vectors; } xdna->dev_handle = ndev; ret =aie2_hw_start (xdna);if (ret) {XDNA_ERR (xdna,"start npu failed, ret %d" , ret); - goto release_fw; + goto free_irq_vectors; } xrs_cfg.clk_list.num_levels = ndev->max_dpm_level +1 ;
@@ -623,6 +623,8 @@ static int aie2_init(struct amdxdna_dev *xdna) stop_hw:aie2_hw_stop (xdna); +free_irq_vectors: +pci_free_irq_vectors (pdev); release_fw:release_firmware (fw);
Signature · 1 line
2.43.0
Lizhi Hou
maintainerQuoted 10 lines · Guangshuo Li
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
aie2_init()allocates MSI-X vectors withpci_alloc_irq_vectors()before creating the PSP handle, starting the hardware and initializing the resolver.When
aie2m_psp_create(),aie2_hw_start()orxrsm_init()fails after IRQ vectors have been allocated successfully, the function releases the firmware and unwinds hardware state, but fails to free the allocated IRQ vectors.
aie2_init enables device via pcim_enable_device(), which sets managed device. Thus the vectors are automatically cleanup. So NAK.
Lizhi
Quoted 45 lines
The issue was identified by a static analysis tool I developed and confirmed by manual review. Add a dedicated error path to free the IRQ vectors after
pci_alloc_irq_vectors()succeeds.Fixes 8c9ff1b181ba ("accel/amdxdna: Add a new driver for AMD AI Engine")Signed-off-by Guangshuo Li <[email protected]>--- drivers/accel/amdxdna/aie2_pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/accel/amdxdna/aie2_pci.c +4
-3@@ -591,14 +591,14 @@ static int aie2_init(struct amdxdna_dev *xdna)if (!ndev->psp_hdl) {XDNA_ERR (xdna,"failed to create psp" ); ret = -ENOMEM ; - goto release_fw; + goto free_irq_vectors; } xdna->dev_handle = ndev; ret =aie2_hw_start (xdna);if (ret) {XDNA_ERR (xdna,"start npu failed, ret %d" , ret); - goto release_fw; + goto free_irq_vectors; } xrs_cfg.clk_list.num_levels = ndev->max_dpm_level +1 ;@@ -623,6 +623,8 @@ static int aie2_init(struct amdxdna_dev *xdna) stop_hw:aie2_hw_stop (xdna); +free_irq_vectors: +pci_free_irq_vectors (pdev); release_fw:release_firmware (fw); --2.43.0
Hello,
Thanks for reviewing.
Quoted 10 lines · Lizhi Hou
aie2_initenables device viapcim_enable_device(), which sets managed device. Thus the vectors are automatically cleanup. So NAK.Lizhi
Sorry, I missed that pcim_enable_device() already makes the device managed, so the IRQ vectors are cleaned up automatically. Thanks for pointing it out.
Best regards,
Guangshuo