From: Niloy Meharchandani <niloymeharchandani@gmail.com>
To: Parthiban Veerasooran <parthiban.veerasooran@microchip.com>,
Christian Gromm <christian.gromm@microchip.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
Niloy Meharchandani <niloymeharchandani@gmail.com>
Subject: [PATCH] staging: most: net: use guard(mutex) for probe_disc_mt
Date: Fri, 13 Nov 2026 22:53:58 -0800 [thread overview]
Message-ID: <20261114065358.149853-1-niloymeharchandani@gmail.com> (raw)
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
next reply other threads:[~2026-11-14 6:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 6:53 Niloy Meharchandani [this message]
2026-11-20 7:16 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261114065358.149853-1-niloymeharchandani@gmail.com \
--to=niloymeharchandani@gmail.com \
--cc=christian.gromm@microchip.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=parthiban.veerasooran@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®