ipvlan: Remove NULL check before dev_{put, hold}

Message ID 20230511072119.72536-1-yang.lee@linux.alibaba.com
State New
Headers
Series ipvlan: Remove NULL check before dev_{put, hold} |

Commit Message

Yang Li May 11, 2023, 7:21 a.m. UTC
  The call netdev_{put, hold} of dev_{put, hold} will check NULL,
so there is no need to check before using dev_{put, hold},
remove it to silence the warning:

./drivers/net/ipvlan/ipvlan_core.c:559:3-11: WARNING: NULL check before dev_{put, hold} functions is not needed.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4930
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
 drivers/net/ipvlan/ipvlan_core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Simon Horman May 11, 2023, 12:56 p.m. UTC | #1
On Thu, May 11, 2023 at 03:21:19PM +0800, Yang Li wrote:
> The call netdev_{put, hold} of dev_{put, hold} will check NULL,
> so there is no need to check before using dev_{put, hold},
> remove it to silence the warning:
> 
> ./drivers/net/ipvlan/ipvlan_core.c:559:3-11: WARNING: NULL check before dev_{put, hold} functions is not needed.
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4930
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>
  
Stephen Hemminger May 11, 2023, 3:54 p.m. UTC | #2
On Thu, 11 May 2023 15:21:19 +0800
Yang Li <yang.lee@linux.alibaba.com> wrote:

> The call netdev_{put, hold} of dev_{put, hold} will check NULL,
> so there is no need to check before using dev_{put, hold},
> remove it to silence the warning:
> 
> ./drivers/net/ipvlan/ipvlan_core.c:559:3-11: WARNING: NULL check before dev_{put, hold} functions is not needed.
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4930
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>

Maybe add new coccinelle script for this? scripts/free/dev_hold.cocci?
  
patchwork-bot+netdevbpf@kernel.org May 12, 2023, 8 a.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Thu, 11 May 2023 15:21:19 +0800 you wrote:
> The call netdev_{put, hold} of dev_{put, hold} will check NULL,
> so there is no need to check before using dev_{put, hold},
> remove it to silence the warning:
> 
> ./drivers/net/ipvlan/ipvlan_core.c:559:3-11: WARNING: NULL check before dev_{put, hold} functions is not needed.
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4930
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
> 
> [...]

Here is the summary with links:
  - ipvlan: Remove NULL check before dev_{put, hold}
    https://git.kernel.org/netdev/net-next/c/0fae8847563b

You are awesome, thank you!
  
Simon Horman May 12, 2023, 2:08 p.m. UTC | #4
On Thu, May 11, 2023 at 08:54:53AM -0700, Stephen Hemminger wrote:
> On Thu, 11 May 2023 15:21:19 +0800
> Yang Li <yang.lee@linux.alibaba.com> wrote:
> 
> > The call netdev_{put, hold} of dev_{put, hold} will check NULL,
> > so there is no need to check before using dev_{put, hold},
> > remove it to silence the warning:
> > 
> > ./drivers/net/ipvlan/ipvlan_core.c:559:3-11: WARNING: NULL check before dev_{put, hold} functions is not needed.
> > 
> > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4930
> > Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
> 
> Maybe add new coccinelle script for this? scripts/free/dev_hold.cocci?

FWIIW, I observe that Coccinelle flags this problem as per the log above.
But perhaps I am missing your point.
  

Patch

diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c
index ab5133eb1d51..a8977965a7f2 100644
--- a/drivers/net/ipvlan/ipvlan_core.c
+++ b/drivers/net/ipvlan/ipvlan_core.c
@@ -555,8 +555,7 @@  static void ipvlan_multicast_enqueue(struct ipvl_port *port,
 
 	spin_lock(&port->backlog.lock);
 	if (skb_queue_len(&port->backlog) < IPVLAN_QBACKLOG_LIMIT) {
-		if (skb->dev)
-			dev_hold(skb->dev);
+		dev_hold(skb->dev);
 		__skb_queue_tail(&port->backlog, skb);
 		spin_unlock(&port->backlog.lock);
 		schedule_work(&port->wq);