All of lore.kernel.org
 help / color / mirror / Atom feed
From: <zhang.songyi@zte.com.cn>
To: <yishaih@nvidia.com>
Cc: <jgg@ziepe.ca>, <leon@kernel.org>, <linux-rdma@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <zhang.songyi@zte.com.cn>
Subject: [PATCH linux-next] RDMA/mlx4: NULL check before dev_{put, hold} functions is not
 needed
Date: Wed, 23 Nov 2022 17:08:25 +0800 (CST)	[thread overview]
Message-ID: <202211231708254077305@zte.com.cn> (raw)

From: zhang songyi <zhang.songyi@zte.com.cn>

The call netdev_{put, hold} of dev_{put, hold} will check NULL,
so there is no need to check before using dev_{put, hold}.

Fix the following coccicheck warnings:
/drivers/infiniband/hw/mlx4/main.c:1311:2-10: WARNING:
WARNING  NULL check before dev_{put, hold} functions is not needed.

/drivers/infiniband/hw/mlx4/main.c:148:2-10: WARNING:
WARNING  NULL check before dev_{put, hold} functions is not needed.

/drivers/infiniband/hw/mlx4/main.c:1959:3-11: WARNING:
WARNING  NULL check before dev_{put, hold} functions is not needed.

/drivers/infiniband/hw/mlx4/main.c:1962:3-10: WARNING:
WARNING  NULL check before dev_{put, hold} functions is not needed.

Signed-off-by: zhang songyi <zhang.songyi@zte.com.cn>
---
 drivers/infiniband/hw/mlx4/main.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index ba47874f90d3..dceebcd885bb 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -144,8 +144,7 @@ static struct net_device *mlx4_ib_get_netdev(struct ib_device *device,
                        }
                }
        }
-       if (dev)
-               dev_hold(dev);
+       dev_hold(dev);

        rcu_read_unlock();
        return dev;
@@ -1307,8 +1306,7 @@ int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,

        spin_lock_bh(&mdev->iboe.lock);
        ndev = mdev->iboe.netdevs[mqp->port - 1];
-       if (ndev)
-               dev_hold(ndev);
+       dev_hold(ndev);
        spin_unlock_bh(&mdev->iboe.lock);

        if (ndev) {
@@ -1955,11 +1953,9 @@ static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
        if (ge) {
                spin_lock_bh(&mdev->iboe.lock);
                ndev = ge->added ? mdev->iboe.netdevs[ge->port - 1] : NULL;
-               if (ndev)
-                       dev_hold(ndev);
+               dev_hold(ndev);
                spin_unlock_bh(&mdev->iboe.lock);
-               if (ndev)
-                       dev_put(ndev);
+               dev_put(ndev);
                list_del(&ge->list);
                kfree(ge);
        } else
--
2.15.2

             reply	other threads:[~2022-11-23  9:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23  9:08 zhang.songyi [this message]
2022-11-28  9:50 ` [PATCH linux-next] RDMA/mlx4: NULL check before dev_{put, hold} functions is not? needed Leon Romanovsky
  -- strict thread matches above, loose matches on Subject: below --
2022-11-28 10:58 [PATCH linux-next] RDMA/mlx4: NULL check before dev_{put, hold} functions is not needed zhang.songyi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202211231708254077305@zte.com.cn \
    --to=zhang.songyi@zte.com.cn \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=yishaih@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.