Skip to contentSkip to conversation

net: wwan: iosm: Call mutex_init before locking it

PATCH Applied Maxim Mikityanskiy 3 participants 3 messages Oct 1, 2022 – Oct 3, 2022

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

PATCH 1/1 net: wwan: iosm: Call mutex_init before locking it

wwan_register_ops calls wwan_create_default_link, which ends up in the ipc_wwan_newlink callback that locks ipc_wwan->if_mutex. However, this mutex is not yet initialized by that point. Fix it by moving mutex_init above the wwan_register_ops call. This also makes the order of operations in ipc_wwan_init symmetric to ipc_wwan_deinit.

Fixes 83068395bbfc ("net: iosm: create default link via WWAN core")
---
 drivers/net/wwan/iosm/iosm_ipc_wwan.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/wwan/iosm/iosm_ipc_wwan.c +3 -2
index 27151148c782..4712f01a7e33 100644
@@ -323,15 +323,16 @@ struct iosm_wwan *ipc_wwan_init(struct iosm_imem *ipc_imem, struct device *dev)
 	ipc_wwan->dev = dev;
 	ipc_wwan->ipc_imem = ipc_imem;
 
+	mutex_init(&ipc_wwan->if_mutex);
+
 	/* WWAN core will create a netdev for the default IP MUX channel */
 	if (wwan_register_ops(ipc_wwan->dev, &iosm_wwan_ops, ipc_wwan,
 			      IP_MUX_SESSION_DEFAULT)) {
+		mutex_destroy(&ipc_wwan->if_mutex);
 		kfree(ipc_wwan);
 		return NULL;
 	}
 
-	mutex_init(&ipc_wwan->if_mutex);
-
 	return ipc_wwan;
 }
 
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 49 lines

-----Original Message-----
From: Maxim Mikityanskiy <[email protected]>
Sent: Saturday, October 1, 2022 4:27 PM
To: Kumar, M Chetan <[email protected]>; linuxwwan <[email protected]>
Cc: Loic Poulain <[email protected]>; Sergey Ryazanov <[email protected]>; Johannes Berg <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; Maxim Mikityanskiy <[email protected]>
Subject: [PATCH net] net: wwan: iosm: Call mutex_init before locking it

wwan_register_ops calls wwan_create_default_link, which ends up in the ipc_wwan_newlink callback that locks ipc_wwan->if_mutex. However, this mutex is not yet initialized by that point. Fix it by moving mutex_init above the wwan_register_ops call. This also makes the order of operations in ipc_wwan_init symmetric to ipc_wwan_deinit.

Fixes 83068395bbfc ("net: iosm: create default link via WWAN core")
---
 drivers/net/wwan/iosm/iosm_ipc_wwan.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/wwan/iosm/iosm_ipc_wwan.c +3 -2
index 27151148c782..4712f01a7e33 100644
@@ -323,15 +323,16 @@ struct iosm_wwan *ipc_wwan_init(struct
 iosm_imem *ipc_imem, struct device *dev)
 	ipc_wwan->dev = dev;
 	ipc_wwan->ipc_imem = ipc_imem;
 
+	mutex_init(&ipc_wwan->if_mutex);
+
 	/* WWAN core will create a netdev for the default IP MUX channel */
 	if (wwan_register_ops(ipc_wwan->dev, &iosm_wwan_ops,
 ipc_wwan,
 			      IP_MUX_SESSION_DEFAULT)) {
+		mutex_destroy(&ipc_wwan->if_mutex);
 		kfree(ipc_wwan);
 		return NULL;
 	}
 
-	mutex_init(&ipc_wwan->if_mutex);
-
 	return ipc_wwan;
Quoted 1 line

}

#2 lore raw
In reply to Maxim Mikityanskiy
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:

Quoted 10 lines · On Sat, 1 Oct 2022 13:57:13 +0300 you wrote:

wwan_register_ops calls wwan_create_default_link, which ends up in the ipc_wwan_newlink callback that locks ipc_wwan->if_mutex. However, this mutex is not yet initialized by that point. Fix it by moving mutex_init above the wwan_register_ops call. This also makes the order of operations in ipc_wwan_init symmetric to ipc_wwan_deinit.

Fixes 83068395bbfc ("net: iosm: create default link via WWAN core")

[...]

Here is the summary with links:
- [net] net: wwan: iosm: Call mutex_init before locking it

    https://git.kernel.org/netdev/net/c/ba0fbdb95da5

You are awesome, thank you!

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