From patchwork Tue Apr 4 07:29:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Li X-Patchwork-Id: 78901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2851410vqo; Tue, 4 Apr 2023 01:03:11 -0700 (PDT) X-Google-Smtp-Source: AKy350aeRCUHWc3pq9O83a9+sRYn2KKw0mv3ZtAZ8gOKioYFJ1ZRmiZMLHZiSb29DtB+y75s8uWE X-Received: by 2002:a17:906:858f:b0:884:930:b017 with SMTP id v15-20020a170906858f00b008840930b017mr1592527ejx.60.1680595390760; Tue, 04 Apr 2023 01:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680595390; cv=none; d=google.com; s=arc-20160816; b=eZvw1VmkxmaKtblfgvFA4+rBeFcTKMFON8RmOo80O4Uj8LvM9Td9fYIbnsj8XroRRA kxAtps7aKOz4DBuodgyDPK0AzdWJg2cVAI80GLmKPnwCQf/QJ0kqmUaG5l+9hd9QufHn owpQFkqw/DvZ9LrOwmJkd3xhCnjlkJ9ExMk6shqDj7Nbc4qmZbAkYpO0joAe4RSFGKYF 8GR7QyyF2GlFa8atvVpRh+EdJjwccyAKhr4oj4d/MKLQawA/VoJuJWo3kciiB2UlMMbG OHPxT9xvbBGBhJkvZIPJJrrSwz8/uoUz1y1+q6DTsFnqiiJEwxk+1XuqkVRumciBhvBQ vHkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=yhYJk5BAVHyqMOO0K36qVTsOtlFTT3aXKoEgyv/QT2E=; b=HJuD7Q0hOe4IBC965FlPizYuNoDhh8Ayd98zeFAJRcwX23R+Ioqyi5kFfHpzWK/wuq pkUidqp5+HtgCouRkNAsXHskPXK7vTUQIRkIO+fhzz1CYJ4x7UbLJTSvtX50saaBJWDm lChKVYxe6l2TTPjOWjKCBDMflYTZRw/RdiSy+Rqy1KhKSyK5mwg4QOT04ypPAhlX4MXm LwMZzQU1L3sqd7PN11ArHpy5Ums6Njlimn06EF/PYog6lnv5liQVTr3gs7bMm/pDLmm1 ruxE0yNn+t0jCED9d2/d5n2dh5E3jM3GKxIKXjs+TgYLcLtpqIn5Nc9d8yfuoX2g0YZG 2lZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vv8-20020a170907a68800b00947bf51effbsi661762ejc.580.2023.04.04.01.02.47; Tue, 04 Apr 2023 01:03:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233832AbjDDHaR (ORCPT + 99 others); Tue, 4 Apr 2023 03:30:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233899AbjDDH36 (ORCPT ); Tue, 4 Apr 2023 03:29:58 -0400 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61A27B7; Tue, 4 Apr 2023 00:29:38 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R531e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=yang.lee@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VfKsUhm_1680593374; Received: from localhost(mailfrom:yang.lee@linux.alibaba.com fp:SMTPD_---0VfKsUhm_1680593374) by smtp.aliyun-inc.com; Tue, 04 Apr 2023 15:29:34 +0800 From: Yang Li To: davem@davemloft.net Cc: edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, saeedm@nvidia.com, leon@kernel.org, netdev@vger.kernel.org, simon.horman@corigine.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Li , Abaci Robot Subject: [PATCH net-next v3] net/mlx5e: Remove NULL check before dev_{put, hold} Date: Tue, 4 Apr 2023 15:29:32 +0800 Message-Id: <20230404072932.88383-1-yang.lee@linux.alibaba.com> X-Mailer: git-send-email 2.20.1.7.g153144c MIME-Version: 1.0 X-Spam-Status: No, score=-8.0 required=5.0 tests=ENV_AND_HDR_SPF_MATCH, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762231992665441077?= X-GMAIL-MSGID: =?utf-8?q?1762231992665441077?= ./drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c:35:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed. ./drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c:72:2-10: WARNING: NULL check before dev_{put, hold} functions is not needed. ./drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c:80:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed. ./drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:35:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed. ./drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:734:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed. ./drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:769:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed. ./drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:1450:2-10: WARNING: NULL check before dev_{put, hold} functions is not needed. Reported-by: Abaci Robot Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4667 Signed-off-by: Yang Li Reviewed-by: Leon Romanovsky --- change in v3: --According to Leon's suggestion, do this cleanup for whole driver. drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c | 9 +++------ .../net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 10 +++------- drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c | 3 +-- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c index 00a04fdd756f..20f6e7ed7475 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c @@ -31,8 +31,7 @@ static void mlx5e_tc_tun_route_attr_cleanup(struct mlx5e_tc_tun_route_attr *attr { if (attr->n) neigh_release(attr->n); - if (attr->route_dev) - dev_put(attr->route_dev); + dev_put(attr->route_dev); } struct mlx5e_tc_tunnel *mlx5e_get_tc_tun(struct net_device *tunnel_dev) @@ -68,16 +67,14 @@ static int get_route_and_out_devs(struct mlx5e_priv *priv, * while holding rcu read lock. Take the net_device for correctness * sake. */ - if (uplink_upper) - dev_hold(uplink_upper); + dev_hold(uplink_upper); rcu_read_unlock(); dst_is_lag_dev = (uplink_upper && netif_is_lag_master(uplink_upper) && real_dev == uplink_upper && mlx5_lag_is_sriov(priv->mdev)); - if (uplink_upper) - dev_put(uplink_upper); + dev_put(uplink_upper); /* if the egress device isn't on the same HW e-switch or * it's a LAG device, use the uplink diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c index 20c2d2ecaf93..2cb2ba857155 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c @@ -32,9 +32,7 @@ static int mlx5e_set_int_port_tunnel(struct mlx5e_priv *priv, &attr->action, out_index); out: - if (route_dev) - dev_put(route_dev); - + dev_put(route_dev); return err; } @@ -730,8 +728,7 @@ static int mlx5e_set_vf_tunnel(struct mlx5_eswitch *esw, } out: - if (route_dev) - dev_put(route_dev); + dev_put(route_dev); return err; } @@ -765,8 +762,7 @@ static int mlx5e_update_vf_tunnel(struct mlx5_eswitch *esw, mlx5e_tc_match_to_reg_mod_hdr_change(esw->dev, mod_hdr_acts, VPORT_TO_REG, act_id, data); out: - if (route_dev) - dev_put(route_dev); + dev_put(route_dev); return err; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c index 5d331b940f4d..f0216bf6e215 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c @@ -1446,8 +1446,7 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev) } else { ndev = ldev->pf[MLX5_LAG_P1].netdev; } - if (ndev) - dev_hold(ndev); + dev_hold(ndev); unlock: spin_unlock_irqrestore(&lag_lock, flags);