2022-06-20 09:20:59

by Kate Hsuan

[permalink] [raw]
Subject: [PATCH v1] staging: r8188eu: an incorrect return value made the function always return fail

Since _SUCCESS (1) and _FAIL (0) are used to indicate the status of the
functions. The previous commit 8ae7bf782eacad803f752c83a183393b0a67127b
fixed and prevented dereferencing a NULL pointer through checking the
return pointer. The NULL pointer check work properly but the return
values (-ENOMEM on fail and 0 on success). This work fixed the return
values to make sure the caller function will return the correct status.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=2097526
Signed-off-by: Kate Hsuan <[email protected]>
---
drivers/staging/r8188eu/core/rtw_xmit.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c
index f4e9f6102539..2f8720db21d9 100644
--- a/drivers/staging/r8188eu/core/rtw_xmit.c
+++ b/drivers/staging/r8188eu/core/rtw_xmit.c
@@ -180,10 +180,8 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;

res = rtw_alloc_hwxmits(padapter);
- if (res) {
- res = _FAIL;
+ if (res == _FAIL)
goto exit;
- }

rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);

@@ -1510,7 +1508,7 @@ int rtw_alloc_hwxmits(struct adapter *padapter)

pxmitpriv->hwxmits = kzalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry, GFP_KERNEL);
if (!pxmitpriv->hwxmits)
- return -ENOMEM;
+ return _FAIL;

hwxmits = pxmitpriv->hwxmits;

@@ -1528,7 +1526,7 @@ int rtw_alloc_hwxmits(struct adapter *padapter)
} else {
}

- return 0;
+ return _SUCCESS;
}

void rtw_free_hwxmits(struct adapter *padapter)
--
2.36.1


2022-06-20 14:59:33

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH v1] staging: r8188eu: an incorrect return value made the function always return fail

On 6/20/22 03:54, Kate Hsuan wrote:
> Since _SUCCESS (1) and _FAIL (0) are used to indicate the status of the
> functions. The previous commit 8ae7bf782eacad803f752c83a183393b0a67127b
> fixed and prevented dereferencing a NULL pointer through checking the
> return pointer. The NULL pointer check work properly but the return
> values (-ENOMEM on fail and 0 on success). This work fixed the return
> values to make sure the caller function will return the correct status.
>
> BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=2097526
> Signed-off-by: Kate Hsuan <[email protected]>
> ---
> drivers/staging/r8188eu/core/rtw_xmit.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c
> index f4e9f6102539..2f8720db21d9 100644
> --- a/drivers/staging/r8188eu/core/rtw_xmit.c
> +++ b/drivers/staging/r8188eu/core/rtw_xmit.c
> @@ -180,10 +180,8 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
> pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
>
> res = rtw_alloc_hwxmits(padapter);
> - if (res) {
> - res = _FAIL;
> + if (res == _FAIL)
> goto exit;
> - }
>
> rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
>

This problem was fixed in mid May with commit 5b7419ae1d20 ("staging: r8188eu:
fix rtw_alloc_hwxmits error detection for now"). The fix was

@@ -178,8 +178,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct
adapter *padapter)

pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;

- res = rtw_alloc_hwxmits(padapter);
- if (res) {
+ if (rtw_alloc_hwxmits(padapter)) {
res = _FAIL;
goto exit;
}

The "for now" part is that Phillip plans to get rid of _FAIL and _SUCCESS, and
replace the logic with a normal 1 for fail, etc.; however, this will be a major
change that must be done carefully.

In any case NACK for this patch.

Larry



2022-06-22 12:56:18

by Phillip Potter

[permalink] [raw]
Subject: Re: [PATCH v1] staging: r8188eu: an incorrect return value made the function always return fail

On Mon, Jun 20, 2022 at 09:05:17AM -0500, Larry Finger wrote:
>
> The "for now" part is that Phillip plans to get rid of _FAIL and _SUCCESS,
> and replace the logic with a normal 1 for fail, etc.; however, this will be
> a major change that must be done carefully.
>
> In any case NACK for this patch.
>
> Larry
>
>
>

Hi all,

I would be happy to work on purging _FAIL and _SUCCESS from the driver
by all means - definitely a worthwhile goal. I know Pavel said he
might take a look too though - copying him in therefore to see if we can
coordinate an approach - happy to do as much or as little as desired.

Regards,
Phil