staging: rtl8723bs: convert mutex_lock/unlock to guard and scoped_guard in rtw_pwrctrl.c
PATCH 1/1 staging: rtl8723bs: convert mutex_lock/unlock to guard and scoped_guard in rtw_pwrctrl.c
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.
--- drivers/staging/rtl8723bs/core/rtw_pwrctrl.c | 27 ++++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-)
drivers/staging/rtl8723bs/core/rtw_pwrctrl.c +10 -17
@@ -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); }/*
Signature · 1 line
2.53.0
Greg KH
maintainerQuoted 7 lines · Gustavo Arantes
Replace simple mutex_lock()/mutex_unlock() pairs with guard(mutex)() and
scoped_guard(mutex, ...)inrtw_pwrctrl.c, simplifying the locking by usingcleanup.hguard 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 <[email protected]>
Let's not convert existing code to use guard(), but rather use it for newer code submitted to the kernel.
thanks,
greg k-h
Quoted 2 lines · Greg KH
Let's not convert existing code to use
guard(), but rather use it for newer code submitted to the kernel.
Understood, thanks for the feedback.
Gustavo
Quoted 8 lines · Gustavo Arantes
Replace simple mutex_lock()/mutex_unlock() pairs with guard(mutex)() and
scoped_guard(mutex, ...)inrtw_pwrctrl.c, simplifying the locking by usingcleanup.hguard 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 <[email protected]>---
We're only doing these conversions for new code or when we're fixing bugs.
regards,
dan carpenter