From: Bart Van Assche <bart.vanassche@linux.dev>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun@kernel.org>, Waiman Long <longman@redhat.com>,
linux-kernel@vger.kernel.org, Marco Elver <elver@google.com>,
Christoph Hellwig <hch@lst.de>,
Steven Rostedt <rostedt@goodmis.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Nathan Chancellor <nathan@kernel.org>,
Kees Cook <kees@kernel.org>, Jann Horn <jannh@google.com>,
Bart Van Assche <bvanassche@acm.org>,
Manish Chopra <manishc@marvell.com>,
netdev@vger.kernel.org
Subject: [PATCH 21/62] qed: Make _qed_mcp_cmd_and_union() easier to analyze
Date: Mon, 23 Feb 2026 14:00:21 -0800 [thread overview]
Message-ID: <20260223220102.2158611-22-bart.vanassche@linux.dev> (raw)
In-Reply-To: <20260223220102.2158611-1-bart.vanassche@linux.dev>
From: Bart Van Assche <bvanassche@acm.org>
Make the implementation of this function compatible with clang's
compile-time thread-safety analysis by moving error-handling code to the
end of this function. No functionality has been changed.
Cc: Manish Chopra <manishc@marvell.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/net/ethernet/qlogic/qed/qed_mcp.c | 56 ++++++++++++-----------
1 file changed, 30 insertions(+), 26 deletions(-)
diff --git a/drivers/net/ethernet/qlogic/qed/qed_mcp.c b/drivers/net/ethernet/qlogic/qed/qed_mcp.c
index 7e37fe631a58..462e758c5890 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_mcp.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_mcp.c
@@ -467,7 +467,7 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
int rc = 0;
/* Wait until the mailbox is non-occupied */
- do {
+ for (;;) {
/* Exit the loop if there is no pending command, or if the
* pending command is completed during this iteration.
* The spinlock stays locked until the command is sent.
@@ -486,18 +486,14 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
+ if (++cnt >= QED_DRV_MB_MAX_RETRIES)
+ goto retries_exceeded_1;
+
if (QED_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP))
usleep_range(QED_MCP_RESP_ITER_US,
QED_MCP_RESP_ITER_US * 2);
else
udelay(QED_MCP_RESP_ITER_US);
- } while (++cnt < QED_DRV_MB_MAX_RETRIES);
-
- if (cnt >= QED_DRV_MB_MAX_RETRIES) {
- DP_NOTICE(p_hwfn,
- "The MFW mailbox is occupied by an uncompleted command. Failed to send command 0x%08x [param 0x%08x].\n",
- p_mb_params->cmd, p_mb_params->param);
- return -EAGAIN;
}
/* Send the mailbox command */
@@ -513,7 +509,7 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
/* Wait for the MFW response */
- do {
+ for (;;) {
/* Exit the loop if the command is already completed, or if the
* command is completed during this iteration.
* The spinlock stays locked until the list element is removed.
@@ -537,24 +533,9 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
goto err;
spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
- } while (++cnt < QED_DRV_MB_MAX_RETRIES);
-
- if (cnt >= QED_DRV_MB_MAX_RETRIES) {
- DP_NOTICE(p_hwfn,
- "The MFW failed to respond to command 0x%08x [param 0x%08x].\n",
- p_mb_params->cmd, p_mb_params->param);
- qed_mcp_print_cpu_info(p_hwfn, p_ptt);
-
- spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
- qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
- spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
- if (!QED_MB_FLAGS_IS_SET(p_mb_params, AVOID_BLOCK))
- qed_mcp_cmd_set_blocking(p_hwfn, true);
-
- qed_hw_err_notify(p_hwfn, p_ptt,
- QED_HW_ERR_MFW_RESP_FAIL, NULL);
- return -EAGAIN;
+ if (++cnt >= QED_DRV_MB_MAX_RETRIES)
+ goto retries_exceeded_2;
}
qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
@@ -576,6 +557,29 @@ _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
err:
spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
return rc;
+
+retries_exceeded_1:
+ DP_NOTICE(p_hwfn,
+ "The MFW mailbox is occupied by an uncompleted command. Failed to send command 0x%08x [param 0x%08x].\n",
+ p_mb_params->cmd, p_mb_params->param);
+ return -EAGAIN;
+
+retries_exceeded_2:
+ DP_NOTICE(p_hwfn,
+ "The MFW failed to respond to command 0x%08x [param 0x%08x].\n",
+ p_mb_params->cmd, p_mb_params->param);
+ qed_mcp_print_cpu_info(p_hwfn, p_ptt);
+
+ spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
+ qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
+ spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
+
+ if (!QED_MB_FLAGS_IS_SET(p_mb_params, AVOID_BLOCK))
+ qed_mcp_cmd_set_blocking(p_hwfn, true);
+
+ qed_hw_err_notify(p_hwfn, p_ptt,
+ QED_HW_ERR_MFW_RESP_FAIL, NULL);
+ return -EAGAIN;
}
static int qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
next prev parent reply other threads:[~2026-02-23 22:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260223220102.2158611-1-bart.vanassche@linux.dev>
2026-02-23 22:00 ` [PATCH 17/62] bnxt_en: Make bnxt_resume() easier to analyze Bart Van Assche
2026-02-23 22:00 ` [PATCH 18/62] bnxt_en: Fix bnxt_dl_reload_up() Bart Van Assche
2026-02-23 22:00 ` [PATCH 20/62] octeontx2-pf: Fix locking in an error path Bart Van Assche
2026-02-23 22:00 ` Bart Van Assche [this message]
2026-02-23 22:00 ` [PATCH 22/62] mctp i3c: Fix locking in error paths Bart Van Assche
2026-02-25 4:27 ` Matt Johnston
2026-02-23 22:00 ` [PATCH 23/62] net: phy: mxl-86110: Fix locking in an error path Bart Van Assche
2026-02-23 23:12 ` Daniel Golle
2026-02-24 0:19 ` Andrew Lunn
[not found] <20260223214950.2153735-1-bvanassche@acm.org>
2026-02-23 21:49 ` [PATCH 21/62] qed: Make _qed_mcp_cmd_and_union() easier to analyze Bart Van Assche
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=20260223220102.2158611-22-bart.vanassche@linux.dev \
--to=bart.vanassche@linux.dev \
--cc=boqun@kernel.org \
--cc=bvanassche@acm.org \
--cc=elver@google.com \
--cc=hch@lst.de \
--cc=jannh@google.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=manishc@marvell.com \
--cc=mingo@redhat.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=will@kernel.org \
/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