net/smc: remove device from smcd_dev_list after failed device_add()
PATCH 1/1 net/smc: remove device from smcd_dev_list after failed device_add()
From: Julian Wiedmann <[email protected]>
If the device_add() for a smcd_dev fails, there's no cleanup step that rolls back the earlier list_add(). The device subsequently gets freed, and we end up with a corrupted list.
Add some error handling that removes the device from the list.
--- net/smc/smc_ism.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
net/smc/smc_ism.c +10 -1
@@ -428,6 +428,8 @@ EXPORT_SYMBOL_GPL(smcd_alloc_dev);int smcd_register_dev (struct smcd_dev *smcd) { +int rc; +mutex_lock (&smcd_dev_list.mutex);if (list_empty (&smcd_dev_list.list)) {u8 *system_eid =NULL ;
@@ -447,7 +449,14 @@ int smcd_register_dev(struct smcd_dev *smcd)dev_name (&smcd->dev), smcd->pnetid, smcd->pnetid_by_user ? " (user defined)" : ""); -return device_add (&smcd->dev); + rc =device_add (&smcd->dev); +if (rc) { +mutex_lock (&smcd_dev_list.mutex); +list_del (&smcd->list); +mutex_unlock (&smcd_dev_list.mutex); + } + +return rc; }EXPORT_SYMBOL_GPL (smcd_register_dev);
Signature · 1 line
2.25.1
This patch was applied to netdev/net.git (refs/heads/master):
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
Quoted 9 lines · On Mon, 17 May 2021 10:47:06 +0200 you wrote:
From: Julian Wiedmann <[email protected]>
If the
device_add()for asmcd_devfails, there's no cleanup step that rolls back the earlierlist_add(). The device subsequently gets freed, and we end up with a corrupted list.Add some error handling that removes the device from the list.
[...]
Here is the summary with links:
- [net] net/smc: remove device from smcd_dev_list after failed device_add()
https://git.kernel.org/netdev/net/c/444d7be9532d
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html