2022-08-03 00:16:24

by Phillip Potter

[permalink] [raw]
Subject: [PATCH] staging: r8188eu: convert rtw_p2p_enable to correct error code semantics

Convert the rtw_p2p_enable function to use correct error code semantics
rather than _SUCCESS/_FAIL, and also make sure we allow these to be
passed through properly in the one caller where we actually check the
code, rtw_wext_p2p_enable.

This change moves these functions to a clearer 'return 0;' style at the
end of the function, and in the case of errors now returns ret instead
of jumping to the end of the function, so that these can still be passed
through but without using a goto to jump to a single return statement at
the end which is less clear.

This change moves the driver slowly closer to using standard error code
semantics everywhere.

Signed-off-by: Phillip Potter <[email protected]>
---
drivers/staging/r8188eu/core/rtw_p2p.c | 19 ++++++++-----------
drivers/staging/r8188eu/os_dep/ioctl_linux.c | 12 +++++-------
2 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_p2p.c b/drivers/staging/r8188eu/core/rtw_p2p.c
index bd654d4ff8b4..dc159e58f428 100644
--- a/drivers/staging/r8188eu/core/rtw_p2p.c
+++ b/drivers/staging/r8188eu/core/rtw_p2p.c
@@ -1883,15 +1883,14 @@ void init_wifidirect_info(struct adapter *padapter, enum P2P_ROLE role)

int rtw_p2p_enable(struct adapter *padapter, enum P2P_ROLE role)
{
- int ret = _SUCCESS;
+ int ret;
struct wifidirect_info *pwdinfo = &padapter->wdinfo;

if (role == P2P_ROLE_DEVICE || role == P2P_ROLE_CLIENT || role == P2P_ROLE_GO) {
/* leave IPS/Autosuspend */
- if (rtw_pwr_wakeup(padapter)) {
- ret = _FAIL;
- goto exit;
- }
+ ret = rtw_pwr_wakeup(padapter);
+ if (ret)
+ return ret;

/* Added by Albert 2011/03/22 */
/* In the P2P mode, the driver should not support the b mode. */
@@ -1902,10 +1901,9 @@ int rtw_p2p_enable(struct adapter *padapter, enum P2P_ROLE role)
init_wifidirect_info(padapter, role);

} else if (role == P2P_ROLE_DISABLE) {
- if (rtw_pwr_wakeup(padapter)) {
- ret = _FAIL;
- goto exit;
- }
+ ret = rtw_pwr_wakeup(padapter);
+ if (ret)
+ return ret;

/* Disable P2P function */
if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
@@ -1923,6 +1921,5 @@ int rtw_p2p_enable(struct adapter *padapter, enum P2P_ROLE role)
update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
}

-exit:
- return ret;
+ return 0;
}
diff --git a/drivers/staging/r8188eu/os_dep/ioctl_linux.c b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
index 7f91dac2e41b..e9802d42aa1b 100644
--- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
@@ -2079,7 +2079,7 @@ static int rtw_wext_p2p_enable(struct net_device *dev,
struct iw_request_info *info,
union iwreq_data *wrqu, char *extra)
{
- int ret = 0;
+ int ret;
struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
struct wifidirect_info *pwdinfo = &padapter->wdinfo;
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
@@ -2094,10 +2094,9 @@ static int rtw_wext_p2p_enable(struct net_device *dev,
else if (*extra == '3')
init_role = P2P_ROLE_GO;

- if (_FAIL == rtw_p2p_enable(padapter, init_role)) {
- ret = -EFAULT;
- goto exit;
- }
+ ret = rtw_p2p_enable(padapter, init_role);
+ if (ret)
+ return ret;

/* set channel/bandwidth */
if (init_role != P2P_ROLE_DISABLE) {
@@ -2121,8 +2120,7 @@ static int rtw_wext_p2p_enable(struct net_device *dev,
set_channel_bwmode(padapter, channel, ch_offset, bwmode);
}

-exit:
- return ret;
+ return 0;
}

static void rtw_p2p_set_go_nego_ssid(struct net_device *dev,
--
2.37.1



2022-08-03 12:37:44

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: convert rtw_p2p_enable to correct error code semantics

On Wed, Aug 03, 2022 at 12:44:08AM +0100, Phillip Potter wrote:
> Convert the rtw_p2p_enable function to use correct error code semantics
> rather than _SUCCESS/_FAIL, and also make sure we allow these to be
> passed through properly in the one caller where we actually check the
> code, rtw_wext_p2p_enable.
>
> This change moves these functions to a clearer 'return 0;' style at the
> end of the function, and in the case of errors now returns ret instead
> of jumping to the end of the function, so that these can still be passed
> through but without using a goto to jump to a single return statement at
> the end which is less clear.
>
> This change moves the driver slowly closer to using standard error code
> semantics everywhere.
>
> Signed-off-by: Phillip Potter <[email protected]>

Looks good. Thanks!

Reviewed-by: Dan Carpenter <[email protected]>

regards,
dan carpenter


2022-08-04 20:41:10

by Philipp Hortmann

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: convert rtw_p2p_enable to correct error code semantics

On 8/3/22 01:44, Phillip Potter wrote:
> Convert the rtw_p2p_enable function to use correct error code semantics
> rather than _SUCCESS/_FAIL, and also make sure we allow these to be
> passed through properly in the one caller where we actually check the
> code, rtw_wext_p2p_enable.
>
> This change moves these functions to a clearer 'return 0;' style at the
> end of the function, and in the case of errors now returns ret instead
> of jumping to the end of the function, so that these can still be passed
> through but without using a goto to jump to a single return statement at
> the end which is less clear.
>
> This change moves the driver slowly closer to using standard error code
> semantics everywhere.
>
> Signed-off-by: Phillip Potter<[email protected]>
> ---
> drivers/staging/r8188eu/core/rtw_p2p.c | 19 ++++++++-----------
> drivers/staging/r8188eu/os_dep/ioctl_linux.c | 12 +++++-------
> 2 files changed, 13 insertions(+), 18 deletions(-)


Tested-by: Philipp Hortmann <[email protected]> # Edimax N150

2022-08-04 22:46:33

by Phillip Potter

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: convert rtw_p2p_enable to correct error code semantics

On Wed, Aug 03, 2022 at 03:11:08PM +0300, Dan Carpenter wrote:
> On Wed, Aug 03, 2022 at 12:44:08AM +0100, Phillip Potter wrote:
> > Convert the rtw_p2p_enable function to use correct error code semantics
> > rather than _SUCCESS/_FAIL, and also make sure we allow these to be
> > passed through properly in the one caller where we actually check the
> > code, rtw_wext_p2p_enable.
> >
> > This change moves these functions to a clearer 'return 0;' style at the
> > end of the function, and in the case of errors now returns ret instead
> > of jumping to the end of the function, so that these can still be passed
> > through but without using a goto to jump to a single return statement at
> > the end which is less clear.
> >
> > This change moves the driver slowly closer to using standard error code
> > semantics everywhere.
> >
> > Signed-off-by: Phillip Potter <[email protected]>
>
> Looks good. Thanks!
>
> Reviewed-by: Dan Carpenter <[email protected]>
>
> regards,
> dan carpenter
>

Thanks for the review Dan, much appreciated.

Regards,
Phil

2022-08-04 22:46:36

by Phillip Potter

[permalink] [raw]
Subject: Re: [PATCH] staging: r8188eu: convert rtw_p2p_enable to correct error code semantics

On Thu, Aug 04, 2022 at 10:26:39PM +0200, Philipp Hortmann wrote:
> On 8/3/22 01:44, Phillip Potter wrote:
> > Convert the rtw_p2p_enable function to use correct error code semantics
> > rather than _SUCCESS/_FAIL, and also make sure we allow these to be
> > passed through properly in the one caller where we actually check the
> > code, rtw_wext_p2p_enable.
> >
> > This change moves these functions to a clearer 'return 0;' style at the
> > end of the function, and in the case of errors now returns ret instead
> > of jumping to the end of the function, so that these can still be passed
> > through but without using a goto to jump to a single return statement at
> > the end which is less clear.
> >
> > This change moves the driver slowly closer to using standard error code
> > semantics everywhere.
> >
> > Signed-off-by: Phillip Potter<[email protected]>
> > ---
> > drivers/staging/r8188eu/core/rtw_p2p.c | 19 ++++++++-----------
> > drivers/staging/r8188eu/os_dep/ioctl_linux.c | 12 +++++-------
> > 2 files changed, 13 insertions(+), 18 deletions(-)
>
>
> Tested-by: Philipp Hortmann <[email protected]> # Edimax N150

Thank you for testing Philipp :-)

Regards,
Phil