Staging: rtl8723bs: Remove functions and replace return types
PATCH 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 u32
- Replace local variable 'res' data type from sint to u32 in both the functions.
Issue suggested by Coccinelle using ret.cocci.
--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +4 -20
@@ -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) +u32 rtw_init_cmd_priv (struct cmd_priv *pcmdpriv) { -sint res = _SUCCESS; +u32 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) +u32 rtw_init_evt_priv (struct evt_priv *pevtpriv) { -sint res = _SUCCESS; +u32 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
Quoted 9 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 u32
- Replace local variable 'res' data type from sint to u32 in both the functions.
Issue suggested by Coccinelle usingret.cocci.
OK, this is a really good first step, with a nice log message as well. However, looking a bit further, there is more to do.
We can observe that you changed the return type from signed to unsigned, and it is a little bit surprising that this is ok.
Looking at the definitions of these functions it seems that they return error codes, _SUCCESS and _FAIL. Often in the Linux kernel, success is indicated by 0 and failure is indicated by a negative number, so one may still be surprised by the change of type.
But this driver actually returns 1 for success and 0 for failure, so the code remains correctly functioning with the change of type.
Still, these are not really ideal error values. To be compatible with the rest of the kernel, success should be 0 and failure should be -ENOMEM, because these are memory allocating functions. In that case the return type of these functions should be int, rather than u32.
Finally, _rtw_init_evt_priv actually never returns _FAIL. The memory allocation in this function bottoms out at kmalloc, which can fail, so there needs to be a check for this, and to return an -ENOMEM value.
Checking on all of that leads to:
void *_rtw_malloc(u32 sz)
{
return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
}which is incorrect. Each call site needs to be checked to determine whether it is in atomic context (accessible from an interrupt handler or with a lock held) and to use GFP_ATOMIC if that is the case and GFP_KERNEL otherwise.
I would suggest to clean up everything up to the paragraph starting with "Finally" in a single series. Then, if you want to work more on this driver, you can look for other uses of _SUCCESS and _FAIL and convert them to more appropriate return values, and convert calls to rtw_malloc to calls to kmalloc with the correct flag argument. There is also a function rtw_zalloc that should be kzalloc with the same issues. Actually, the file osdep_service.c hasa good set of unsuitable definitions that should be cleaned up.
julia
Quoted 67 lines
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-)drivers/staging/rtl8723bs/core/rtw_cmd.c +4
-21@@ -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) +u32 rtw_init_cmd_priv (struct cmd_priv *pcmdpriv) { -sint res = _SUCCESS; +u32 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) +u32 rtw_init_evt_priv (struct evt_priv *pevtpriv) { -sint res = _SUCCESS; +u32 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/20190314223416.3994-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 17 lines · Julia Lawall
Quoted 9 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 u32
- Replace local variable 'res' data type from sint to u32 in both the functions.
Issue suggested by Coccinelle usingret.cocci.OK, this is a really good first step, with a nice log message as well. However, looking a bit further, there is more to do.
Quoted 7 lines
We can observe that you changed the return type from signed to unsigned, and it is a little bit surprising that this is ok.
Looking at the definitions of these functions it seems that they return error codes,
_SUCCESSand_FAIL. Often in the Linux kernel, success is indicated by 0 and failure is indicated by a negative number, so one may still be surprised by the change of type.
I didn't changed _SUCCESS value to 0 and _FAIL value to -ENOMEM. yet again it complied. I want to confirm whether I have to change it directly or there is function RTW_STATUS_CODE in os_dep/osdep_service.c, which can be modified to make _SUCCESS and _FAIL compatible with rest of the kernel
Quoted 25 lines
But this driver actually returns 1 for success and 0 for failure, so the code remains correctly functioning with the change of type.
Still, these are not really ideal error values. To be compatible with the rest of the kernel, success should be 0 and failure should be
-ENOMEM, because these are memory allocating functions. In that case the return type of these functions should be int, rather than u32.Finally,
_rtw_init_evt_privactually never returns_FAIL. The memory allocation in this function bottoms out at kmalloc, which can fail, so there needs to be a check for this, and to return an-ENOMEMvalue.Checking on all of that leads to:
void *_rtw_malloc(u32 sz)
{ return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); }which is incorrect. Each call site needs to be checked to determine whether it is in atomic context (accessible from an interrupt handler or with a lock held) and to use
GFP_ATOMICif that is the case andGFP_KERNELotherwise.
Quoted 8 lines
I would suggest to clean up everything up to the paragraph starting with "Finally" in a single series. Then, if you want to work more on this driver, you can look for other uses of
_SUCCESSand_FAILand convert them to more appropriate return values, and convert calls tortw_mallocto calls to kmalloc with the correct flag argument. There is also a functionrtw_zallocthat should be kzalloc with the same issues. Actually, the fileosdep_service.chasa good set of unsuitable definitions that should be cleaned up.
I sent it as a patch series. I will work on all unsuitable definitions in osdep_service.c.
Quoted 70 lines
julia
Quoted 67 lines
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-)drivers/staging/rtl8723bs/core/rtw_cmd.c +4
-21@@ -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) +u32 rtw_init_cmd_priv (struct cmd_priv *pcmdpriv) { -sint res = _SUCCESS; +u32 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) +u32 rtw_init_evt_priv (struct evt_priv *pevtpriv) { -sint res = _SUCCESS; +u32 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/20190314223416.3994-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 26 lines · Madhumthia Prabakaran
Quoted 17 lines · Julia Lawall
Quoted 9 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 u32
- Replace local variable 'res' data type from sint to u32 in both the functions.
Issue suggested by Coccinelle usingret.cocci.OK, this is a really good first step, with a nice log message as well. However, looking a bit further, there is more to do.
Quoted 7 lines
We can observe that you changed the return type from signed to unsigned, and it is a little bit surprising that this is ok.
Looking at the definitions of these functions it seems that they return error codes,
_SUCCESSand_FAIL. Often in the Linux kernel, success is indicated by 0 and failure is indicated by a negative number, so one may still be surprised by the change of type.
Quoted 5 lines
I didn't changed
_SUCCESSvalue to 0 and_FAILvalue to-ENOMEM. yet again it complied. I want to confirm whether I have to change it directly or there is functionRTW_STATUS_CODEinos_dep/osdep_service.c, which can be modified to make_SUCCESSand_FAILcompatible with rest of the kernel
Please don't use _SUCCESS and _FAIL. It doesn't really matter what these symbols are bound to. Using them won't cause a compiler error. The problem is that they are the wrong symbols. Success should be indicated with 0 and failure, in the case of a memory allocation, should be indicated with -ENOMEM. Other kinds of failures have other error codes (-EINVAL, -ENODEV, etc).
Quoted 34 lines
Quoted 25 lines
But this driver actually returns 1 for success and 0 for failure, so the code remains correctly functioning with the change of type.
Still, these are not really ideal error values. To be compatible with the rest of the kernel, success should be 0 and failure should be
-ENOMEM, because these are memory allocating functions. In that case the return type of these functions should be int, rather than u32.Finally,
_rtw_init_evt_privactually never returns_FAIL. The memory allocation in this function bottoms out at kmalloc, which can fail, so there needs to be a check for this, and to return an-ENOMEMvalue.Checking on all of that leads to:
void *_rtw_malloc(u32 sz)
{ return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); }which is incorrect. Each call site needs to be checked to determine whether it is in atomic context (accessible from an interrupt handler or with a lock held) and to use
GFP_ATOMICif that is the case andGFP_KERNELotherwise.Quoted 8 lines
I would suggest to clean up everything up to the paragraph starting with "Finally" in a single series. Then, if you want to work more on this driver, you can look for other uses of
_SUCCESSand_FAILand convert them to more appropriate return values, and convert calls tortw_mallocto calls to kmalloc with the correct flag argument. There is also a functionrtw_zallocthat should be kzalloc with the same issues. Actually, the fileosdep_service.chasa good set of unsuitable definitions that should be cleaned up.
Quoted 2 lines
I sent it as a patch series. I will work on all unsuitable definitions in
osdep_service.c.
Actually, it is not really the definitions that need to be cleaned up. The uses of these functions need to be replaced by direct calls to the standard kernel functions, and then the functions in osdep_service.c should be dropped.
julia
Quoted 72 lines
Quoted 71 lines
julia
Quoted 67 lines
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-)drivers/staging/rtl8723bs/core/rtw_cmd.c +4
-21@@ -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) +u32 rtw_init_cmd_priv (struct cmd_priv *pcmdpriv) { -sint res = _SUCCESS; +u32 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) +u32 rtw_init_evt_priv (struct evt_priv *pevtpriv) { -sint res = _SUCCESS; +u32 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/20190314223416.3994-1-madhumithabiw%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 77 lines · Julia Lawall
Quoted 26 lines · Madhumthia Prabakaran
Quoted 17 lines · Julia Lawall
Quoted 9 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 u32
- Replace local variable 'res' data type from sint to u32 in both the functions.
Issue suggested by Coccinelle usingret.cocci.OK, this is a really good first step, with a nice log message as well. However, looking a bit further, there is more to do.
Quoted 7 lines
We can observe that you changed the return type from signed to unsigned, and it is a little bit surprising that this is ok.
Looking at the definitions of these functions it seems that they return error codes,
_SUCCESSand_FAIL. Often in the Linux kernel, success is indicated by 0 and failure is indicated by a negative number, so one may still be surprised by the change of type.Quoted 5 lines
I didn't changed
_SUCCESSvalue to 0 and_FAILvalue to-ENOMEM. yet again it complied. I want to confirm whether I have to change it directly or there is functionRTW_STATUS_CODEinos_dep/osdep_service.c, which can be modified to make_SUCCESSand_FAILcompatible with rest of the kernelPlease don't use
_SUCCESSand_FAIL. It doesn't really matter what these symbols are bound to. Using them won't cause a compiler error. The problem is that they are the wrong symbols. Success should be indicated with 0 and failure, in the case of a memory allocation, should be indicated with-ENOMEM. Other kinds of failures have other error codes (-EINVAL,-ENODEV, etc).Quoted 34 lines
Quoted 33 lines
But this driver actually returns 1 for success and 0 for failure, so the code remains correctly functioning with the change of type.
Still, these are not really ideal error values. To be compatible with the rest of the kernel, success should be 0 and failure should be
-ENOMEM, because these are memory allocating functions. In that case the return type of these functions should be int, rather than u32.Finally,
_rtw_init_evt_privactually never returns_FAIL. The memory allocation in this function bottoms out at kmalloc, which can fail, so there needs to be a check for this, and to return an-ENOMEMvalue.Checking on all of that leads to:
void *_rtw_malloc(u32 sz)
{ return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); }which is incorrect. Each call site needs to be checked to determine whether it is in atomic context (accessible from an interrupt handler or with a lock held) and to use
GFP_ATOMICif that is the case andGFP_KERNELotherwise.I would suggest to clean up everything up to the paragraph starting with "Finally" in a single series. Then, if you want to work more on this driver, you can look for other uses of
_SUCCESSand_FAILand convert them to more appropriate return values, and convert calls tortw_mallocto calls to kmalloc with the correct flag argument. There is also a functionrtw_zallocthat should be kzalloc with the same issues. Actually, the fileosdep_service.chasa good set of unsuitable definitions that should be cleaned up.
Quoted 7 lines
Quoted 2 lines
I sent it as a patch series. I will work on all unsuitable definitions in
osdep_service.c.Actually, it is not really the definitions that need to be cleaned up. The uses of these functions need to be replaced by direct calls to the standard kernel functions, and then the functions in
osdep_service.cshould be dropped.
I will fix all the functions backtracing from _rtw_init_evt_priv to _rtw_malloc in another patch. Along with that, I wil fix rtw_zalloc, which have same issues.
Thanks
Quoted 82 lines
julia
Quoted 72 lines
Quoted 71 lines
julia
Quoted 67 lines
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-)drivers/staging/rtl8723bs/core/rtw_cmd.c +4
-21@@ -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) +u32 rtw_init_cmd_priv (struct cmd_priv *pcmdpriv) { -sint res = _SUCCESS; +u32 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) +u32 rtw_init_evt_priv (struct evt_priv *pevtpriv) { -sint res = _SUCCESS; +u32 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/20190314223416.3994-1-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.1903161419430.2487%40hadrien. For more options, visit https://groups.google.com/d/optout.
Quoted 81 lines · Madhumthia Prabakaran
Quoted 80 lines · Julia Lawall
Quoted 26 lines · Madhumthia Prabakaran
Quoted 17 lines · Julia Lawall
Quoted 9 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 u32
- Replace local variable 'res' data type from sint to u32 in both the functions.
Issue suggested by Coccinelle usingret.cocci.OK, this is a really good first step, with a nice log message as well. However, looking a bit further, there is more to do.
Quoted 7 lines
We can observe that you changed the return type from signed to unsigned, and it is a little bit surprising that this is ok.
Looking at the definitions of these functions it seems that they return error codes,
_SUCCESSand_FAIL. Often in the Linux kernel, success is indicated by 0 and failure is indicated by a negative number, so one may still be surprised by the change of type.Quoted 5 lines
I didn't changed
_SUCCESSvalue to 0 and_FAILvalue to-ENOMEM. yet again it complied. I want to confirm whether I have to change it directly or there is functionRTW_STATUS_CODEinos_dep/osdep_service.c, which can be modified to make_SUCCESSand_FAILcompatible with rest of the kernelPlease don't use
_SUCCESSand_FAIL. It doesn't really matter what these symbols are bound to. Using them won't cause a compiler error. The problem is that they are the wrong symbols. Success should be indicated with 0 and failure, in the case of a memory allocation, should be indicated with-ENOMEM. Other kinds of failures have other error codes (-EINVAL,-ENODEV, etc).Quoted 36 lines
Quoted 25 lines
But this driver actually returns 1 for success and 0 for failure, so the code remains correctly functioning with the change of type.
Still, these are not really ideal error values. To be compatible with the rest of the kernel, success should be 0 and failure should be
-ENOMEM, because these are memory allocating functions. In that case the return type of these functions should be int, rather than u32.Finally,
_rtw_init_evt_privactually never returns_FAIL. The memory allocation in this function bottoms out at kmalloc, which can fail, so there needs to be a check for this, and to return an-ENOMEMvalue.Checking on all of that leads to:
void *_rtw_malloc(u32 sz)
{ return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); }which is incorrect. Each call site needs to be checked to determine whether it is in atomic context (accessible from an interrupt handler or with a lock held) and to use
GFP_ATOMICif that is the case andGFP_KERNELotherwise.Quoted 8 lines
I would suggest to clean up everything up to the paragraph starting with "Finally" in a single series. Then, if you want to work more on this driver, you can look for other uses of
_SUCCESSand_FAILand convert them to more appropriate return values, and convert calls tortw_mallocto calls to kmalloc with the correct flag argument. There is also a functionrtw_zallocthat should be kzalloc with the same issues. Actually, the fileosdep_service.chasa good set of unsuitable definitions that should be cleaned up.I sent it as a patch series. I will work on all unsuitable definitions in
osdep_service.c.
Quoted 8 lines
Quoted 4 lines
Actually, it is not really the definitions that need to be cleaned up. The uses of these functions need to be replaced by direct calls to the standard kernel functions, and then the functions in
osdep_service.cshould be dropped.I will fix all the functions backtracing from
_rtw_init_evt_privto_rtw_mallocin another patch. Along with that, I wil fixrtw_zalloc, which have same issues.
Don't go overobard. I would suggest to fix each call site one at a time. Or perhaps all call sites in a single file, if there aren't too many of them. But don't aim to send a single patch with 50 changes.
julia
Quoted 86 lines
Thanks
Quoted 82 lines
julia
Quoted 64 lines
Quoted 64 lines
julia
Quoted 60 lines
Signed-off-by Madhumitha Prabakaran <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-)drivers/staging/rtl8723bs/core/rtw_cmd.c +4
-21@@ -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) +u32 rtw_init_cmd_priv (struct cmd_priv *pcmdpriv) { -sint res = _SUCCESS; +u32 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) +u32 rtw_init_evt_priv (struct evt_priv *pevtpriv) { -sint res = _SUCCESS; +u32 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
Quoted 8 lines
Quoted 7 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/20190314223416.3994-1-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.1903161419430.2487%40hadrien.
For more options, visit https://groups.google.com/d/optout.