[PATCHv2 16/17] nvme: fix Clang context analysis warning in tcp.c
Nilay Shroff
nilay at linux.ibm.com
Sun Jun 14 06:15:31 PDT 2026
After adding Clang context annotations, compiling tcp.c reports the
following warning while context analysis is enabled:
drivers/nvme/host/tcp.c:2572:24: warning: passing pointer to variable 'list' requires holding mutex 'nvme_tcp_ctrl_mutex'
[-Wthread-safety-pointer]
2572 | if (list_empty(&ctrl->list))
| ^
The above warning is triggered because ctrl->list is guarded with mutex
nvme_tcp_ctrl_mutex but when list_empty(&ctrl->list) is invoked it
doesn't acquire nvme_tcp_ctrl_mutex.
Fix the warning by performing the list_empty(&ctrl->list) check while
holding nvme_tcp_ctrl_mutex.
Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
drivers/nvme/host/tcp.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index c4662ccb5c49..86ef98aefeb4 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -2569,10 +2569,11 @@ static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl)
{
struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
- if (list_empty(&ctrl->list))
- goto free_ctrl;
-
mutex_lock(&nvme_tcp_ctrl_mutex);
+ if (list_empty(&ctrl->list)) {
+ mutex_unlock(&nvme_tcp_ctrl_mutex);
+ goto free_ctrl;
+ }
list_del(&ctrl->list);
mutex_unlock(&nvme_tcp_ctrl_mutex);
--
2.53.0
More information about the Linux-nvme
mailing list