diff mbox series

[rdma-next] RDMA/device: Return error earlier if port in not valid

Message ID 022047a8b16988fc88d4426da50bf60a4833311b.1719235449.git.leon@kernel.org (mailing list archive)
State Accepted
Headers show
Series [rdma-next] RDMA/device: Return error earlier if port in not valid | expand

Commit Message

Leon Romanovsky June 24, 2024, 1:24 p.m. UTC
From: Leon Romanovsky <leonro@nvidia.com>

There is no need to allocate port data if port provided is not valid.

Fixes: c2261dd76b54 ("RDMA/device: Add ib_device_set_netdev() as an alternative to get_netdev")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/core/device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Leon Romanovsky July 1, 2024, 11:32 a.m. UTC | #1
On Mon, 24 Jun 2024 16:24:32 +0300, Leon Romanovsky wrote:
> There is no need to allocate port data if port provided is not valid.
> 
> 

Applied, thanks!

[1/1] RDMA/device: Return error earlier if port in not valid
      https://git.kernel.org/rdma/rdma/c/917918f57a7b13

Best regards,
diff mbox series

Patch

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 8547cab50b23..7aaf2b4c1844 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -2163,6 +2163,9 @@  int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
 	unsigned long flags;
 	int ret;
 
+	if (!rdma_is_port_valid(ib_dev, port))
+		return -EINVAL;
+
 	/*
 	 * Drivers wish to call this before ib_register_driver, so we have to
 	 * setup the port data early.
@@ -2171,9 +2174,6 @@  int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
 	if (ret)
 		return ret;
 
-	if (!rdma_is_port_valid(ib_dev, port))
-		return -EINVAL;
-
 	pdata = &ib_dev->port_data[port];
 	spin_lock_irqsave(&pdata->netdev_lock, flags);
 	old_ndev = rcu_dereference_protected(