Skip to contentSkip to conversation

Issue suggested by Coccinelle using ret.cocci

PATCH New Madhumitha Prabakaran 1 participant 5 messages Mar 18, 2019 Staging

lore
Share & tools
lore
#0 lore raw

v3 cover Issue suggested by Coccinelle using ret.cocci

This patchset does tasks as below:
1) Remove unnecessary local variable in function
2) Change values to standard error codes in functions
3) Replace NULL comparison with !
4) Add missing NULL check for kmalloc

All these patches are relevant to an issue suggested by Coccinelle using ret.cocci.

Madhumitha Prabakaran (4):
Staging: rtl8723bs: Remove unnecessary local variable in function
Staging: rtl8723bs: Change values to standard error codes in functions
Staging: rtl8723bs: Replace NULL comparison with !
Staging: rtl8723bs: Add missing NULL check for kmalloc

Changes in v3-
1) Added one more patch
2) Splitted the changes in two patches
3) Modified a code in patch 2 and changed a commit log

 drivers/staging/rtl8723bs/core/rtw_cmd.c    | 16 ++++++++--------
 drivers/staging/rtl8723bs/os_dep/os_intfs.c |  4 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/4 Staging: rtl8723bs: Remove unnecessary local variable in function

Remove unnecessary local variable 'res' in function and replace the value directly in the return of the function.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +1 -3
index 9edd9a24756a..b67a5f9c27fa 100644
@@ -203,8 +203,6 @@ int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 static void c2h_wk_callback(_workitem *work);
 int rtw_init_evt_priv(struct evt_priv *pevtpriv)
 {
-	int res = _SUCCESS;
-
 	/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
 	atomic_set(&pevtpriv->event_seq, 0);
 	pevtpriv->evt_done_cnt = 0;
@@ -213,7 +211,7 @@ int rtw_init_evt_priv(struct evt_priv *pevtpriv)
 	pevtpriv->c2h_wk_alive = false;
 	pevtpriv->c2h_queue = rtw_cbuf_alloc(C2H_QUEUE_MAX_LEN+1);
 
-	return res;
+	return 0;
 }
 
 void _rtw_free_evt_priv(struct	evt_priv *pevtpriv)
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 2/4 Staging: rtl8723bs: Change values to standard error codes in functions

In reply to Madhumitha Prabakaran

Change values for standard error codes in functions rtw_init_cmd_priv and rtw_init_evt_priv, as _SUCCESS should be 0 and _FAIL should be -ENOMEM. Also, change the values in corresponding call sites of the functions.

---
Changes in v3:
Change the commit log and function callsites

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c    | 6 +++---
 drivers/staging/rtl8723bs/os_dep/os_intfs.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +3 -3
index b67a5f9c27fa..32d8ff9e41bd 100644
@@ -164,7 +164,7 @@ No irqsave is necessary.
 
 int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 {
-	int res = _SUCCESS;
+	int res = 0;
 
 	init_completion(&pcmdpriv->cmd_queue_comp);
 	init_completion(&pcmdpriv->terminate_cmdthread_comp);
@@ -178,7 +178,7 @@ int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 	pcmdpriv->cmd_allocated_buf = rtw_zmalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ);
 
 	if (pcmdpriv->cmd_allocated_buf == NULL) {
-		res = _FAIL;
+		res = -ENOMEM;
 		goto exit;
 	}
 
@@ -187,7 +187,7 @@ int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 	pcmdpriv->rsp_allocated_buf = rtw_zmalloc(MAX_RSPSZ + 4);
 
 	if (pcmdpriv->rsp_allocated_buf == NULL) {
-		res = _FAIL;
+		res = -ENOMEM;
 		goto exit;
 	}
 
drivers/staging/rtl8723bs/os_dep/os_intfs.c +2 -2
index 5c0fbf5170cc..9021bf519605 100644
@@ -754,7 +754,7 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
 
 	rtw_init_hal_com_default_value(padapter);
 
-	if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == _FAIL) {
+	if (rtw_init_cmd_priv(&padapter->cmdpriv)) {
 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init cmd_priv\n"));
 		ret8 = _FAIL;
 		goto exit;
@@ -762,7 +762,7 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
 
 	padapter->cmdpriv.padapter = padapter;
 
-	if ((rtw_init_evt_priv(&padapter->evtpriv)) == _FAIL) {
+	if (rtw_init_evt_priv(&padapter->evtpriv)) {
 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init evt_priv\n"));
 		ret8 = _FAIL;
 		goto exit;
Signature · 1 line
2.17.1
#3 lore raw

PATCH v3 3/4 Staging: rtl8723bs: Replace NULL comparison with !

In reply to Madhumitha Prabakaran

Replace NULL comparison with ! in function rtw_init_cmd_priv, to maintain Linux kernel coding style.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +2 -2
index 32d8ff9e41bd..9edd0dda3c06 100644
@@ -177,7 +177,7 @@ int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 
 	pcmdpriv->cmd_allocated_buf = rtw_zmalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ);
 
-	if (pcmdpriv->cmd_allocated_buf == NULL) {
+	if (!pcmdpriv->cmd_allocated_buf) {
 		res = -ENOMEM;
 		goto exit;
 	}
@@ -186,7 +186,7 @@ int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 
 	pcmdpriv->rsp_allocated_buf = rtw_zmalloc(MAX_RSPSZ + 4);
 
-	if (pcmdpriv->rsp_allocated_buf == NULL) {
+	if (!pcmdpriv->rsp_allocated_buf) {
 		res = -ENOMEM;
 		goto exit;
 	}
Signature · 1 line
2.17.1
#4 lore raw

PATCH v3 4/4 Staging: rtl8723bs: Add missing NULL check for kmalloc

In reply to Madhumitha Prabakaran

Include missing NULL check for kmalloc in function rtw_init_evt_priv.

---
Change in v3-

Split changes into two different patches in a series.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/rtl8723bs/core/rtw_cmd.c +2 -0
index 9edd0dda3c06..bd3a5a23a418 100644
@@ -210,6 +210,8 @@ int rtw_init_evt_priv(struct evt_priv *pevtpriv)
 	_init_workitem(&pevtpriv->c2h_wk, c2h_wk_callback, NULL);
 	pevtpriv->c2h_wk_alive = false;
 	pevtpriv->c2h_queue = rtw_cbuf_alloc(C2H_QUEUE_MAX_LEN+1);
+	if (!pevtpriv->c2h_queue)
+		return -ENOMEM;
 
 	return 0;
 }
Signature · 1 line
2.17.1