mirror of
https://github.com/torvalds/linux.git
synced 2026-06-08 22:52:35 +02:00
net/smc: remove device from smcd_dev_list after failed device_add()
[ Upstream commit444d7be953] 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:c6ba7c9ba4("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>
This commit is contained in:
parent
beb39adb15
commit
8b2cdc004d
|
|
@ -331,6 +331,8 @@ EXPORT_SYMBOL_GPL(smcd_alloc_dev);
|
||||||
|
|
||||||
int smcd_register_dev(struct smcd_dev *smcd)
|
int smcd_register_dev(struct smcd_dev *smcd)
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
mutex_lock(&smcd_dev_list.mutex);
|
mutex_lock(&smcd_dev_list.mutex);
|
||||||
if (list_empty(&smcd_dev_list.list)) {
|
if (list_empty(&smcd_dev_list.list)) {
|
||||||
u8 *system_eid = NULL;
|
u8 *system_eid = NULL;
|
||||||
|
|
@ -350,7 +352,14 @@ int smcd_register_dev(struct smcd_dev *smcd)
|
||||||
dev_name(&smcd->dev), smcd->pnetid,
|
dev_name(&smcd->dev), smcd->pnetid,
|
||||||
smcd->pnetid_by_user ? " (user defined)" : "");
|
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);
|
EXPORT_SYMBOL_GPL(smcd_register_dev);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user