[PATCHv2 14/17] nvme: fix Clang context analysis warning in rdma.c
Nilay Shroff
nilay at linux.ibm.com
Sun Jun 14 06:15:29 PDT 2026
After adding Clang lock context annotations in rdma.c, Clang reports
the following warning when context analysis is enabled:
drivers/nvme/host/rdma.c:972:24: warning: passing pointer to variable 'list' requires holding mutex 'nvme_rdma_ctrl_mutex'
[-Wthread-safety-pointer]
972 | if (list_empty(&ctrl->list))
| ^
The warning is triggered because ctrl->list is annotated as being
protected by nvme_rdma_ctrl_mutex, but list_empty(&ctrl->list) is
invoked without holding that mutex.
Fix the warning by performing the list_empty(&ctrl->list) check while
holding nvme_rdma_ctrl_mutex.
Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
drivers/nvme/host/rdma.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 2c55f05f7550..da7770025059 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -969,10 +969,11 @@ static void nvme_rdma_free_ctrl(struct nvme_ctrl *nctrl)
{
struct nvme_rdma_ctrl *ctrl = to_rdma_ctrl(nctrl);
- if (list_empty(&ctrl->list))
- goto free_ctrl;
-
mutex_lock(&nvme_rdma_ctrl_mutex);
+ if (list_empty(&ctrl->list)) {
+ mutex_unlock(&nvme_rdma_ctrl_mutex);
+ goto free_ctrl;
+ }
list_del(&ctrl->list);
mutex_unlock(&nvme_rdma_ctrl_mutex);
--
2.53.0
More information about the Linux-nvme
mailing list