Skip to contentSkip to conversation

hinic3: handle auxiliary device ID allocation failure

PATCH Applied Sang-Hoon Choi 3 participants 3 messages Sep 21 – Sep 28

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hinic3: handle auxiliary device ID allocation failure

hinic3_init_hwdev() stores the result of hinic3_adev_idx_alloc() in hwdev->dev_id without checking for an error. If ID allocation fails but the remaining initialization succeeds, hinic3_add_one_adev() uses the negative error code as the auxiliary device ID instead of a reserved ID.

Return the allocation error before initializing the hardware. Add an unwind label that clears pci_adapter->hwdev and frees the allocation without attempting to release an ID that was never allocated.

Fixes 8133788d023f ("hinic3: Nic_io initialization")
Assisted-by LLM

---
Found during source review at mainline 5dd1818b15d98d4a20806cd00b1b40320b06004f. The affected source is unchanged at f0100363d8c374bd8e9ea7c9ba02744f0b802ca4.

The modified hinic3_hwdev.o compiled with x86 allmodconfig and W=1. I have not tested this on hinic3 hardware or injected ID allocation failures.

drivers/net/ethernet/huawei/hinic3/hinic3_hwdev.c +6 -1
index f44b3064a..830bf9aad 100644
@@ -545,6 +545,10 @@ int hinic3_init_hwdev(struct pci_dev *pdev)
 	hwdev->dev = &pci_adapter->pdev->dev;
 	hwdev->func_state = 0;
 	hwdev->dev_id = hinic3_adev_idx_alloc();
+	if (hwdev->dev_id < 0) {
+		err = hwdev->dev_id;
+		goto err_free_hwdev_no_id;
+	}
 	spin_lock_init(&hwdev->channel_lock);
 
 	err = hinic3_init_hwif(hwdev);
@@ -602,8 +606,9 @@ int hinic3_init_hwdev(struct pci_dev *pdev)
 err_free_hwif:
 	hinic3_free_hwif(hwdev);
 err_free_hwdev:
-	pci_adapter->hwdev = NULL;
 	hinic3_adev_idx_free(hwdev->dev_id);
+err_free_hwdev_no_id:
+	pci_adapter->hwdev = NULL;
 	kfree(hwdev);
 
 	return err;
maintainer
#1 lore raw
Quoted 13 lines

hinic3_init_hwdev() stores the result of hinic3_adev_idx_alloc() in hwdev->dev_id without checking for an error. If ID allocation fails but the remaining initialization succeeds, hinic3_add_one_adev() uses the negative error code as the auxiliary device ID instead of a reserved ID.

Return the allocation error before initializing the hardware. Add an unwind label that clears pci_adapter->hwdev and frees the allocation without attempting to release an ID that was never allocated.

Fixes 8133788d023f ("hinic3: Nic_io initialization")
Assisted-by LLM
Quoted 8 lines

---
Found during source review at mainline 5dd1818b15d98d4a20806cd00b1b40320b06004f. The affected source is unchanged at f0100363d8c374bd8e9ea7c9ba02744f0b802ca4.

The modified hinic3_hwdev.o compiled with x86 allmodconfig and W=1. I have not tested this on hinic3 hardware or injected ID allocation failures.

Thank you for your contribution! We will test this patch later.

#2 lore raw
In reply to Sang-Hoon Choi
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 22 Sep 2026 03:49:28 +0900 you wrote:

hinic3_init_hwdev() stores the result of hinic3_adev_idx_alloc() in hwdev->dev_id without checking for an error. If ID allocation fails but the remaining initialization succeeds, hinic3_add_one_adev() uses the negative error code as the auxiliary device ID instead of a reserved ID.

Return the allocation error before initializing the hardware. Add an unwind label that clears pci_adapter->hwdev and frees the allocation without attempting to release an ID that was never allocated.

[...]

Here is the summary with links:
- [net] hinic3: handle auxiliary device ID allocation failure

    https://git.kernel.org/netdev/net-next/c/087827628ad3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html