Skip to contentSkip to conversation

staging: r8188eu: an incorrect return value made the function always return fail

PATCH In review Kate Hsuan 5 participants 7 messages Jun 20, 2022 – Jun 22, 2022 Staging

lore
Share & tools
lore

Kate Hsuan

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/staging/r8188eu/core/rtw_xmit.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_xmit.c +3 -5
index f4e9f6102539..2f8720db21d9 100644
@@ -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)
Signature · 1 line
2.36.1
#1 lore raw
Quoted 2 lines · Kate Hsuan

Since _SUCCESS (1) and _FAIL (0) are used to indicate the status of the functions. The previous commit 8ae7bf782eacad803f752c83a183393b0a67127b

In the future, please reference commit ids as the documentation asks, as it's a much nicer way to understand things. Also this commit id is not in Linus's tree or any tree that I can see, where did it come from?

Quoted 28 lines

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.

---
 drivers/staging/r8188eu/core/rtw_xmit.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_xmit.c +1 -3
index f4e9f6102539..2f8720db21d9 100644
@@ -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);
 

drivers/staging/r8188eu/core/rtw_xmit.c int rtw_alloc_hwxmits(struct adapter *padapter) · line 1511

Quoted 5 lines
drivers/staging/r8188eu/core/rtw_xmit.c +1 -1
@@ -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;

No, please let's fix up the callers to properly detect normal kernel error values and get rid of all of the crazy _FAIL and _SUCCESS values in this driver.

drivers/staging/r8188eu/core/rtw_xmit.c int rtw_alloc_hwxmits(struct adapter *padapter) · line 1529

Quoted 9 lines
drivers/staging/r8188eu/core/rtw_xmit.c +1 -1
 	hwxmits = pxmitpriv->hwxmits;
 
@@ -1528,7 +1526,7 @@ int rtw_alloc_hwxmits(struct adapter *padapter)
 	} else {
 	}
 
-	return 0;
+	return _SUCCESS;

Same here, fix up the callers if they are checking this incorrectly.

thanks,

greg k-h

author
#2 lore raw
Quoted 8 lines · Greg Kroah-Hartman
Quoted 2 lines · Kate Hsuan

Since _SUCCESS (1) and _FAIL (0) are used to indicate the status of the functions. The previous commit 8ae7bf782eacad803f752c83a183393b0a67127b

In the future, please reference commit ids as the documentation asks, as it's a much nicer way to understand things. Also this commit id is not in Linus's tree or any tree that I can see, where did it come from?

Sorry about this. I'll improve this in my v2 patch.

Quoted 30 lines
Quoted 30 lines

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.

---
 drivers/staging/r8188eu/core/rtw_xmit.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_xmit.c +1 -3
index f4e9f6102539..2f8720db21d9 100644
@@ -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)
 
Quoted 8 lines

drivers/staging/r8188eu/core/rtw_xmit.c int rtw_alloc_hwxmits(struct adapter *padapter) · line 1511

Quoted 4 lines
drivers/staging/r8188eu/core/rtw_xmit.c +1 -1
      pxmitpriv->hwxmits = kzalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry, GFP_KERNEL);
      if (!pxmitpriv->hwxmits)
-             return -ENOMEM;
+             return _FAIL;

No, please let's fix up the callers to properly detect normal kernel error values and get rid of all of the crazy _FAIL and _SUCCESS values in this driver.

Okay.

Quoted 8 lines
Quoted 8 lines
drivers/staging/r8188eu/core/rtw_xmit.c +0 -0
      hwxmits = pxmitpriv->hwxmits;
 
@@ -1528,7 +1526,7 @@ int rtw_alloc_hwxmits(struct adapter *padapter)
      } else {
      }
 
Quoted 9 lines

drivers/staging/r8188eu/core/rtw_xmit.c int rtw_alloc_hwxmits(struct adapter *padapter) · line 1529

Quoted 2 lines
drivers/staging/r8188eu/core/rtw_xmit.c +1 -1
-     return 0;
+     return _SUCCESS;

Same here, fix up the callers if they are checking this incorrectly.

thanks,

greg k-h

Thank you :)

Signature · 2 lines
BR,
Kate
#3 lore raw
In reply to Kate Hsuan

Hi Kate,

Good catch!

Quoted 2 lines · Kate Hsuan

Since _SUCCESS (1) and _FAIL (0) are used to indicate the status of the functions. The previous commit 8ae7bf782eacad803f752c83a183393b0a67127b

This is the commit hash from one of the stable series backports, you should always use the commit hash from Linus' master branch which is f94b47c6bde6 and the format for referencing commits in a commit-message is:

commit <12 char hash> ("commit subject")

so in this case this should have been:

commit f94b47c6bde6 ("staging: r8188eu: add check for kzalloc")

Note that checkpatch.pl would have complained about the wrong format (but not the wrong hash)

Quoted 7 lines

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.

This should have a fixes tag:

Fixes f94b47c6bde6 ("staging: r8188eu: add check for kzalloc")

But while looking up the torvalds/master branch hash I noticed someone alreayd beat you to it. Linus' master already has a fix for this:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/staging/r8188eu?id=5b7419ae1d208cab1e2826d473d8dab045aa75c7

So this patch can be dropped since it is a duplicate.

Regards,

hans

Quoted 38 lines
---
 drivers/staging/r8188eu/core/rtw_xmit.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_xmit.c +3 -5
index f4e9f6102539..2f8720db21d9 100644
@@ -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)
author
#4 lore raw
Quoted 13 lines · Hans de Goede

Hi Kate,

Good catch!

Quoted 2 lines · Kate Hsuan

Since _SUCCESS (1) and _FAIL (0) are used to indicate the status of the functions. The previous commit 8ae7bf782eacad803f752c83a183393b0a67127b

This is the commit hash from one of the stable series backports, you should always use the commit hash from Linus' master branch which is f94b47c6bde6 and the format for referencing commits in a commit-message is:

Quoted 8 lines

commit <12 char hash> ("commit subject")

so in this case this should have been:

commit f94b47c6bde6 ("staging: r8188eu: add check for kzalloc")

Note that checkpatch.pl would have complained about the wrong format (but not the wrong hash)

Thanks for this. I'll improve my commit message.

Quoted 13 lines
Quoted 8 lines

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.

This should have a fixes tag:

Fixes f94b47c6bde6 ("staging: r8188eu: add check for kzalloc")
Quoted 7 lines

But while looking up the torvalds/master branch hash I noticed someone alreayd beat you to it. Linus' master already has a fix for this:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/staging/r8188eu?id=5b7419ae1d208cab1e2826d473d8dab045aa75c7

So this patch can be dropped since it is a duplicate.

Ah~ I have to check before starting to fix it.

Thank you :)

Quoted 46 lines

Regards,

hans

Quoted 38 lines
---
 drivers/staging/r8188eu/core/rtw_xmit.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_xmit.c +3 -5
index f4e9f6102539..2f8720db21d9 100644
@@ -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)
Signature · 2 lines
BR,
Kate
#5 lore raw
In reply to Kate Hsuan
Quoted 19 lines · Kate Hsuan

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.

---
  drivers/staging/r8188eu/core/rtw_xmit.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_xmit.c +0 -0
index f4e9f6102539..2f8720db21d9 100644
@@ -180,10 +180,8 @@ s32	_rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
  	pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;

drivers/staging/r8188eu/core/rtw_xmit.c s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) · line 187

Quoted 10 lines
drivers/staging/r8188eu/core/rtw_xmit.c +1 -3
 
  	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

#6 lore raw
Quoted 11 lines · Larry Finger

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