summaryrefslogtreecommitdiff
path: root/net/smc
diff options
context:
space:
mode:
authorJulian Wiedmann <jwi@linux.ibm.com>2021-05-17 11:47:06 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-06-03 10:00:48 +0300
commit8b2cdc004d21a7255f219706dca64411108f7897 (patch)
treeb8eb1cf85b0cabe85fa0ec74f9271e221a138a95 /net/smc
parentbeb39adb150f8f3b516ddf7c39835a9788704d23 (diff)
downloadlinux-8b2cdc004d21a7255f219706dca64411108f7897.tar.xz
net/smc: remove device from smcd_dev_list after failed device_add()
[ Upstream commit 444d7be9532dcfda8e0385226c862fd7e986f607 ] 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> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net/smc')
-rw-r--r--net/smc/smc_ism.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c
index 024ca21392f7..8e33c0128d73 100644
--- a/net/smc/smc_ism.c
+++ b/net/smc/smc_ism.c
@@ -331,6 +331,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;
@@ -350,7 +352,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);