Skip to contentSkip to conversation

Issue suggested by Coccinelle using ret.cocci

PATCH In review Madhumitha Prabakaran 2 participants 6 messages Mar 16, 2019 Staging

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 Staging: rtl87223bs: Refactor function and check return value

In reply to Madhumitha Prabakaran

- Refactor return tenary statement in _rtw_malloc
- Check return value against NULL

---
 drivers/staging/rtl8723bs/os_dep/osdep_service.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/os_dep/osdep_service.c +9 -1
index 73b87da15eb2..9dfdd13d4acd 100644
@@ -24,7 +24,15 @@ inline int RTW_STATUS_CODE(int error_code)
 
 void *_rtw_malloc(u32 sz)
 {
-	return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
+	int _sz;
+
+	if (in_interrupt())
+		_sz = kmalloc(sz, GFP_ATOMIC);
+	else
+		_sz = kmalloc(sz, GFP_KERNEL);
+	if (!_sz)
+		return -ENOMEM;
+	return _sz;
 }
 
 void *_rtw_zmalloc(u32 sz)
Signature · 1 line
2.17.1
#0 lore raw

cover Issue suggested by Coccinelle using ret.cocci

This patchset does following -
1) Refactor function and check return values
2) Remove function and replace return types

Madhumitha Prabakaran (2):
Staging: rtl87223bs: Refactor function and check return value
Staging: rtl8723bs: Remove functions and replace return types

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

PATCH 2/2 Staging: rtl8723bs: Remove functions and replace return types

- Remove functions rtw_init_cmd_priv and rtw_init_evt_priv, as its only purpose is to call the other functions _rtw_init_cmd_priv and _rtw_init_evt_priv, respectively.
- Rename functions from _rtw_init_cmd_priv and _rtw_init_evt_priv, to rtw_init_cmd_priv and rtw_init_evt_priv.
- Replace return types from sint to int
- Replace local variable 'res' data type from sint to int in both the functions.

Issue suggested by Coccinelle using ret.cocci.

Change in v2-
- Changed the commit log
- Modified the return types from sint to int.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -20
index 91520ca3bbad..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);
@@ -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"));
Signature · 1 line
2.17.1
#2 lore raw

Re: [Outreachy kernel] [PATCH 1/2] Staging: rtl87223bs: Refactor function and check return value

In reply to Madhumitha Prabakaran
Quoted 16 lines · Madhumitha Prabakaran

- Refactor return tenary statement in _rtw_malloc
- Check return value against NULL

---
 drivers/staging/rtl8723bs/os_dep/osdep_service.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/os_dep/osdep_service.c +0 -0
index 73b87da15eb2..9dfdd13d4acd 100644
@@ -24,7 +24,15 @@ inline int RTW_STATUS_CODE(int error_code)
 
 void *_rtw_malloc(u32 sz)
 {

drivers/staging/rtl8723bs/os_dep/osdep_service.c inline int RTW_STATUS_CODE(int error_code) · line 35

Quoted 10 lines
drivers/staging/rtl8723bs/os_dep/osdep_service.c +9 -1
-	return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
+	int _sz;
+
+	if (in_interrupt())
+		_sz = kmalloc(sz, GFP_ATOMIC);
+	else
+		_sz = kmalloc(sz, GFP_KERNEL);
+	if (!_sz)
+		return -ENOMEM;
+	return _sz;

Sorry, but this is neither correct nor useful.

If you compile it, you should see that it is not correct.

The change that should be done is to eliminate the function entirely. The calls should be replaced by calls to kmalloc directly, with the second argument appropriate to the context.

But the way to do that is not by starting with this function, but rather by working on the usage sites one by one. When there are no usage sites, this function definition can be dropped.

julia

Quoted 13 lines
drivers/staging/rtl8723bs/os_dep/osdep_service.c +0 -1
 }
 
 void *_rtw_zmalloc(u32 sz)
--

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/79e1366235e198546f0a6781a8538ac825f775c1.1552740889.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#5 lore raw

Re: [Outreachy kernel] [PATCH 2/2] Staging: rtl8723bs: Remove functions and replace return types

In reply to Madhumitha Prabakaran
Quoted 25 lines · Madhumitha Prabakaran

- Remove functions rtw_init_cmd_priv and rtw_init_evt_priv, as its only purpose is to call the other functions _rtw_init_cmd_priv and _rtw_init_evt_priv, respectively.
- Rename functions from _rtw_init_cmd_priv and _rtw_init_evt_priv, to rtw_init_cmd_priv and rtw_init_evt_priv.
- Replace return types from sint to int
- Replace local variable 'res' data type from sint to int in both the functions.

Issue suggested by Coccinelle using ret.cocci.

Change in v2-
- Changed the commit log
- Modified the return types from sint to int.

---
 drivers/staging/rtl8723bs/core/rtw_cmd.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +0 -0
index 91520ca3bbad..ab450f717f34 100644

drivers/staging/rtl8723bs/core/rtw_cmd.c Caller and the rtw_cmd_thread can protect cmd_q by spin_lock. · line 167

Quoted 8 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +2 -2
@@ -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;

This looks ok, but a better solution would be to replace _SUCCESS by 0 and _FAIL by -ENOMEM and fix up the call sites accordingly.

Also currently one of the functions never returns _FAIL. It should be updated to check for failure and return -ENOMEM in this case. You should look at how the allocated value is used, and explain why it is correct to fail in this case.

julia

Quoted 48 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +2 -19
 	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);
@@ -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"));
--

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/9e058ab3c889d2d59b0e7c7e0296e8640a513d23.1552740889.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#3 lore raw

Re: [Outreachy kernel] [PATCH 1/2] Staging: rtl87223bs: Refactor function and check return value

In reply to Julia Lawall
Quoted 33 lines · Julia Lawall
Quoted 16 lines · Madhumitha Prabakaran

- Refactor return tenary statement in _rtw_malloc
- Check return value against NULL

---
 drivers/staging/rtl8723bs/os_dep/osdep_service.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/os_dep/osdep_service.c +0 -0
index 73b87da15eb2..9dfdd13d4acd 100644
@@ -24,7 +24,15 @@ inline int RTW_STATUS_CODE(int error_code)
 
 void *_rtw_malloc(u32 sz)
 {

drivers/staging/rtl8723bs/os_dep/osdep_service.c inline int RTW_STATUS_CODE(int error_code) · line 35

Quoted 10 lines
drivers/staging/rtl8723bs/os_dep/osdep_service.c +9 -1
-	return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
+	int _sz;
+
+	if (in_interrupt())
+		_sz = kmalloc(sz, GFP_ATOMIC);
+	else
+		_sz = kmalloc(sz, GFP_KERNEL);
+	if (!_sz)
+		return -ENOMEM;
+	return _sz;

Sorry, but this is neither correct nor useful.

Quoted 5 lines

If you compile it, you should see that it is not correct.

The change that should be done is to eliminate the function entirely. The calls should be replaced by calls to kmalloc directly, with the second argument appropriate to the context.

I will work on this and resend it

Quoted 20 lines

But the way to do that is not by starting with this function, but rather by working on the usage sites one by one. When there are no usage sites, this function definition can be dropped.

julia

Quoted 13 lines
drivers/staging/rtl8723bs/os_dep/osdep_service.c +0 -1
 }
 
 void *_rtw_zmalloc(u32 sz)
--

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/79e1366235e198546f0a6781a8538ac825f775c1.1552740889.git.madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.