From: lirongqing <lirongqing@baidu.com>
To: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
Patrisious Haddad <phaddad@nvidia.com>,
Jiri Pirko <jiri@resnulli.us>, Edward Srouji <edwards@nvidia.com>,
Michael Guralnik <michaelgur@nvidia.com>,
Tao Cui <cuitao@kylinos.cn>,
Erni Sri Satya Vennela <ernis@linux.microsoft.com>,
Michael Margolin <mrgolin@amazon.com>,
David Ahern <dsahern@kernel.org>,
Zhu Yanjun <yanjun.zhu@linux.dev>, <linux-rdma@vger.kernel.org>
Cc: Li RongQing <lirongqing@baidu.com>
Subject: [PATCH] RDMA/nldev: Put the device when dellink fails
Date: Thu, 3 Sep 2026 16:25:50 +0800 [thread overview]
Message-ID: <20260903082550.2257-1-lirongqing@baidu.com> (raw)
From: Li RongQing <lirongqing@baidu.com>
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")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
drivers/infiniband/core/nldev.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index a4014a2..a1542ed 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -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);
--
2.9.4
reply other threads:[~2026-09-03 8:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260903082550.2257-1-lirongqing@baidu.com \
--to=lirongqing@baidu.com \
--cc=cuitao@kylinos.cn \
--cc=dsahern@kernel.org \
--cc=edwards@nvidia.com \
--cc=ernis@linux.microsoft.com \
--cc=jgg@ziepe.ca \
--cc=jiri@resnulli.us \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=michaelgur@nvidia.com \
--cc=mrgolin@amazon.com \
--cc=phaddad@nvidia.com \
--cc=yanjun.zhu@linux.dev \
/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