Skip to contentSkip to conversation

staging: rtl8723bs: use guard(mutex) in ips_enter()

PATCH In review Ivy Lopez 2 participants 4 messages Jul 30 – Jul 31 Staging

lore
Share & tools
lore

Ivy Lopez

author
#0 lore raw

PATCH 1/1 staging: rtl8723bs: use guard(mutex) in ips_enter()

Replace manual mutex_lock()/mutex_unlock() in ips_enter() with guard(mutex) from linux/cleanup.h. This is a single-exit function so the conversion is a direct drop-in and removes the need to manually balance the unlock.

---
 drivers/staging/rtl8723bs/core/rtw_pwrctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_pwrctrl.c +2 -2
index b9f8cf1014ed..141c322befb6 100644
@@ -6,6 +6,7 @@
  ******************************************************************************/
 #include <drv_types.h>
 #include <hal_data.h>
+#include <linux/cleanup.h>
 #include <linux/jiffies.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)
Signature · 1 line
2.55.0
author
#1 lore raw

PATCH 1/1 staging: rtl8723bs: use kfree_sensitive() for key material in rtw_set_key()

psetkeyparm holds WEP/TKIP/AES key material copied in via memcpy from psecuritypriv before being freed. Use kfree_sensitive() instead of kfree() so the key bytes are zeroed before the memory is released, consistent with how psetstakey_para is already handled elsewhere in this driver.

---
 drivers/staging/rtl8723bs/core/rtw_mlme.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme.c +3 -3
index 1196ec011455..fb45f7295386 100644
@@ -1926,14 +1926,14 @@ signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecurityp
 		break;
 	default:
 		res = _FAIL;
-		kfree(psetkeyparm);
+		kfree_sensitive(psetkeyparm);
 		goto exit;
 	}
 
 	if (enqueue) {
 		pcmd = kzalloc_obj(*pcmd);
 		if (!pcmd) {
-			kfree(psetkeyparm);
+			kfree_sensitive(psetkeyparm);
 			res = _FAIL;  /* try again */
 			goto exit;
 		}
@@ -1949,7 +1949,7 @@ signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecurityp
 		res = rtw_enqueue_cmd(pcmdpriv, pcmd);
 	} else {
 		setkey_hdl(adapter, (u8 *)psetkeyparm);
-		kfree(psetkeyparm);
+		kfree_sensitive(psetkeyparm);
 	}
 exit:
 	return res;
Signature · 1 line
2.55.0
#3 lore raw
In reply to Ivy Lopez
Quoted 4 lines · Ivy Lopez

Replace manual mutex_lock()/mutex_unlock() in ips_enter() with guard(mutex) from linux/cleanup.h. This is a single-exit function so the conversion is a direct drop-in and removes the need to manually balance the unlock.

Yes, but as stated before, that's great for new code, but for existing code that is not broken, you should just leave it alone and not convert to using guard().

thanks,

greg k-h