2021-10-31 18:11:40

by Saurav Girepunje

[permalink] [raw]
Subject: [PATCH] staging: r8188eu: os_dep: remove the goto statement

Remove the goto statement from rtw_init_drv_sw(). In this function goto
can be replace by return statement. As on goto label exit, function
only return it is not performing any cleanup. Avoiding goto will
improve the function readability.

Signed-off-by: Saurav Girepunje <[email protected]>
---
drivers/staging/r8188eu/os_dep/os_intfs.c | 39 +++++++----------------
1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/r8188eu/os_dep/os_intfs.c b/drivers/staging/r8188eu/os_dep/os_intfs.c
index 1418c9c4916c..4b409479108e 100644
--- a/drivers/staging/r8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/r8188eu/os_dep/os_intfs.c
@@ -480,48 +480,34 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
{
u8 ret8 = _SUCCESS;

- if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == _FAIL) {
- ret8 = _FAIL;
- goto exit;
- }
+ if (!rtw_init_cmd_priv(&padapter->cmdpriv))
+ return _FAIL;

padapter->cmdpriv.padapter = padapter;

- if ((rtw_init_evt_priv(&padapter->evtpriv)) == _FAIL) {
- ret8 = _FAIL;
- goto exit;
- }
-
- if (rtw_init_mlme_priv(padapter) == _FAIL) {
- ret8 = _FAIL;
- goto exit;
- }
+ if (!rtw_init_evt_priv(&padapter->evtpriv) || !rtw_init_mlme_priv(padapter))
+ return _FAIL;

rtw_init_wifidirect_timers(padapter);
init_wifidirect_info(padapter, P2P_ROLE_DISABLE);
reset_global_wifidirect_info(padapter);

- if (init_mlme_ext_priv(padapter) == _FAIL) {
- ret8 = _FAIL;
- goto exit;
- }
+ if (!init_mlme_ext_priv(padapter))
+ return _FAIL;

- if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) {
+ if (!_rtw_init_xmit_priv(&padapter->xmitpriv, padapter)) {
DBG_88E("Can't _rtw_init_xmit_priv\n");
- ret8 = _FAIL;
- goto exit;
+ return _FAIL;
}

- if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) {
+ if (!_rtw_init_recv_priv(&padapter->recvpriv, padapter)) {
DBG_88E("Can't _rtw_init_recv_priv\n");
- ret8 = _FAIL;
- goto exit;
+ return _FAIL;
}

- if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) {
+ if (!_rtw_init_sta_priv(&padapter->stapriv)) {
DBG_88E("Can't _rtw_init_sta_priv\n");
- ret8 = _FAIL;
- goto exit;
+ return _FAIL;
}

padapter->stapriv.padapter = padapter;
@@ -539,7 +525,6 @@ u8 rtw_init_drv_sw(struct adapter *padapter)

spin_lock_init(&padapter->br_ext_lock);

-exit:
return ret8;
}

--
2.33.0


2021-10-31 18:46:54

by Pavel Skripkin

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement

On 10/31/21 21:10, Saurav Girepunje wrote:
> Remove the goto statement from rtw_init_drv_sw(). In this function goto
> can be replace by return statement. As on goto label exit, function
> only return it is not performing any cleanup. Avoiding goto will
> improve the function readability.
>
> Signed-off-by: Saurav Girepunje <[email protected]>
> ---
> drivers/staging/r8188eu/os_dep/os_intfs.c | 39 +++++++----------------
> 1 file changed, 12 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/os_dep/os_intfs.c b/drivers/staging/r8188eu/os_dep/os_intfs.c
> index 1418c9c4916c..4b409479108e 100644
> --- a/drivers/staging/r8188eu/os_dep/os_intfs.c
> +++ b/drivers/staging/r8188eu/os_dep/os_intfs.c
> @@ -480,48 +480,34 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
> {
> u8 ret8 = _SUCCESS;
>


Btw, this variable can be removed completely then. It's used only for:

ret8 = rtw_init_default_value(padapter);

with your patch applied, but rtw_init_default_value() always returns
_SUCCESS.


> -exit:
> return ret8;
> }


And just `return _SUCCESS;` here.



With regards,
Pavel Skripkin

2021-10-31 19:19:11

by Saurav Girepunje

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement



On 01/11/21 12:13 am, Pavel Skripkin wrote:
> On 10/31/21 21:10, Saurav Girepunje wrote:
>> Remove the goto statement from rtw_init_drv_sw(). In this function goto
>> can be replace by return statement. As on goto label exit, function
>> only return it is not performing any cleanup. Avoiding goto will
>> improve the function readability.
>>
>> Signed-off-by: Saurav Girepunje <[email protected]>
>> ---
>>   drivers/staging/r8188eu/os_dep/os_intfs.c | 39 +++++++----------------
>>   1 file changed, 12 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/staging/r8188eu/os_dep/os_intfs.c b/drivers/staging/r8188eu/os_dep/os_intfs.c
>> index 1418c9c4916c..4b409479108e 100644
>> --- a/drivers/staging/r8188eu/os_dep/os_intfs.c
>> +++ b/drivers/staging/r8188eu/os_dep/os_intfs.c
>> @@ -480,48 +480,34 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
>>   {
>>       u8    ret8 = _SUCCESS;
>>
>
>
> Btw, this variable can be removed completely then. It's used only for:
>
> ret8 = rtw_init_default_value(padapter);
>
> with your patch applied, but rtw_init_default_value() always returns _SUCCESS.
>
I think rtw_init_default_value should return void. It's return value is not useful.
>
>> -exit:
>>      return ret8;
>>  }
>
>
> And just `return _SUCCESS;` here.
>
However rtw_init_drv_sw should return _SUCCESS here.
>
> With regards,
> Pavel Skripkin


Regards,
Saurav

2021-10-31 19:19:11

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement

On Sun, 2021-10-31 at 21:43 +0300, Pavel Skripkin wrote:
> On 10/31/21 21:10, Saurav Girepunje wrote:
> > Remove the goto statement from rtw_init_drv_sw(). In this function goto
> > can be replace by return statement. As on goto label exit, function
> > only return it is not performing any cleanup. Avoiding goto will
> > improve the function readability.
[]
> > diff --git a/drivers/staging/r8188eu/os_dep/os_intfs.c b/drivers/staging/r8188eu/os_dep/os_intfs.c
[]
> > @@ -480,48 +480,34 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
> > {
> > u8 ret8 = _SUCCESS;
>
> Btw, this variable can be removed completely then. It's used only for:
>
> ret8 = rtw_init_default_value(padapter);
>
> with your patch applied, but rtw_init_default_value() always returns
> _SUCCESS.
>
> > -exit:
> > return ret8;
> > }
>
> And just `return _SUCCESS;` here.

And maybe one day s/_SUCCESS/true/ and s/_FAIL/false/
with appropriate conversions to bool


2021-10-31 19:27:08

by Pavel Skripkin

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement

On 10/31/21 22:17, Saurav Girepunje wrote:
>
>
> On 01/11/21 12:13 am, Pavel Skripkin wrote:
>> On 10/31/21 21:10, Saurav Girepunje wrote:
>>> Remove the goto statement from rtw_init_drv_sw(). In this function goto
>>> can be replace by return statement. As on goto label exit, function
>>> only return it is not performing any cleanup. Avoiding goto will
>>> improve the function readability.
>>>
>>> Signed-off-by: Saurav Girepunje <[email protected]>
>>> ---
>>>   drivers/staging/r8188eu/os_dep/os_intfs.c | 39 +++++++----------------
>>>   1 file changed, 12 insertions(+), 27 deletions(-)
>>>
>>> diff --git a/drivers/staging/r8188eu/os_dep/os_intfs.c b/drivers/staging/r8188eu/os_dep/os_intfs.c
>>> index 1418c9c4916c..4b409479108e 100644
>>> --- a/drivers/staging/r8188eu/os_dep/os_intfs.c
>>> +++ b/drivers/staging/r8188eu/os_dep/os_intfs.c
>>> @@ -480,48 +480,34 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
>>>   {
>>>       u8    ret8 = _SUCCESS;
>>>
>>
>>
>> Btw, this variable can be removed completely then. It's used only for:
>>
>> ret8 = rtw_init_default_value(padapter);
>>
>> with your patch applied, but rtw_init_default_value() always returns _SUCCESS.
>>
> I think rtw_init_default_value should return void. It's return value is not useful.


Sure, but you need to firstly remove
`ret8 = rtw_init_default_value(padapter);` and then make it return bool
to not break the build.


With regards,
Pavel Skripkin

2021-10-31 19:29:46

by Pavel Skripkin

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement

On 10/31/21 22:24, Pavel Skripkin wrote:
>> I think rtw_init_default_value should return void. It's return value is not useful.
>
>
> Sure, but you need to firstly remove
> `ret8 = rtw_init_default_value(padapter);` and then make it return bool
^^^^

I mean void, of course :)


With regards,
Pavel Skripkin

2021-11-01 04:35:35

by Saurav Girepunje

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement



On 01/11/21 12:47 am, Joe Perches wrote:
> On Sun, 2021-10-31 at 21:43 +0300, Pavel Skripkin wrote:
>> On 10/31/21 21:10, Saurav Girepunje wrote:
>>> Remove the goto statement from rtw_init_drv_sw(). In this function goto
>>> can be replace by return statement. As on goto label exit, function
>>> only return it is not performing any cleanup. Avoiding goto will
>>> improve the function readability.
> []
>>> diff --git a/drivers/staging/r8188eu/os_dep/os_intfs.c b/drivers/staging/r8188eu/os_dep/os_intfs.c
> []
>>> @@ -480,48 +480,34 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
>>> {
>>> u8 ret8 = _SUCCESS;
>>
>> Btw, this variable can be removed completely then. It's used only for:
>>
>> ret8 = rtw_init_default_value(padapter);
>>
>> with your patch applied, but rtw_init_default_value() always returns
>> _SUCCESS.
>>
>>> -exit:
>>> return ret8;
>>> }
>>
>> And just `return _SUCCESS;` here.
>
> And maybe one day s/_SUCCESS/true/ and s/_FAIL/false/
> with appropriate conversions to bool
>
>

Yes this is another improvement possible on this function.

Regards,
Saurav

2021-11-01 04:36:04

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement

On Mon, 2021-11-01 at 09:58 +0530, Saurav Girepunje wrote:
> On 01/11/21 12:47 am, Joe Perches wrote:
> > On Sun, 2021-10-31 at 21:43 +0300, Pavel Skripkin wrote:
> > > On 10/31/21 21:10, Saurav Girepunje wrote:
> > > > Remove the goto statement from rtw_init_drv_sw(). In this function goto
> > > > can be replace by return statement. As on goto label exit, function
> > > > only return it is not performing any cleanup. Avoiding goto will
> > > > improve the function readability.
[]
> > > And just `return _SUCCESS;` here.
> >
> > And maybe one day s/_SUCCESS/true/ and s/_FAIL/false/
> > with appropriate conversions to bool
>
> Yes this is another improvement possible on this function.

Not just this function, globally in the driver.

2021-11-01 13:05:08

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement

On Sun, Oct 31, 2021 at 11:40:18PM +0530, Saurav Girepunje wrote:
> Remove the goto statement from rtw_init_drv_sw(). In this function goto
> can be replace by return statement. As on goto label exit, function
> only return it is not performing any cleanup. Avoiding goto will
> improve the function readability.
>
> Signed-off-by: Saurav Girepunje <[email protected]>
> ---
> drivers/staging/r8188eu/os_dep/os_intfs.c | 39 +++++++----------------
> 1 file changed, 12 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/os_dep/os_intfs.c b/drivers/staging/r8188eu/os_dep/os_intfs.c
> index 1418c9c4916c..4b409479108e 100644
> --- a/drivers/staging/r8188eu/os_dep/os_intfs.c
> +++ b/drivers/staging/r8188eu/os_dep/os_intfs.c
> @@ -480,48 +480,34 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
> {
> u8 ret8 = _SUCCESS;
>
> - if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == _FAIL) {
> - ret8 = _FAIL;
> - goto exit;
> - }
> + if (!rtw_init_cmd_priv(&padapter->cmdpriv))
> + return _FAIL;
>
> padapter->cmdpriv.padapter = padapter;
>
> - if ((rtw_init_evt_priv(&padapter->evtpriv)) == _FAIL) {
> - ret8 = _FAIL;
> - goto exit;
> - }
> -
> - if (rtw_init_mlme_priv(padapter) == _FAIL) {
> - ret8 = _FAIL;
> - goto exit;
> - }
> + if (!rtw_init_evt_priv(&padapter->evtpriv) || !rtw_init_mlme_priv(padapter))
> + return _FAIL;

These are functions that are being called so keeping them separate as
the code you removed did makes it "obvious" what is happening here.

So can you keep it that way please?

But my larger question is do these functions create state or allocate
memory that needs to be unwound properly if an error does happen? Right
now the function seems to not be doing that at all, but that does not
mean it is correct as-is...

thanks,

greg k-h

2021-11-02 16:42:00

by Saurav Girepunje

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement



On 01/11/21 12:57 am, Pavel Skripkin wrote:
> On 10/31/21 22:24, Pavel Skripkin wrote:
>>> I think rtw_init_default_value should return void. It's return value is not useful.
>>
>>
>> Sure, but you need to firstly remove
>> `ret8 = rtw_init_default_value(padapter);` and then make it return bool
>                                      ^^^^
>
> I mean void, of course :)
>
>
> With regards,
> Pavel Skripkin

Intention for this patch to remove the goto statement. I think removing a local variable
for return value and changing the return type of function can be one separate patch.

On this patch intent to remove the goto statement only.


Regards,
Saurav

2021-11-02 16:42:35

by Saurav Girepunje

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement



On 01/11/21 6:31 pm, Greg KH wrote:
> On Sun, Oct 31, 2021 at 11:40:18PM +0530, Saurav Girepunje wrote:
>> Remove the goto statement from rtw_init_drv_sw(). In this function goto
>> can be replace by return statement. As on goto label exit, function
>> only return it is not performing any cleanup. Avoiding goto will
>> improve the function readability.
>>
>> Signed-off-by: Saurav Girepunje <[email protected]>
>> ---
>> drivers/staging/r8188eu/os_dep/os_intfs.c | 39 +++++++----------------
>> 1 file changed, 12 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/staging/r8188eu/os_dep/os_intfs.c b/drivers/staging/r8188eu/os_dep/os_intfs.c
>> index 1418c9c4916c..4b409479108e 100644
>> --- a/drivers/staging/r8188eu/os_dep/os_intfs.c
>> +++ b/drivers/staging/r8188eu/os_dep/os_intfs.c
>> @@ -480,48 +480,34 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
>> {
>> u8 ret8 = _SUCCESS;
>>
>> - if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == _FAIL) {
>> - ret8 = _FAIL;
>> - goto exit;
>> - }
>> + if (!rtw_init_cmd_priv(&padapter->cmdpriv))
>> + return _FAIL;
>>
>> padapter->cmdpriv.padapter = padapter;
>>
>> - if ((rtw_init_evt_priv(&padapter->evtpriv)) == _FAIL) {
>> - ret8 = _FAIL;
>> - goto exit;
>> - }
>> -
>> - if (rtw_init_mlme_priv(padapter) == _FAIL) {
>> - ret8 = _FAIL;
>> - goto exit;
>> - }
>> + if (!rtw_init_evt_priv(&padapter->evtpriv) || !rtw_init_mlme_priv(padapter))
>> + return _FAIL;
>
> These are functions that are being called so keeping them separate as
> the code you removed did makes it "obvious" what is happening here.
>
> So can you keep it that way please?
>
I will make them separate as they were.

> But my larger question is do these functions create state or allocate
> memory that needs to be unwound properly if an error does happen? Right
> now the function seems to not be doing that at all, but that does not
> mean it is correct as-is...
>
> thanks,
>
> greg k-h
> Regards,
Saurav

2021-11-02 20:23:30

by Pavel Skripkin

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: os_dep: remove the goto statement

On 11/2/21 19:40, Saurav Girepunje wrote:
>
>
> On 01/11/21 12:57 am, Pavel Skripkin wrote:
>> On 10/31/21 22:24, Pavel Skripkin wrote:
>>>> I think rtw_init_default_value should return void. It's return value is not useful.
>>>
>>>
>>> Sure, but you need to firstly remove
>>> `ret8 = rtw_init_default_value(padapter);` and then make it return bool
>>                                      ^^^^
>>
>> I mean void, of course :)
>>
>>
>> With regards,
>> Pavel Skripkin
>
> Intention for this patch to remove the goto statement. I think removing a local variable
> for return value and changing the return type of function can be one separate patch.
>
> On this patch intent to remove the goto statement only.
>

I agree, I've just pointed out to further possible code improvements :)



With regards,
Pavel Skripkin