RDMA/nldev: Put the device when dellink fails
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.
--- drivers/infiniband/core/nldev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/infiniband/core/nldev.c +3 -1
@@ -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
Leon Romanovsky
AppliedQuoted 11 lines · lirongqing
nldev_dellink()takes a device reference throughib_device_get_by_index()and normally hands it over toib_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]>