All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v1] net: wwan: iosm: Remove unneeded if_mutex lock
@ 2022-11-01  5:50 ` zhaoping.shu
  0 siblings, 0 replies; 4+ messages in thread
From: zhaoping.shu @ 2022-11-01  5:50 UTC (permalink / raw)
  To: m.chetan.kumar, linuxwwan, loic.poulain, ryazanov.s.a, johannes,
	davem, edumazet, kuba, pabeni, matthias.bgg
  Cc: netdev, linux-kernel, linux-arm-kernel, linux-mediatek,
	haijun.liu, xiayu.zhang, lambert.wang, zhaoping.shu

From: "zhaoping.shu" <zhaoping.shu@mediatek.com>

These WWAN network interface operations (create/delete/open/close) are
already protected by RTNL lock, i.e., wwan_ops.newlink(),
wwan_ops.dellink(), net_device_ops.ndo_open() and net_device.ndo_stop()
are called with RTNL lock held.
Therefore, this patch removes the unnecessary if_mutex.

Signed-off-by: zhaoping.shu <zhaoping.shu@mediatek.com>
---
 drivers/net/wwan/iosm/iosm_ipc_wwan.c | 42 ++++-----------------------
 1 file changed, 6 insertions(+), 36 deletions(-)

diff --git a/drivers/net/wwan/iosm/iosm_ipc_wwan.c b/drivers/net/wwan/iosm/iosm_ipc_wwan.c
index 2f1f8b5d5b59..fa2261697d53 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_wwan.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_wwan.c
@@ -40,13 +40,11 @@ struct iosm_netdev_priv {
  * @ipc_imem:		Pointer to imem data-struct
  * @sub_netlist:	List of active netdevs
  * @dev:		Pointer device structure
- * @if_mutex:		Mutex used for add and remove interface id
  */
 struct iosm_wwan {
 	struct iosm_imem *ipc_imem;
 	struct iosm_netdev_priv __rcu *sub_netlist[IP_MUX_SESSION_END + 1];
 	struct device *dev;
-	struct mutex if_mutex; /* Mutex used for add and remove interface id */
 };
 
 /* Bring-up the wwan net link */
@@ -55,14 +53,11 @@ static int ipc_wwan_link_open(struct net_device *netdev)
 	struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev);
 	struct iosm_wwan *ipc_wwan = priv->ipc_wwan;
 	int if_id = priv->if_id;
-	int ret;
 
 	if (if_id < IP_MUX_SESSION_START ||
 	    if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist))
 		return -EINVAL;
 
-	mutex_lock(&ipc_wwan->if_mutex);
-
 	/* get channel id */
 	priv->ch_id = ipc_imem_sys_wwan_open(ipc_wwan->ipc_imem, if_id);
 
@@ -70,8 +65,7 @@ static int ipc_wwan_link_open(struct net_device *netdev)
 		dev_err(ipc_wwan->dev,
 			"cannot connect wwan0 & id %d to the IPC mem layer",
 			if_id);
-		ret = -ENODEV;
-		goto out;
+		return -ENODEV;
 	}
 
 	/* enable tx path, DL data may follow */
@@ -80,10 +74,7 @@ static int ipc_wwan_link_open(struct net_device *netdev)
 	dev_dbg(ipc_wwan->dev, "Channel id %d allocated to if_id %d",
 		priv->ch_id, priv->if_id);
 
-	ret = 0;
-out:
-	mutex_unlock(&ipc_wwan->if_mutex);
-	return ret;
+	return 0;
 }
 
 /* Bring-down the wwan net link */
@@ -93,11 +84,9 @@ static int ipc_wwan_link_stop(struct net_device *netdev)
 
 	netif_stop_queue(netdev);
 
-	mutex_lock(&priv->ipc_wwan->if_mutex);
 	ipc_imem_sys_wwan_close(priv->ipc_wwan->ipc_imem, priv->if_id,
 				priv->ch_id);
 	priv->ch_id = -1;
-	mutex_unlock(&priv->ipc_wwan->if_mutex);
 
 	return 0;
 }
@@ -189,26 +178,17 @@ static int ipc_wwan_newlink(void *ctxt, struct net_device *dev,
 	priv->netdev = dev;
 	priv->ipc_wwan = ipc_wwan;
 
-	mutex_lock(&ipc_wwan->if_mutex);
-	if (rcu_access_pointer(ipc_wwan->sub_netlist[if_id])) {
-		err = -EBUSY;
-		goto out_unlock;
-	}
+	if (rcu_access_pointer(ipc_wwan->sub_netlist[if_id]))
+		return -EBUSY;
 
 	err = register_netdevice(dev);
 	if (err)
-		goto out_unlock;
+		return err;
 
 	rcu_assign_pointer(ipc_wwan->sub_netlist[if_id], priv);
-	mutex_unlock(&ipc_wwan->if_mutex);
-
 	netif_device_attach(dev);
 
 	return 0;
-
-out_unlock:
-	mutex_unlock(&ipc_wwan->if_mutex);
-	return err;
 }
 
 static void ipc_wwan_dellink(void *ctxt, struct net_device *dev,
@@ -222,17 +202,12 @@ static void ipc_wwan_dellink(void *ctxt, struct net_device *dev,
 		    if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist)))
 		return;
 
-	mutex_lock(&ipc_wwan->if_mutex);
-
 	if (WARN_ON(rcu_access_pointer(ipc_wwan->sub_netlist[if_id]) != priv))
-		goto unlock;
+		return;
 
 	RCU_INIT_POINTER(ipc_wwan->sub_netlist[if_id], NULL);
 	/* unregistering includes synchronize_net() */
 	unregister_netdevice_queue(dev, head);
-
-unlock:
-	mutex_unlock(&ipc_wwan->if_mutex);
 }
 
 static const struct wwan_ops iosm_wwan_ops = {
@@ -323,12 +298,9 @@ 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;
 	}
@@ -341,7 +313,5 @@ void ipc_wwan_deinit(struct iosm_wwan *ipc_wwan)
 	/* This call will remove all child netdev(s) */
 	wwan_unregister_ops(ipc_wwan->dev);
 
-	mutex_destroy(&ipc_wwan->if_mutex);
-
 	kfree(ipc_wwan);
 }
-- 
2.17.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net v1] net: wwan: iosm: Remove unneeded if_mutex lock
@ 2022-11-01  5:50 ` zhaoping.shu
  0 siblings, 0 replies; 4+ messages in thread
From: zhaoping.shu @ 2022-11-01  5:50 UTC (permalink / raw)
  To: m.chetan.kumar, linuxwwan, loic.poulain, ryazanov.s.a, johannes,
	davem, edumazet, kuba, pabeni, matthias.bgg
  Cc: netdev, linux-kernel, linux-arm-kernel, linux-mediatek,
	haijun.liu, xiayu.zhang, lambert.wang, zhaoping.shu

From: "zhaoping.shu" <zhaoping.shu@mediatek.com>

These WWAN network interface operations (create/delete/open/close) are
already protected by RTNL lock, i.e., wwan_ops.newlink(),
wwan_ops.dellink(), net_device_ops.ndo_open() and net_device.ndo_stop()
are called with RTNL lock held.
Therefore, this patch removes the unnecessary if_mutex.

Signed-off-by: zhaoping.shu <zhaoping.shu@mediatek.com>
---
 drivers/net/wwan/iosm/iosm_ipc_wwan.c | 42 ++++-----------------------
 1 file changed, 6 insertions(+), 36 deletions(-)

diff --git a/drivers/net/wwan/iosm/iosm_ipc_wwan.c b/drivers/net/wwan/iosm/iosm_ipc_wwan.c
index 2f1f8b5d5b59..fa2261697d53 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_wwan.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_wwan.c
@@ -40,13 +40,11 @@ struct iosm_netdev_priv {
  * @ipc_imem:		Pointer to imem data-struct
  * @sub_netlist:	List of active netdevs
  * @dev:		Pointer device structure
- * @if_mutex:		Mutex used for add and remove interface id
  */
 struct iosm_wwan {
 	struct iosm_imem *ipc_imem;
 	struct iosm_netdev_priv __rcu *sub_netlist[IP_MUX_SESSION_END + 1];
 	struct device *dev;
-	struct mutex if_mutex; /* Mutex used for add and remove interface id */
 };
 
 /* Bring-up the wwan net link */
@@ -55,14 +53,11 @@ static int ipc_wwan_link_open(struct net_device *netdev)
 	struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev);
 	struct iosm_wwan *ipc_wwan = priv->ipc_wwan;
 	int if_id = priv->if_id;
-	int ret;
 
 	if (if_id < IP_MUX_SESSION_START ||
 	    if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist))
 		return -EINVAL;
 
-	mutex_lock(&ipc_wwan->if_mutex);
-
 	/* get channel id */
 	priv->ch_id = ipc_imem_sys_wwan_open(ipc_wwan->ipc_imem, if_id);
 
@@ -70,8 +65,7 @@ static int ipc_wwan_link_open(struct net_device *netdev)
 		dev_err(ipc_wwan->dev,
 			"cannot connect wwan0 & id %d to the IPC mem layer",
 			if_id);
-		ret = -ENODEV;
-		goto out;
+		return -ENODEV;
 	}
 
 	/* enable tx path, DL data may follow */
@@ -80,10 +74,7 @@ static int ipc_wwan_link_open(struct net_device *netdev)
 	dev_dbg(ipc_wwan->dev, "Channel id %d allocated to if_id %d",
 		priv->ch_id, priv->if_id);
 
-	ret = 0;
-out:
-	mutex_unlock(&ipc_wwan->if_mutex);
-	return ret;
+	return 0;
 }
 
 /* Bring-down the wwan net link */
@@ -93,11 +84,9 @@ static int ipc_wwan_link_stop(struct net_device *netdev)
 
 	netif_stop_queue(netdev);
 
-	mutex_lock(&priv->ipc_wwan->if_mutex);
 	ipc_imem_sys_wwan_close(priv->ipc_wwan->ipc_imem, priv->if_id,
 				priv->ch_id);
 	priv->ch_id = -1;
-	mutex_unlock(&priv->ipc_wwan->if_mutex);
 
 	return 0;
 }
@@ -189,26 +178,17 @@ static int ipc_wwan_newlink(void *ctxt, struct net_device *dev,
 	priv->netdev = dev;
 	priv->ipc_wwan = ipc_wwan;
 
-	mutex_lock(&ipc_wwan->if_mutex);
-	if (rcu_access_pointer(ipc_wwan->sub_netlist[if_id])) {
-		err = -EBUSY;
-		goto out_unlock;
-	}
+	if (rcu_access_pointer(ipc_wwan->sub_netlist[if_id]))
+		return -EBUSY;
 
 	err = register_netdevice(dev);
 	if (err)
-		goto out_unlock;
+		return err;
 
 	rcu_assign_pointer(ipc_wwan->sub_netlist[if_id], priv);
-	mutex_unlock(&ipc_wwan->if_mutex);
-
 	netif_device_attach(dev);
 
 	return 0;
-
-out_unlock:
-	mutex_unlock(&ipc_wwan->if_mutex);
-	return err;
 }
 
 static void ipc_wwan_dellink(void *ctxt, struct net_device *dev,
@@ -222,17 +202,12 @@ static void ipc_wwan_dellink(void *ctxt, struct net_device *dev,
 		    if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist)))
 		return;
 
-	mutex_lock(&ipc_wwan->if_mutex);
-
 	if (WARN_ON(rcu_access_pointer(ipc_wwan->sub_netlist[if_id]) != priv))
-		goto unlock;
+		return;
 
 	RCU_INIT_POINTER(ipc_wwan->sub_netlist[if_id], NULL);
 	/* unregistering includes synchronize_net() */
 	unregister_netdevice_queue(dev, head);
-
-unlock:
-	mutex_unlock(&ipc_wwan->if_mutex);
 }
 
 static const struct wwan_ops iosm_wwan_ops = {
@@ -323,12 +298,9 @@ 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;
 	}
@@ -341,7 +313,5 @@ void ipc_wwan_deinit(struct iosm_wwan *ipc_wwan)
 	/* This call will remove all child netdev(s) */
 	wwan_unregister_ops(ipc_wwan->dev);
 
-	mutex_destroy(&ipc_wwan->if_mutex);
-
 	kfree(ipc_wwan);
 }
-- 
2.17.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH net v1] net: wwan: iosm: Remove unneeded if_mutex lock
  2022-11-01  5:50 ` zhaoping.shu
@ 2022-11-03 13:34   ` Kumar, M Chetan
  -1 siblings, 0 replies; 4+ messages in thread
From: Kumar, M Chetan @ 2022-11-03 13:34 UTC (permalink / raw)
  To: zhaoping.shu, linuxwwan, loic.poulain, ryazanov.s.a, johannes,
	davem, edumazet, kuba, pabeni, matthias.bgg
  Cc: netdev, linux-kernel, linux-arm-kernel, linux-mediatek, Liu,
	Haijun, xiayu.zhang, lambert.wang

> -----Original Message-----
> From: zhaoping.shu@mediatek.com <zhaoping.shu@mediatek.com>
> Sent: Tuesday, November 1, 2022 11:21 AM
> To: Kumar, M Chetan <m.chetan.kumar@intel.com>; linuxwwan
> <linuxwwan@intel.com>; loic.poulain@linaro.org; ryazanov.s.a@gmail.com;
> johannes@sipsolutions.net; davem@davemloft.net; edumazet@google.com;
> kuba@kernel.org; pabeni@redhat.com; matthias.bgg@gmail.com
> Cc: netdev@vger.kernel.org; linux-kernel@vger.kernel.org; linux-arm-
> kernel@lists.infradead.org; linux-mediatek@lists.infradead.org; Liu, Haijun
> <haijun.liu@mediatek.com>; xiayu.zhang@mediatek.com;
> lambert.wang@mediatek.com; zhaoping.shu
> <zhaoping.shu@mediatek.com>
> Subject: [PATCH net v1] net: wwan: iosm: Remove unneeded if_mutex lock
> 
> From: "zhaoping.shu" <zhaoping.shu@mediatek.com>
> 
> These WWAN network interface operations (create/delete/open/close) are
> already protected by RTNL lock, i.e., wwan_ops.newlink(),
> wwan_ops.dellink(), net_device_ops.ndo_open() and net_device.ndo_stop()
> are called with RTNL lock held.
> Therefore, this patch removes the unnecessary if_mutex.
> 
> Signed-off-by: zhaoping.shu <zhaoping.shu@mediatek.com>

Reviewed-by: M Chetan Kumar <m.chetan.kumar@intel.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH net v1] net: wwan: iosm: Remove unneeded if_mutex lock
@ 2022-11-03 13:34   ` Kumar, M Chetan
  0 siblings, 0 replies; 4+ messages in thread
From: Kumar, M Chetan @ 2022-11-03 13:34 UTC (permalink / raw)
  To: zhaoping.shu, linuxwwan, loic.poulain, ryazanov.s.a, johannes,
	davem, edumazet, kuba, pabeni, matthias.bgg
  Cc: netdev, linux-kernel, linux-arm-kernel, linux-mediatek, Liu,
	Haijun, xiayu.zhang, lambert.wang

> -----Original Message-----
> From: zhaoping.shu@mediatek.com <zhaoping.shu@mediatek.com>
> Sent: Tuesday, November 1, 2022 11:21 AM
> To: Kumar, M Chetan <m.chetan.kumar@intel.com>; linuxwwan
> <linuxwwan@intel.com>; loic.poulain@linaro.org; ryazanov.s.a@gmail.com;
> johannes@sipsolutions.net; davem@davemloft.net; edumazet@google.com;
> kuba@kernel.org; pabeni@redhat.com; matthias.bgg@gmail.com
> Cc: netdev@vger.kernel.org; linux-kernel@vger.kernel.org; linux-arm-
> kernel@lists.infradead.org; linux-mediatek@lists.infradead.org; Liu, Haijun
> <haijun.liu@mediatek.com>; xiayu.zhang@mediatek.com;
> lambert.wang@mediatek.com; zhaoping.shu
> <zhaoping.shu@mediatek.com>
> Subject: [PATCH net v1] net: wwan: iosm: Remove unneeded if_mutex lock
> 
> From: "zhaoping.shu" <zhaoping.shu@mediatek.com>
> 
> These WWAN network interface operations (create/delete/open/close) are
> already protected by RTNL lock, i.e., wwan_ops.newlink(),
> wwan_ops.dellink(), net_device_ops.ndo_open() and net_device.ndo_stop()
> are called with RTNL lock held.
> Therefore, this patch removes the unnecessary if_mutex.
> 
> Signed-off-by: zhaoping.shu <zhaoping.shu@mediatek.com>

Reviewed-by: M Chetan Kumar <m.chetan.kumar@intel.com>


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-03 13:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01  5:50 [PATCH net v1] net: wwan: iosm: Remove unneeded if_mutex lock zhaoping.shu
2022-11-01  5:50 ` zhaoping.shu
2022-11-03 13:34 ` Kumar, M Chetan
2022-11-03 13:34   ` Kumar, M Chetan

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.