linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/sched: taprio: Drop unnecessary NULL check after container_of
@ 2021-05-11 20:54 Guenter Roeck
  2021-05-11 23:33 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2021-05-11 20:54 UTC (permalink / raw)
  To: Jamal Hadi Salim
  Cc: Cong Wang, Jiri Pirko, David S . Miller, Jakub Kicinski, netdev,
	linux-kernel, Guenter Roeck

The rcu_head pointer passed to taprio_free_sched_cb is never NULL.
That means that the result of container_of() operations on it is also
never NULL, even though rcu_head is the first element of the structure
embedding it. 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 check 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/sched/sch_taprio.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 5c91df52b8c2..71e8a7a84841 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -114,9 +114,6 @@ static void taprio_free_sched_cb(struct rcu_head *head)
 	struct sched_gate_list *sched = container_of(head, struct sched_gate_list, rcu);
 	struct sched_entry *entry, *n;
 
-	if (!sched)
-		return;
-
 	list_for_each_entry_safe(entry, n, &sched->entries, list) {
 		list_del(&entry->list);
 		kfree(entry);
-- 
2.25.1


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

* Re: [PATCH] net/sched: taprio: Drop unnecessary NULL check after container_of
  2021-05-11 20:54 [PATCH] net/sched: taprio: Drop unnecessary NULL check after container_of Guenter Roeck
@ 2021-05-11 23:33 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-05-11 23:33 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: jhs, xiyou.wangcong, jiri, davem, kuba, netdev, linux-kernel

Hello:

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

On Tue, 11 May 2021 13:54:49 -0700 you wrote:
> The rcu_head pointer passed to taprio_free_sched_cb is never NULL.
> That means that the result of container_of() operations on it is also
> never NULL, even though rcu_head is the first element of the structure
> embedding it. 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 check invalid. Remove the
> unnecessary NULL check.
> 
> [...]

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

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-11 23:33 UTC | newest]

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).