Skip to contentSkip to conversation

Issue suggested by Coccinelle using ret.cocci

PATCH Superseded Madhumitha Prabakaran 3 participants 16 messages Mar 17, 2019 – Mar 18, 2019 1 message not in the archive Staging

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Issue suggested by Coccinelle using ret.cocci

This patchset does tasks as below:
1) Drop wrapper functions and change function names
2) Change type of variables and return type
3) Change values to standard error codes in functions
4) Replace NULL comparison with !
5) Add missing NULL check for kmalloc

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

Madhumitha Prabakaran (5):
Staging: rtl8723bs: Remove wrapper functions and change function names
Staging: rtl8723bs: Change type of variables and return type
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 v2 -

1) Modified commit log here
2) Dropped patch 4,5,6
3) Included patch 4 for replace NULL comparison with !
4) Merged patch 4 in patch 1, which is to remove unwanted function declarations.
5) Merged patch 5 with patch 3, which is to replace error codes in functions.
6) Merged patch 6 with patch 1, which is to remove extern and change return type
7) Removed unnecessary local variable res in function rtw_init_evt_priv

 drivers/staging/rtl8723bs/core/rtw_cmd.c      | 37 ++++++-------------
 drivers/staging/rtl8723bs/include/cmd_osdep.h |  4 +-
 drivers/staging/rtl8723bs/include/rtw_cmd.h   |  2 -
 drivers/staging/rtl8723bs/os_dep/os_intfs.c   |  4 +-
 4 files changed, 15 insertions(+), 32 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/5 Staging: rtl8723bs: Remove wrapper functions and change function names

Drop wrappers rtw_init_cmd_priv and rtw_init_evt_priv and remove their function declarations, as their only purpose is to call other functions. Change function names from _rtw_init_cmd_priv to rtw_init_cmd_priv, and _rtw_init_evt_priv to rtw_init_evt_priv in function definitions and function declarations. Also, remove externs in function declarations rtw_init_cmd_priv and rtw_init_evt_priv, to maintain Linux kernel coding style.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c      | 20 ++-----------------
 drivers/staging/rtl8723bs/include/cmd_osdep.h |  4 ++--
 drivers/staging/rtl8723bs/include/rtw_cmd.h   |  2 --
 3 files changed, 4 insertions(+), 22 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +2 -18
index 91520ca3bbad..793bc505fa9c 100644
@@ -162,7 +162,7 @@ Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
 No irqsave is necessary.
 */
 
-sint	_rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
+sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 {
 	sint res = _SUCCESS;
 
@@ -201,7 +201,7 @@ sint	_rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 }
 
 static void c2h_wk_callback(_workitem *work);
-sint _rtw_init_evt_priv(struct evt_priv *pevtpriv)
+sint rtw_init_evt_priv(struct evt_priv *pevtpriv)
 {
 	sint res = _SUCCESS;
 
@@ -295,22 +295,6 @@ struct	cmd_obj	*_rtw_dequeue_cmd(struct __queue *queue)
 	return obj;
 }
 
-u32 rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
-{
-	u32 res;
-
-	res = _rtw_init_cmd_priv(pcmdpriv);
-	return res;
-}
-
-u32 rtw_init_evt_priv(struct	evt_priv *pevtpriv)
-{
-	int	res;
-
-	res = _rtw_init_evt_priv(pevtpriv);
-	return res;
-}
-
 void rtw_free_evt_priv(struct	evt_priv *pevtpriv)
 {
 	RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("rtw_free_evt_priv\n"));
drivers/staging/rtl8723bs/include/cmd_osdep.h +2 -2
index 0749936df032..8ed913726d5a 100644
@@ -8,8 +8,8 @@
 #define __CMD_OSDEP_H_
 
 
-extern sint _rtw_init_cmd_priv (struct	cmd_priv *pcmdpriv);
-extern sint _rtw_init_evt_priv(struct evt_priv *pevtpriv);
+sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv);
+sint rtw_init_evt_priv(struct evt_priv *pevtpriv);
 extern void _rtw_free_evt_priv (struct	evt_priv *pevtpriv);
 extern void _rtw_free_cmd_priv (struct	cmd_priv *pcmdpriv);
 extern sint _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj);
drivers/staging/rtl8723bs/include/rtw_cmd.h +0 -2
index 299b55538788..fa4ebc3d7539 100644
@@ -129,10 +129,8 @@ extern void rtw_free_cmd_obj(struct cmd_obj *pcmd);
 void rtw_stop_cmd_thread(struct adapter *adapter);
 int rtw_cmd_thread(void *context);
 
-extern u32 rtw_init_cmd_priv (struct cmd_priv *pcmdpriv);
 extern void rtw_free_cmd_priv (struct cmd_priv *pcmdpriv);
 
-extern u32 rtw_init_evt_priv (struct evt_priv *pevtpriv);
 extern void rtw_free_evt_priv (struct evt_priv *pevtpriv);
 extern void rtw_evt_notify_isr(struct evt_priv *pevtpriv);
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/5 Staging: rtl8723bs: Change type of variables and return type

In reply to Madhumitha Prabakaran

Change type of local variables 'res' and return type of functions 'rtw_init_cmd_pri' and 'rtw_init_evt_priv', as function's return types are defined for standard error codes _SUCCESS and _FAIL. Also, change return type of functions declarations corresponding to change made in function definitions.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c      | 8 ++++----
 drivers/staging/rtl8723bs/include/cmd_osdep.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index 793bc505fa9c..ab450f717f34 100644
@@ -162,9 +162,9 @@ Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
 No irqsave is necessary.
 */
 
-sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
+int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 {
-	sint res = _SUCCESS;
+	int res = _SUCCESS;
 
 	init_completion(&pcmdpriv->cmd_queue_comp);
 	init_completion(&pcmdpriv->terminate_cmdthread_comp);
@@ -201,9 +201,9 @@ sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 }
 
 static void c2h_wk_callback(_workitem *work);
-sint rtw_init_evt_priv(struct evt_priv *pevtpriv)
+int rtw_init_evt_priv(struct evt_priv *pevtpriv)
 {
-	sint res = _SUCCESS;
+	int res = _SUCCESS;
 
 	/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
 	atomic_set(&pevtpriv->event_seq, 0);
drivers/staging/rtl8723bs/include/cmd_osdep.h +2 -2
index 8ed913726d5a..06ab48263757 100644
@@ -8,8 +8,8 @@
 #define __CMD_OSDEP_H_
 
 
-sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv);
-sint rtw_init_evt_priv(struct evt_priv *pevtpriv);
+int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv);
+int rtw_init_evt_priv(struct evt_priv *pevtpriv);
 extern void _rtw_free_evt_priv (struct	evt_priv *pevtpriv);
 extern void _rtw_free_cmd_priv (struct	cmd_priv *pcmdpriv);
 extern sint _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj);
Signature · 1 line
2.17.1
#3 lore raw

Re: [Outreachy kernel] [PATCH v2 2/5] Staging: rtl8723bs: Change type of variables and return type

Quoted 3 lines · Madhumitha Prabakaran

Change type of local variables 'res' and return type of functions 'rtw_init_cmd_pri' and 'rtw_init_evt_priv', as function's return types are defined for standard error codes _SUCCESS and _FAIL.

I'm not sure to undestand the reference to _SUCCESS and _FAIL. sint is a typedef for signed int, but kernel code typically uses just int rather than signed int. In any case, the change doesn't have any impact on the types in the code.

julia

Quoted 62 lines

Also, change return type of functions declarations corresponding to change made in function definitions.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c      | 8 ++++----
 drivers/staging/rtl8723bs/include/cmd_osdep.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index 793bc505fa9c..ab450f717f34 100644
@@ -162,9 +162,9 @@ Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
 No irqsave is necessary.
 */
 
-sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
+int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 {
-	sint res = _SUCCESS;
+	int res = _SUCCESS;
 
 	init_completion(&pcmdpriv->cmd_queue_comp);
 	init_completion(&pcmdpriv->terminate_cmdthread_comp);
@@ -201,9 +201,9 @@ sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 }
 
 static void c2h_wk_callback(_workitem *work);
-sint rtw_init_evt_priv(struct evt_priv *pevtpriv)
+int rtw_init_evt_priv(struct evt_priv *pevtpriv)
 {
-	sint res = _SUCCESS;
+	int res = _SUCCESS;
 
 	/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
 	atomic_set(&pevtpriv->event_seq, 0);
drivers/staging/rtl8723bs/include/cmd_osdep.h +2 -3
index 8ed913726d5a..06ab48263757 100644
@@ -8,8 +8,8 @@
 #define __CMD_OSDEP_H_
 
 
-sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv);
-sint rtw_init_evt_priv(struct evt_priv *pevtpriv);
+int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv);
+int rtw_init_evt_priv(struct evt_priv *pevtpriv);
 extern void _rtw_free_evt_priv (struct	evt_priv *pevtpriv);
 extern void _rtw_free_cmd_priv (struct	cmd_priv *pcmdpriv);
 extern sint _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj);
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/cce081516153acd64194786cb1373150172d73cf.1552858206.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#4 lore raw

Re: [Outreachy kernel] [PATCH v2 2/5] Staging: rtl8723bs: Change type of variables and return type

Quoted 4 lines · Julia Lawall

On Sun, 17 Mar 2019, Madhumitha Prabakaran wrote:

Quoted 8 lines
Quoted 3 lines

Change type of local variables 'res' and return type of functions 'rtw_init_cmd_pri' and 'rtw_init_evt_priv', as function's return types are defined for standard error codes _SUCCESS and _FAIL.

I'm not sure to undestand the reference to _SUCCESS and _FAIL. sint is a typedef for signed int, but kernel code typically uses just int rather than signed int. In any case, the change doesn't have any impact on the types in the code.

That's true. Should I drop this patch?

thanks

Quoted 72 lines

julia

Quoted 62 lines

Also, change return type of functions declarations corresponding to change made in function definitions.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c      | 8 ++++----
 drivers/staging/rtl8723bs/include/cmd_osdep.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index 793bc505fa9c..ab450f717f34 100644
@@ -162,9 +162,9 @@ Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
 No irqsave is necessary.
 */
 
-sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
+int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 {
-	sint res = _SUCCESS;
+	int res = _SUCCESS;
 
 	init_completion(&pcmdpriv->cmd_queue_comp);
 	init_completion(&pcmdpriv->terminate_cmdthread_comp);
@@ -201,9 +201,9 @@ sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 }
 
 static void c2h_wk_callback(_workitem *work);
-sint rtw_init_evt_priv(struct evt_priv *pevtpriv)
+int rtw_init_evt_priv(struct evt_priv *pevtpriv)
 {
-	sint res = _SUCCESS;
+	int res = _SUCCESS;
 
 	/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
 	atomic_set(&pevtpriv->event_seq, 0);
drivers/staging/rtl8723bs/include/cmd_osdep.h +2 -3
index 8ed913726d5a..06ab48263757 100644
@@ -8,8 +8,8 @@
 #define __CMD_OSDEP_H_
 
 
-sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv);
-sint rtw_init_evt_priv(struct evt_priv *pevtpriv);
+int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv);
+int rtw_init_evt_priv(struct evt_priv *pevtpriv);
 extern void _rtw_free_evt_priv (struct	evt_priv *pevtpriv);
 extern void _rtw_free_cmd_priv (struct	cmd_priv *pcmdpriv);
 extern sint _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj);
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/cce081516153acd64194786cb1373150172d73cf.1552858206.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Signature · 5 lines
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1903172250420.2434%40hadrien.
For more options, visit https://groups.google.com/d/optout.
#5 lore raw

Re: [Outreachy kernel] [PATCH v2 2/5] Staging: rtl8723bs: Change type of variables and return type

Quoted 9 lines · Madhumthia Prabakaran
Quoted 8 lines · Julia Lawall
Quoted 3 lines · Madhumitha Prabakaran

Change type of local variables 'res' and return type of functions 'rtw_init_cmd_pri' and 'rtw_init_evt_priv', as function's return types are defined for standard error codes _SUCCESS and _FAIL.

Quoted 6 lines
Quoted 4 lines

I'm not sure to undestand the reference to _SUCCESS and _FAIL. sint is a typedef for signed int, but kernel code typically uses just int rather than signed int. In any case, the change doesn't have any impact on the types in the code.

That's true. Should I drop this patch?

No, no, the patch is good,and I think Greg may have already accepted it. The comment was just about the log message.

julia

Quoted 83 lines

thanks

Quoted 58 lines

julia

Quoted 55 lines

Also, change return type of functions declarations corresponding to change made in function definitions.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c      | 8 ++++----
 drivers/staging/rtl8723bs/include/cmd_osdep.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index 793bc505fa9c..ab450f717f34 100644
@@ -162,9 +162,9 @@ Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
 No irqsave is necessary.
 */
 
-sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
+int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 {
-	sint res = _SUCCESS;
+	int res = _SUCCESS;
 
 	init_completion(&pcmdpriv->cmd_queue_comp);
 	init_completion(&pcmdpriv->terminate_cmdthread_comp);
@@ -201,9 +201,9 @@ sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv)
 }
 
 static void c2h_wk_callback(_workitem *work);
-sint rtw_init_evt_priv(struct evt_priv *pevtpriv)
+int rtw_init_evt_priv(struct evt_priv *pevtpriv)
 {
-	sint res = _SUCCESS;
+	int res = _SUCCESS;
 
 	/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
 	atomic_set(&pevtpriv->event_seq, 0);
drivers/staging/rtl8723bs/include/cmd_osdep.h +2 -3
index 8ed913726d5a..06ab48263757 100644
@@ -8,8 +8,8 @@
 #define __CMD_OSDEP_H_
 
 
-sint rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv);
-sint rtw_init_evt_priv(struct evt_priv *pevtpriv);
+int rtw_init_cmd_priv(struct	cmd_priv *pcmdpriv);
+int rtw_init_evt_priv(struct evt_priv *pevtpriv);
 extern void _rtw_free_evt_priv (struct	evt_priv *pevtpriv);
 extern void _rtw_free_cmd_priv (struct	cmd_priv *pcmdpriv);
 extern sint _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj);
--

2.17.1

Quoted 14 lines
Quoted 7 lines

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/cce081516153acd64194786cb1373150172d73cf.1552858206.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1903172250420.2434%40hadrien.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20190317233426.GA4222%40madhuleo.
For more options, visit https://groups.google.com/d/optout.

#6 lore raw

PATCH v2 3/5 Staging: rtl8723bs: Change values to standard error codes in functions

In reply to Madhumitha Prabakaran

Change values to stand error codes in functions rtw_init_cmd_priv and rtw_init_evt_priv, as _SUCCESS should be 0 and _FAIL should be -ENOMEM (as in this case, these are memory allocating functions). Also, change the values in corresponding call sites of the functions.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c    | 8 ++++----
 drivers/staging/rtl8723bs/os_dep/os_intfs.c | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index ab450f717f34..f8a4f910bfea 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;
 	}
 
@@ -203,7 +203,7 @@ 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;
+	int res = 0;
 
 	/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
 	atomic_set(&pevtpriv->event_seq, 0);
drivers/staging/rtl8723bs/os_dep/os_intfs.c +2 -2
index 143e3f9b31aa..6b3def0397f0 100644
@@ -757,7 +757,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)) == -ENOMEM) {
 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init cmd_priv\n"));
 		ret8 = _FAIL;
 		goto exit;
@@ -765,7 +765,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)) == -ENOMEM) {
 		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

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.21.1903172253010.2434@hadrien

#8 lore raw

Re: [Outreachy kernel] [PATCH v2 3/5] Staging: rtl8723bs: Change values to standard error codes in functions

Quoted 11 lines · Julia Lawall
Quoted 3 lines · Madhumitha Prabakaran

Change values to stand error codes in functions rtw_init_cmd_priv and rtw_init_evt_priv, as _SUCCESS should be 0 and _FAIL should be -ENOMEM (as in this case, these are memory allocating functions).

You don't have to change it, but the above is a really long sentence.

julia

I will fix this commit log, as I made a mistake in mentioning "stand error code".

Quoted 82 lines
Quoted 82 lines

Also, change
the values in corresponding call sites of the functions.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c    | 8 ++++----
 drivers/staging/rtl8723bs/os_dep/os_intfs.c | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index ab450f717f34..f8a4f910bfea 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;
 	}
 
@@ -203,7 +203,7 @@ 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;
+	int res = 0;
 
 	/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
 	atomic_set(&pevtpriv->event_seq, 0);
drivers/staging/rtl8723bs/os_dep/os_intfs.c +2 -3
index 143e3f9b31aa..6b3def0397f0 100644
@@ -757,7 +757,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)) == -ENOMEM) {
 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init cmd_priv\n"));
 		ret8 = _FAIL;
 		goto exit;
@@ -765,7 +765,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)) == -ENOMEM) {
 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init evt_priv\n"));
 		ret8 = _FAIL;
 		goto exit;
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/3079e4485a34348cdaed25939551424267ee32f6.1552858206.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#9 lore raw

Re: [Outreachy kernel] [PATCH v2 3/5] Staging: rtl8723bs: Change values to standard error codes in functions

Quoted 11 lines
Quoted 11 lines

drivers/staging/rtl8723bs/os_dep/os_intfs.c u8 rtw_init_drv_sw(struct adapter *padapter) · line 768

Quoted 11 lines
drivers/staging/rtl8723bs/os_dep/os_intfs.c +2 -2
-	if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == _FAIL) {
+	if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == -ENOMEM) {
 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init cmd_priv\n"));
 		ret8 = _FAIL;
 		goto exit;
@@ -765,7 +765,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)) == -ENOMEM) {

In addition to Greg's comment on this code, there are too many parentheses as well.

julia

maintainer
#10 lore raw

Re: [PATCH v2 3/5] Staging: rtl8723bs: Change values to standard error codes in functions

In reply to Madhumitha Prabakaran
Quoted 56 lines · Madhumitha Prabakaran

Change values to stand error codes in functions rtw_init_cmd_priv and rtw_init_evt_priv, as _SUCCESS should be 0 and _FAIL should be -ENOMEM (as in this case, these are memory allocating functions). Also, change the values in corresponding call sites of the functions.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c    | 8 ++++----
 drivers/staging/rtl8723bs/os_dep/os_intfs.c | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index ab450f717f34..f8a4f910bfea 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;
 	}
 
@@ -203,7 +203,7 @@ 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;
+	int res = 0;
 
 	/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */
 	atomic_set(&pevtpriv->event_seq, 0);
drivers/staging/rtl8723bs/os_dep/os_intfs.c +0 -0
index 143e3f9b31aa..6b3def0397f0 100644

drivers/staging/rtl8723bs/os_dep/os_intfs.c u8 rtw_init_drv_sw(struct adapter *padapter) · line 760

Quoted 5 lines
drivers/staging/rtl8723bs/os_dep/os_intfs.c +1 -1
@@ -757,7 +757,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)) == -ENOMEM) {

No need to check for a specific error value, just _any_ error value.

drivers/staging/rtl8723bs/os_dep/os_intfs.c u8 rtw_init_drv_sw(struct adapter *padapter) · line 768

Quoted 9 lines
drivers/staging/rtl8723bs/os_dep/os_intfs.c +1 -1
 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init cmd_priv\n"));
 		ret8 = _FAIL;
 		goto exit;
@@ -765,7 +765,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)) == -ENOMEM) {

Same here.

thanks,

greg k-h

#11 lore raw

PATCH v2 4/5 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 f8a4f910bfea..3550de9f12c3 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
#12 lore raw

PATCH v2 5/5 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. Also, remove unnecessary local variable 'res' in the function and replace the value directly in the return of the function.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -3
index 3550de9f12c3..c76f27a6b3ab 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 = 0;
-
 	/* 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,10 @@ 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;
+	if (!pevtpriv->c2h_queue)
+		return -ENOMEM;
+
+	return 0;
 }
 
 void _rtw_free_evt_priv(struct	evt_priv *pevtpriv)
Signature · 1 line
2.17.1
#13 lore raw

Re: [Outreachy kernel] [PATCH v2 5/5] Staging: rtl8723bs: Add missing NULL check for kmalloc

Quoted 3 lines · Madhumitha Prabakaran

Include missing NULL check for kmalloc in function rtw_init_evt_priv. Also, remove unnecessary local variable 'res' in the function and replace the value directly in the return of the function.

These changes seem quite unrelated. Dropping res was possible before any of the other changes because its value was never updated, and if you make your change, the value of res is not updated either.

julia

Quoted 41 lines
---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index 3550de9f12c3..c76f27a6b3ab 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 = 0;
-
 	/* 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,10 @@ 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;
+	if (!pevtpriv->c2h_queue)
+		return -ENOMEM;
+
+	return 0;
 }
 
 void _rtw_free_evt_priv(struct	evt_priv *pevtpriv)
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/4010080c4d3e2bd0ed50a747eff3d00c66eea169.1552858206.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#14 lore raw

Re: [Outreachy kernel] [PATCH v2 5/5] Staging: rtl8723bs: Add missing NULL check for kmalloc

Quoted 11 lines · Julia Lawall
Quoted 3 lines · Madhumitha Prabakaran

Include missing NULL check for kmalloc in function rtw_init_evt_priv. Also, remove unnecessary local variable 'res' in the function and replace the value directly in the return of the function.

These changes seem quite unrelated. Dropping res was possible before any of the other changes because its value was never updated, and if you make your change, the value of res is not updated either.

Yeah! But it is in same function, also res is not used anywhere in the function. So I removed it and changed the return type as return 0.

Quoted 51 lines

julia

Quoted 41 lines
---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index 3550de9f12c3..c76f27a6b3ab 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 = 0;
-
 	/* 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,10 @@ 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;
+	if (!pevtpriv->c2h_queue)
+		return -ENOMEM;
+
+	return 0;
 }
 
 void _rtw_free_evt_priv(struct	evt_priv *pevtpriv)
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/4010080c4d3e2bd0ed50a747eff3d00c66eea169.1552858206.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Signature · 5 lines
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1903172254090.2434%40hadrien.
For more options, visit https://groups.google.com/d/optout.
#15 lore raw

Re: [Outreachy kernel] [PATCH v2 5/5] Staging: rtl8723bs: Add missing NULL check for kmalloc

Quoted 9 lines · Madhumthia Prabakaran
Quoted 8 lines · Julia Lawall
Quoted 3 lines · Madhumitha Prabakaran

Include missing NULL check for kmalloc in function rtw_init_evt_priv. Also, remove unnecessary local variable 'res' in the function and replace the value directly in the return of the function.

Quoted 6 lines
Quoted 3 lines

These changes seem quite unrelated. Dropping res was possible before any of the other changes because its value was never updated, and if you make your change, the value of res is not updated either.

Yeah! But it is in same function, also res is not used anywhere in the function. So I removed it and changed the return type as return 0.

Same function doesn't mean that it needs to be in the same patch. It is quite fine to have it in the same series, because you in general are changing these res values.

julia

Quoted 53 lines
Quoted 52 lines

julia

Quoted 34 lines
---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -4
index 3550de9f12c3..c76f27a6b3ab 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 = 0;
-
 	/* 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,10 @@ 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;
+	if (!pevtpriv->c2h_queue)
+		return -ENOMEM;
+
+	return 0;
 }
 
 void _rtw_free_evt_priv(struct	evt_priv *pevtpriv)
--

2.17.1

Quoted 7 lines

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/4010080c4d3e2bd0ed50a747eff3d00c66eea169.1552858206.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1903172254090.2434%40hadrien.
For more options, visit https://groups.google.com/d/optout.

maintainer
#16 lore raw
In reply to Madhumitha Prabakaran
Quoted 10 lines · Madhumitha Prabakaran

This patchset does tasks as below:
1) Drop wrapper functions and change function names
2) Change type of variables and return type
3) Change values to standard error codes in functions
4) Replace NULL comparison with !
5) Add missing NULL check for kmalloc

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

Quoted 7 lines

Madhumitha Prabakaran (5):
Staging: rtl8723bs: Remove wrapper functions and change function names
Staging: rtl8723bs: Change type of variables and return type
Staging: rtl8723bs: Change values to standard error codes in
functions
Staging: rtl8723bs: Replace NULL comparison with !
Staging: rtl8723bs: Add missing NULL check for kmalloc

I applied the first two patches, please rebase and redo the remaining ones.

thanks,

greg k-h