All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] brcm80211: Drop unnecessary NULL check after container_of
@ 2021-05-11 23:56 Guenter Roeck
  2021-06-15 10:42 ` brcmsmac: " Kalle Valo
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2021-05-11 23:56 UTC (permalink / raw)
  To: Arend van Spriel
  Cc: Kalle Valo, David S . Miller, linux-wireless,
	brcm80211-dev-list.pdl, netdev, linux-kernel, Guenter Roeck

The parameter passed to ai_detach() is guaranteed to never be NULL
because it is checked by the caller. Consequently, the result of
container_of() on it is also never NULL, and a NULL check on it
is unnecessary. Even without that, the NULL check would still be
unnecessary because the subsequent kfree() can handle NULL arguments.
On top of all that, it is misleading to check the result of container_of()
against NULL because the position of the contained element could change,
which would make the check invalid. Remove it.

This change was made automatically with the following Coccinelle script.

@@
type t;
identifier v;
statement s;
@@

<+...
(
  t v = container_of(...);
|
  v = container_of(...);
)
  ...
  when != v
- if (\( !v \| v == NULL \) ) s
...+>

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/net/wireless/broadcom/brcm80211/brcmsmac/aiutils.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/aiutils.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/aiutils.c
index 53365977bfd6..2084b506a450 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/aiutils.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/aiutils.c
@@ -531,9 +531,6 @@ void ai_detach(struct si_pub *sih)
 
 	sii = container_of(sih, struct si_info, pub);
 
-	if (sii == NULL)
-		return;
-
 	kfree(sii);
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: brcmsmac: Drop unnecessary NULL check after container_of
  2021-05-11 23:56 [PATCH] brcm80211: Drop unnecessary NULL check after container_of Guenter Roeck
@ 2021-06-15 10:42 ` Kalle Valo
  0 siblings, 0 replies; 2+ messages in thread
From: Kalle Valo @ 2021-06-15 10:42 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Arend van Spriel, David S . Miller, linux-wireless,
	brcm80211-dev-list.pdl, netdev, linux-kernel, Guenter Roeck

Guenter Roeck <linux@roeck-us.net> wrote:

> The parameter passed to ai_detach() is guaranteed to never be NULL
> because it is checked by the caller. Consequently, the result of
> container_of() on it is also never NULL, and a NULL check on it
> is unnecessary. Even without that, the NULL check would still be
> unnecessary because the subsequent kfree() can handle NULL arguments.
> On top of all that, it is misleading to check the result of container_of()
> against NULL because the position of the contained element could change,
> which would make the check invalid. Remove it.
> 
> This change was made automatically with the following Coccinelle script.
> 
> @@
> type t;
> identifier v;
> statement s;
> @@
> 
> <+...
> (
>   t v = container_of(...);
> |
>   v = container_of(...);
> )
>   ...
>   when != v
> - if (\( !v \| v == NULL \) ) s
> ...+>
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Patch applied to wireless-drivers-next.git, thanks.

34fe7038a3b3 brcmsmac: Drop unnecessary NULL check after container_of

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20210511235629.1686038-1-linux@roeck-us.net/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-15 10:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 23:56 [PATCH] brcm80211: Drop unnecessary NULL check after container_of Guenter Roeck
2021-06-15 10:42 ` brcmsmac: " Kalle Valo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.