From: Gustavo Arantes <dev.gustavoa@gmail.com>
To: gregkh@linuxfoundation.org
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
Gustavo Arantes <dev.gustavoa@gmail.com>
Subject: [PATCH] staging: rtl8723bs: convert mutex_lock/unlock to guard and scoped_guard in rtw_pwrctrl.c
Date: Tue, 10 Mar 2026 05:48:06 -0300 [thread overview]
Message-ID: <20260310084806.34265-1-dev.gustavoa@gmail.com> (raw)
Replace simple mutex_lock()/mutex_unlock() pairs with guard(mutex)() and
scoped_guard(mutex, ...) in rtw_pwrctrl.c, simplifying the locking by
using cleanup.h guard API which automatically releases the mutex when the
variable goes out of scope, reducing risks of missing unlocks on error
paths.
Signed-off-by: Gustavo Arantes <dev.gustavoa@gmail.com>
---
drivers/staging/rtl8723bs/core/rtw_pwrctrl.c | 27 ++++++++------------
1 file changed, 10 insertions(+), 17 deletions(-)
diff --git a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
index f074ea6e0f38..d9b7956f6189 100644
--- a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c
@@ -7,6 +7,7 @@
#include <drv_types.h>
#include <hal_data.h>
#include <linux/jiffies.h>
+#include <linux/cleanup.h>
void _ips_enter(struct adapter *padapter)
{
@@ -37,9 +38,8 @@ void ips_enter(struct adapter *padapter)
hal_btcoex_IpsNotify(padapter, pwrpriv->ips_mode_req);
- mutex_lock(&pwrpriv->lock);
+ guard(mutex)(&pwrpriv->lock);
_ips_enter(padapter);
- mutex_unlock(&pwrpriv->lock);
}
int _ips_leave(struct adapter *padapter)
@@ -69,9 +69,8 @@ int ips_leave(struct adapter *padapter)
struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
int ret;
- mutex_lock(&pwrpriv->lock);
- ret = _ips_leave(padapter);
- mutex_unlock(&pwrpriv->lock);
+ scoped_guard(mutex, &pwrpriv->lock)
+ ret = _ips_leave(padapter);
if (ret == _SUCCESS)
hal_btcoex_IpsNotify(padapter, IPS_NONE);
@@ -138,9 +137,8 @@ void rtw_ps_processor(struct adapter *padapter)
struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
u32 ps_deny = 0;
- mutex_lock(&adapter_to_pwrctl(padapter)->lock);
- ps_deny = rtw_ps_deny_get(padapter);
- mutex_unlock(&adapter_to_pwrctl(padapter)->lock);
+ scoped_guard(mutex, &adapter_to_pwrctl(padapter)->lock)
+ ps_deny = rtw_ps_deny_get(padapter);
if (ps_deny != 0)
goto exit;
@@ -494,11 +492,8 @@ void LeaveAllPowerSaveModeDirect(struct adapter *Adapter)
if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
return;
- mutex_lock(&pwrpriv->lock);
-
- rtw_set_rpwm(Adapter, PS_STATE_S4);
-
- mutex_unlock(&pwrpriv->lock);
+ scoped_guard(mutex, &pwrpriv->lock)
+ rtw_set_rpwm(Adapter, PS_STATE_S4);
rtw_lps_ctrl_wk_cmd(pri_padapter, LPS_CTRL_LEAVE, 0);
} else {
@@ -1114,9 +1109,8 @@ void rtw_ps_deny(struct adapter *padapter, enum ps_deny_reason reason)
pwrpriv = adapter_to_pwrctl(padapter);
- mutex_lock(&pwrpriv->lock);
+ guard(mutex)(&pwrpriv->lock);
pwrpriv->ps_deny |= BIT(reason);
- mutex_unlock(&pwrpriv->lock);
}
/*
@@ -1129,9 +1123,8 @@ void rtw_ps_deny_cancel(struct adapter *padapter, enum ps_deny_reason reason)
pwrpriv = adapter_to_pwrctl(padapter);
- mutex_lock(&pwrpriv->lock);
+ guard(mutex)(&pwrpriv->lock);
pwrpriv->ps_deny &= ~BIT(reason);
- mutex_unlock(&pwrpriv->lock);
}
/*
--
2.53.0
next reply other threads:[~2026-03-10 8:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 8:48 Gustavo Arantes [this message]
2026-03-10 9:02 ` [PATCH] staging: rtl8723bs: convert mutex_lock/unlock to guard and scoped_guard in rtw_pwrctrl.c Greg KH
2026-03-10 9:09 ` Gustavo Arantes
2026-03-10 9:25 ` Dan Carpenter
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=20260310084806.34265-1-dev.gustavoa@gmail.com \
--to=dev.gustavoa@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/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