Staging: rtl8723bs: Remove functions and replace return types
PATCH v2 1/1 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 _SUCCESS with 0 and _FAIL with -ENOMEM (as it is memory allocating functions), to maintain compatibility with rest of the kernel, wherein the driver returns 1 for _SUCCESS and 0 for _FAIL.
- Replace local variable 'res' data type from sint to int in both the functions.
- Include missing NULL check for kmalloc
- Replace NULL comparison with ! in function rtw_init_cmd_priv. Issue suggested by Coccinelle using ret.cocci.
--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 34 +++++++----------------- 1 file changed, 10 insertions(+), 24 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +10 -24
@@ -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 =0 ;init_completion (&pcmdpriv->cmd_queue_comp);init_completion (&pcmdpriv->terminate_cmdthread_comp);
@@ -177,8 +177,8 @@ sint _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; +if (!pcmdpriv->cmd_allocated_buf) { + res = -ENOMEM ; goto exit; }
@@ -186,8 +186,8 @@ sint _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; +if (!pcmdpriv->rsp_allocated_buf) { + res = -ENOMEM ; goto exit; }
@@ -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 =0 ;/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */ atomic_set (&pevtpriv->event_seq,0 );
@@ -213,6 +213,8 @@ sint _rtw_init_evt_priv(struct evt_priv *pevtpriv) pevtpriv->c2h_wk_alive = false; pevtpriv->c2h_queue =rtw_cbuf_alloc (C2H_QUEUE_MAX_LEN +1 ); +if (!pevtpriv->c2h_queue) +return -ENOMEM ;return res; }
@@ -295,22 +297,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
Quoted 6 lines · Madhumitha Prabakaran
- Remove functions
rtw_init_cmd_privandrtw_init_evt_priv, as its only purpose is to call the other functions_rtw_init_cmd_privand_rtw_init_evt_priv, respectively.
- Rename functions from_rtw_init_cmd_privand_rtw_init_evt_priv, tortw_init_cmd_privandrtw_init_evt_priv.
- Replace return types from sint to int
Quoted 8 lines
- Replace
_SUCCESSwith 0 and_FAILwith-ENOMEM(as it is memory allocating functions), to maintain compatibility with rest of the kernel, wherein the driver returns 1 for_SUCCESSand 0 for_FAIL.
- Replace local variable 'res' data type from sint to int in both the functions.
- Include missing NULL check for kmalloc
- Replace NULL comparison with ! in functionrtw_init_cmd_priv. Issue suggested by Coccinelle usingret.cocci.
This is looking good, but there is still more to do. You have changed the return values of these functions, so now you have to go find the call sites and update those as well.
This is also kind of a lot of different changes for one patch. At least the sint -> int change is not related to the rest. Make a series with that part in another patch.
The missing NULL check could also be a separate patch.
It could be:
patch 1: drop wrappers and change function names
patch 2: sint -> int
patch 3: change _SUCCESS and _FAIL
patch 4: replace NULL comparison
patch 5: add null check
julia
Quoted 98 lines
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 34 +++++++----------------- 1 file changed, 10 insertions(+), 24 deletions(-)drivers/staging/rtl8723bs/core/rtw_cmd.c +10
-25@@ -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 =0 ;init_completion (&pcmdpriv->cmd_queue_comp);init_completion (&pcmdpriv->terminate_cmdthread_comp);@@ -177,8 +177,8 @@ sint _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; +if (!pcmdpriv->cmd_allocated_buf) { + res = -ENOMEM ; goto exit; }@@ -186,8 +186,8 @@ sint _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; +if (!pcmdpriv->rsp_allocated_buf) { + res = -ENOMEM ; goto exit; }@@ -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 =0 ;/* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */ atomic_set (&pevtpriv->event_seq,0 );@@ -213,6 +213,8 @@ sint _rtw_init_evt_priv(struct evt_priv *pevtpriv) pevtpriv->c2h_wk_alive = false; pevtpriv->c2h_queue =rtw_cbuf_alloc (C2H_QUEUE_MAX_LEN +1 ); +if (!pevtpriv->c2h_queue) +return -ENOMEM ;return res; }@@ -295,22 +297,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/20190316151615.25314-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.