* [PATCH net] net/smc: remove device from smcd_dev_list after failed device_add()
@ 2021-05-17 8:47 Karsten Graul
2021-05-17 22:30 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Karsten Graul @ 2021-05-17 8:47 UTC (permalink / raw)
To: David Miller, Jakub Kicinski
Cc: Heiko Carstens, Stefan Raspl, netdev, linux-s390
From: Julian Wiedmann <jwi@linux.ibm.com>
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.
Fixes: c6ba7c9ba43d ("net/smc: add base infrastructure for SMC-D and ISM")
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
---
net/smc/smc_ism.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c
index 9c6e95882553..d24b96ea0eb5 100644
--- a/net/smc/smc_ism.c
+++ b/net/smc/smc_ism.c
@@ -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);
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net/smc: remove device from smcd_dev_list after failed device_add()
2021-05-17 8:47 [PATCH net] net/smc: remove device from smcd_dev_list after failed device_add() Karsten Graul
@ 2021-05-17 22:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-05-17 22:30 UTC (permalink / raw)
To: Karsten Graul; +Cc: davem, kuba, hca, raspl, netdev, linux-s390
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
On Mon, 17 May 2021 10:47:06 +0200 you wrote:
> From: Julian Wiedmann <jwi@linux.ibm.com>
>
> 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.
>
> [...]
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-17 22:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 8:47 [PATCH net] net/smc: remove device from smcd_dev_list after failed device_add() Karsten Graul
2021-05-17 22:30 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.