public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Kamal Heib <kheib@redhat.com>
To: linux-rdma@vger.kernel.org
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
	Kamal Heib <kheib@redhat.com>
Subject: [for-rc] RDMA/core: Make sure the netdev is not already associated
Date: Mon, 12 Dec 2022 11:22:40 +0200	[thread overview]
Message-ID: <20221212092240.21694-1-kheib@redhat.com> (raw)

Make sure that the requested net_device is not already associated with
an ib_device before trying to create a new ib_device that will be
associated with the same net_device, this is needed to avoid creating
siw and rxe devices that will be associated with the same net_device.

Fixes: 3856ec4b93c9 ("RDMA/core: Add RDMA_NLDEV_CMD_NEWLINK/DELLINK support")
Signed-off-by: Kamal Heib <kheib@redhat.com>
---
 drivers/infiniband/core/nldev.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index a981ac2f0975..376c9e158556 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -1696,6 +1696,7 @@ static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 	const struct rdma_link_ops *ops;
 	char ndev_name[IFNAMSIZ];
 	struct net_device *ndev;
+	struct ib_device *ibdev;
 	char type[IFNAMSIZ];
 	int err;
 
@@ -1718,6 +1719,12 @@ static int nldev_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (!ndev)
 		return -ENODEV;
 
+	ibdev = ib_device_get_by_netdev(ndev, RDMA_DRIVER_UNKNOWN);
+	if (ibdev) {
+		ib_device_put(ibdev);
+		return -EINVAL;
+	}
+
 	down_read(&link_ops_rwsem);
 	ops = link_ops_get(type);
 #ifdef CONFIG_MODULES
-- 
2.38.1


             reply	other threads:[~2022-12-12  9:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-12  9:22 Kamal Heib [this message]
2022-12-12 10:16 ` [for-rc] RDMA/core: Make sure the netdev is not already associated Leon Romanovsky
2022-12-12 12:51 ` Jason Gunthorpe
2022-12-12 13:18   ` Leon Romanovsky

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=20221212092240.21694-1-kheib@redhat.com \
    --to=kheib@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox