Linux kernel staging patches
 help / color / mirror / Atom feed
* [PATCH] staging: most: net: use guard(mutex) for probe_disc_mt
@ 2026-11-14  6:53 Niloy Meharchandani
  2026-11-20  7:16 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Niloy Meharchandani @ 2026-11-14  6:53 UTC (permalink / raw)
  To: Parthiban Veerasooran, Christian Gromm, Greg Kroah-Hartman
  Cc: linux-staging, linux-kernel, Niloy Meharchandani

Replace manual mutex_lock() and mutex_unlock() calls on probe_disc_mt
with guard(mutex)(&probe_disc_mt) in most_nd_open(), comp_probe_channel(),
and comp_disconnect_channel(). Include <linux/cleanup.h> and
<linux/mutex.h> explicitly.

This simplifies error paths by removing the unlock goto labels and
temporary return variables while ensuring the mutex is always released
on scope exit.

No functional change intended. Compile-tested only.

Signed-off-by: Niloy Meharchandani <niloymeharchandani@gmail.com>
---
 drivers/staging/most/net/net.c | 57 ++++++++++++----------------------
 1 file changed, 20 insertions(+), 37 deletions(-)

diff --git a/drivers/staging/most/net/net.c b/drivers/staging/most/net/net.c
index e6e4498d33ab..e08804c8ec6e 100644
--- a/drivers/staging/most/net/net.c
+++ b/drivers/staging/most/net/net.c
@@ -13,7 +13,9 @@
 #include <linux/init.h>
 #include <linux/list.h>
 #include <linux/wait.h>
+#include <linux/cleanup.h>
 #include <linux/kobject.h>
+#include <linux/mutex.h>
 #include <linux/most.h>
 
 #define MEP_HDR_LEN 8
@@ -175,21 +177,18 @@ static void on_netinfo(struct most_interface *iface,
 static int most_nd_open(struct net_device *dev)
 {
 	struct net_dev_context *nd = netdev_priv(dev);
-	int ret = 0;
 
-	mutex_lock(&probe_disc_mt);
+	guard(mutex)(&probe_disc_mt);
 
 	if (most_start_channel(nd->iface, nd->rx.ch_id, &comp)) {
 		netdev_err(dev, "most_start_channel() failed\n");
-		ret = -EBUSY;
-		goto unlock;
+		return -EBUSY;
 	}
 
 	if (most_start_channel(nd->iface, nd->tx.ch_id, &comp)) {
 		netdev_err(dev, "most_start_channel() failed\n");
 		most_stop_channel(nd->iface, nd->rx.ch_id, &comp);
-		ret = -EBUSY;
-		goto unlock;
+		return -EBUSY;
 	}
 
 	netif_carrier_off(dev);
@@ -201,9 +200,7 @@ static int most_nd_open(struct net_device *dev)
 	if (nd->iface->request_netinfo)
 		nd->iface->request_netinfo(nd->iface, nd->tx.ch_id, on_netinfo);
 
-unlock:
-	mutex_unlock(&probe_disc_mt);
-	return ret;
+	return 0;
 }
 
 static int most_nd_stop(struct net_device *dev)
@@ -299,7 +296,6 @@ static int comp_probe_channel(struct most_interface *iface, int channel_idx,
 	struct net_dev_channel *ch;
 	struct net_device *dev;
 	unsigned long flags;
-	int ret = 0;
 
 	if (!iface)
 		return -EINVAL;
@@ -307,15 +303,13 @@ static int comp_probe_channel(struct most_interface *iface, int channel_idx,
 	if (ccfg->data_type != MOST_CH_ASYNC)
 		return -EINVAL;
 
-	mutex_lock(&probe_disc_mt);
+	guard(mutex)(&probe_disc_mt);
 	nd = get_net_dev(iface);
 	if (!nd) {
 		dev = alloc_netdev(sizeof(struct net_dev_context), "meth%d",
 				   NET_NAME_UNKNOWN, most_nd_setup);
-		if (!dev) {
-			ret = -ENOMEM;
-			goto unlock;
-		}
+		if (!dev)
+			return -ENOMEM;
 
 		nd = netdev_priv(dev);
 		nd->iface = iface;
@@ -330,22 +324,18 @@ static int comp_probe_channel(struct most_interface *iface, int channel_idx,
 		ch = ccfg->direction == MOST_CH_TX ? &nd->tx : &nd->rx;
 		if (ch->linked) {
 			netdev_err(nd->dev, "direction is allocated\n");
-			ret = -EINVAL;
-			goto unlock;
+			return -EINVAL;
 		}
 
 		if (register_netdev(nd->dev)) {
 			netdev_err(nd->dev, "register_netdev() failed\n");
-			ret = -EINVAL;
-			goto unlock;
+			return -EINVAL;
 		}
 	}
 	ch->ch_id = channel_idx;
 	ch->linked = true;
 
-unlock:
-	mutex_unlock(&probe_disc_mt);
-	return ret;
+	return 0;
 }
 
 static int comp_disconnect_channel(struct most_interface *iface,
@@ -354,23 +344,18 @@ static int comp_disconnect_channel(struct most_interface *iface,
 	struct net_dev_context *nd;
 	struct net_dev_channel *ch;
 	unsigned long flags;
-	int ret = 0;
 
-	mutex_lock(&probe_disc_mt);
+	guard(mutex)(&probe_disc_mt);
 	nd = get_net_dev(iface);
-	if (!nd) {
-		ret = -EINVAL;
-		goto unlock;
-	}
+	if (!nd)
+		return -EINVAL;
 
-	if (nd->rx.linked && channel_idx == nd->rx.ch_id) {
+	if (nd->rx.linked && channel_idx == nd->rx.ch_id)
 		ch = &nd->rx;
-	} else if (nd->tx.linked && channel_idx == nd->tx.ch_id) {
+	else if (nd->tx.linked && channel_idx == nd->tx.ch_id)
 		ch = &nd->tx;
-	} else {
-		ret = -EINVAL;
-		goto unlock;
-	}
+	else
+		return -EINVAL;
 
 	if (nd->rx.linked && nd->tx.linked) {
 		spin_lock_irqsave(&list_lock, flags);
@@ -390,9 +375,7 @@ static int comp_disconnect_channel(struct most_interface *iface,
 		free_netdev(nd->dev);
 	}
 
-unlock:
-	mutex_unlock(&probe_disc_mt);
-	return ret;
+	return 0;
 }
 
 static int comp_resume_tx_channel(struct most_interface *iface,
-- 
2.53.0


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

end of thread, other threads:[~2026-11-20  7:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14  6:53 [PATCH] staging: most: net: use guard(mutex) for probe_disc_mt Niloy Meharchandani
2026-11-20  7:16 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox