2021-10-25 14:42:21

by Saurav Girepunje

[permalink] [raw]
Subject: [PATCH v2] staging: r8188eu: avoid use of goto statement

Remove the goto statement from _rtw_init_cmd_priv(). In this function
goto statement can be replace by return statement. By replacing the
goto statement with return statement local variable "res" is also not
required. As on goto label exit, function only return it is not
performing any cleanup. Avoiding goto statement will simplify the function.

Signed-off-by: Saurav Girepunje <[email protected]>
---

ChangeLog V2:

-Add space after line end on changelog.
-Remove addition blank link after the local variable res
as per the coding guidelines for linux kernel.

ChangeLog V1:

-Remove the goto statement from _rtw_init_cmd_priv(). In this
function goto statement can be replace by return statement.
By replacing the goto statement with return statement local
variable "res" is also not required. As on goto label exit,
function only return it is not performing any cleanup.
Avoiding goto statement will simplify the function.

drivers/staging/r8188eu/core/rtw_cmd.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
index e17332677daa..c94b9559b5e4 100644
--- a/drivers/staging/r8188eu/core/rtw_cmd.c
+++ b/drivers/staging/r8188eu/core/rtw_cmd.c
@@ -19,8 +19,6 @@ No irqsave is necessary.

static int _rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
{
- int res = _SUCCESS;
-
sema_init(&pcmdpriv->cmd_queue_sema, 0);
/* sema_init(&(pcmdpriv->cmd_done_sema), 0); */
sema_init(&pcmdpriv->terminate_cmdthread_sema, 0);
@@ -34,28 +32,23 @@ static int _rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
pcmdpriv->cmd_allocated_buf = kzalloc(MAX_CMDSZ + CMDBUFF_ALIGN_SZ,
GFP_KERNEL);

- if (!pcmdpriv->cmd_allocated_buf) {
- res = _FAIL;
- goto exit;
- }
+ if (!pcmdpriv->cmd_allocated_buf)
+ return _FAIL;

pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf + CMDBUFF_ALIGN_SZ - ((size_t)(pcmdpriv->cmd_allocated_buf) & (CMDBUFF_ALIGN_SZ - 1));

pcmdpriv->rsp_allocated_buf = kzalloc(MAX_RSPSZ + 4, GFP_KERNEL);

- if (!pcmdpriv->rsp_allocated_buf) {
- res = _FAIL;
- goto exit;
- }
+ if (!pcmdpriv->rsp_allocated_buf)
+ return _FAIL;

pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ((size_t)(pcmdpriv->rsp_allocated_buf) & 3);

pcmdpriv->cmd_issued_cnt = 0;
pcmdpriv->cmd_done_cnt = 0;
pcmdpriv->rsp_cnt = 0;
-exit:

- return res;
+ return _SUCCESS;
}

static void c2h_wk_callback(struct work_struct *work);
--
2.33.0


2021-10-27 00:55:04

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2] staging: r8188eu: avoid use of goto statement

On Mon, Oct 25, 2021 at 08:06:00PM +0530, Saurav Girepunje wrote:
> Remove the goto statement from _rtw_init_cmd_priv(). In this function
> goto statement can be replace by return statement. By replacing the
> goto statement with return statement local variable "res" is also not
> required. As on goto label exit, function only return it is not
> performing any cleanup. Avoiding goto statement will simplify the function.
>
> Signed-off-by: Saurav Girepunje <[email protected]>
> ---
>
> ChangeLog V2:
>
> -Add space after line end on changelog.
> -Remove addition blank link after the local variable res
> as per the coding guidelines for linux kernel.
>

This does not apply to my tree, please rebase and resubmit.

thanks,

greg k-h

2021-10-31 09:39:49

by Saurav Girepunje

[permalink] [raw]
Subject: Re: [PATCH v2] staging: r8188eu: avoid use of goto statement



On 26/10/21 10:16 pm, Greg KH wrote:
> On Mon, Oct 25, 2021 at 08:06:00PM +0530, Saurav Girepunje wrote:
>> Remove the goto statement from _rtw_init_cmd_priv(). In this function
>> goto statement can be replace by return statement. By replacing the
>> goto statement with return statement local variable "res" is also not
>> required. As on goto label exit, function only return it is not
>> performing any cleanup. Avoiding goto statement will simplify the function.
>>
>> Signed-off-by: Saurav Girepunje <[email protected]>
>> ---
>>
>> ChangeLog V2:
>>
>> -Add space after line end on changelog.
>> -Remove addition blank link after the local variable res
>> as per the coding guidelines for linux kernel.
>>
>
> This does not apply to my tree, please rebase and resubmit.
>
> thanks,
>
> greg k-h
>

OK,

Regards,
Saurav