All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: caif: Drop unnecessary NULL check after container_of
@ 2021-05-13 16:58 Guenter Roeck
  2021-05-13 23:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2021-05-13 16:58 UTC (permalink / raw)
  To: David S . Miller; +Cc: Jakub Kicinski, netdev, linux-kernel, Guenter Roeck

The first parameter passed to chnl_recv_cb() can never be NULL since all
callers dereferenced it. Consequently, container_of() on it is also never
NULL, even though the reference into the structure points to the first
element of the structure. The NULL check is therefore unnecessary.
On top of that, it is misleading to perform a NULL check on the result of
container_of() because the position of the contained element could change,
which would make the test invalid. Remove the unnecessary NULL check.

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>
---
 net/caif/chnl_net.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
index fadc7c8a3107..37b67194c0df 100644
--- a/net/caif/chnl_net.c
+++ b/net/caif/chnl_net.c
@@ -76,8 +76,6 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
 	u8 buf;
 
 	priv = container_of(layr, struct chnl_net, chnl);
-	if (!priv)
-		return -EINVAL;
 
 	skb = (struct sk_buff *) cfpkt_tonative(pkt);
 
-- 
2.25.1


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

* Re: [PATCH] net: caif: Drop unnecessary NULL check after container_of
  2021-05-13 16:58 [PATCH] net: caif: Drop unnecessary NULL check after container_of Guenter Roeck
@ 2021-05-13 23:00 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-05-13 23:00 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: davem, kuba, netdev, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Thu, 13 May 2021 09:58:40 -0700 you wrote:
> The first parameter passed to chnl_recv_cb() can never be NULL since all
> callers dereferenced it. Consequently, container_of() on it is also never
> NULL, even though the reference into the structure points to the first
> element of the structure. The NULL check is therefore unnecessary.
> On top of that, it is misleading to perform a NULL check on the result of
> container_of() because the position of the contained element could change,
> which would make the test invalid. Remove the unnecessary NULL check.
> 
> [...]

Here is the summary with links:
  - net: caif: Drop unnecessary NULL check after container_of
    https://git.kernel.org/netdev/net-next/c/0f3ee280331e

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-05-13 23:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-13 16:58 [PATCH] net: caif: Drop unnecessary NULL check after container_of Guenter Roeck
2021-05-13 23:00 ` patchwork-bot+netdevbpf

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.