Skip to contentSkip to conversation

RDMA/nldev: Put the device when dellink fails

PATCH Applied lirongqing 2 participants 2 messages Sep 3 – Sep 6 InfiniBand

lore
Share & tools
lore

lirongqing

author
#0 lore raw

PATCH 1/1 RDMA/nldev: Put the device when dellink fails

From: Li RongQing <[email protected]>

nldev_dellink() takes a device reference through ib_device_get_by_index() and normally hands it over to ib_unregister_device_and_put(). The error path of the ->dellink callback returns without releasing it, so the reference is leaked.

Once that happens, any later unregistration of the device blocks forever, because disable_device() drops its own reference and then waits for the refcount to drain. No in-tree driver returns an error from ->dellink today, so the leak is currently latent.

Put the device before returning the error.

Fixes a60e3f3d6fba ("RDMA/nldev: Add dellink function pointer")
---
 drivers/infiniband/core/nldev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/infiniband/core/nldev.c +3 -1
index a4014a2..a1542ed 100644
@@ -1895,8 +1895,10 @@ static int nldev_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
 		mutex_lock(&nldev_dellink_mutex);
 		err = device->link_ops->dellink(device);
 		mutex_unlock(&nldev_dellink_mutex);
-		if (err)
+		if (err) {
+			ib_device_put(device);
 			return err;
+		}
 	}
 
 	ib_unregister_device_and_put(device);
Signature · 1 line
2.9.4
#1 lore raw
Quoted 11 lines · lirongqing

nldev_dellink() takes a device reference through ib_device_get_by_index() and normally hands it over to ib_unregister_device_and_put(). The error path of the ->dellink callback returns without releasing it, so the reference is leaked.

Once that happens, any later unregistration of the device blocks forever, because disable_device() drops its own reference and then waits for the refcount to drain. No in-tree driver returns an error from ->dellink today, so the leak is currently latent.

[...]

Applied, thanks!

[1/1] RDMA/nldev: Put the device when dellink fails

      https://git.kernel.org/rdma/rdma/c/0ff7fcd6aac16d

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>