[PATCH] staging: r8188eu: remove unnecessary null check

cgel.zte@gmail.com posted 1 patch 3 years, 7 months ago
drivers/staging/r8188eu/core/rtw_mlme.c | 4 ----
1 file changed, 4 deletions(-)
[PATCH] staging: r8188eu: remove unnecessary null check
Posted by cgel.zte@gmail.com 3 years, 7 months ago
From: Minghao Chi <chi.minghao@zte.com.cn>

container_of is never null, so this null check is
unnecessary.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
---
 drivers/staging/r8188eu/core/rtw_mlme.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_mlme.c b/drivers/staging/r8188eu/core/rtw_mlme.c
index 56c8bd5f4c60..d089da7e90e0 100644
--- a/drivers/staging/r8188eu/core/rtw_mlme.c
+++ b/drivers/staging/r8188eu/core/rtw_mlme.c
@@ -1442,10 +1442,6 @@ int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv)
 	pmlmepriv->pscanned = phead->next;
 	while (phead != pmlmepriv->pscanned) {
 		pnetwork = container_of(pmlmepriv->pscanned, struct wlan_network, list);
-		if (!pnetwork) {
-			ret = _FAIL;
-			goto exit;
-		}
 		pmlmepriv->pscanned = pmlmepriv->pscanned->next;
 		rtw_check_join_candidate(pmlmepriv, &candidate, pnetwork);
 	}
-- 
2.25.1
Re: [PATCH] staging: r8188eu: remove unnecessary null check
Posted by Dan Carpenter 3 years, 7 months ago
On Wed, Aug 24, 2022 at 08:03:50AM +0000, cgel.zte@gmail.com wrote:
> From: Minghao Chi <chi.minghao@zte.com.cn>
> 
> container_of is never null, so this null check is
> unnecessary.
> 

I can't Ack a patch with this commit message because container_of()
*CAN* be NULL.  Here, it requires two things:
1) That ->list is the first struct member of struct wlan_network which
   is true.
2) That "pmlmepriv->pscanned" is NULL.  Which I have not looked at.

It's really ugly to check container_of() for NULL but some people do it
deliberately.  Some people also will add a build time assert to ensure
that ->list is always the first element so that the check always works.

regards,
dan carpenter