From: Sasha Levin <sashal@kernel.org>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
Marcel Holtmann <marcel@holtmann.org>
Cc: Ajay KV <ajay.k.v@intel.com>, Kiran K <kiran.k@intel.com>,
Rosen Penev <rosenp@gmail.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
linux-bluetooth@vger.kernel.org, llvm@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH] Bluetooth: btintel_pcie: Fix context analysis errors on req_lock
Date: Thu, 3 Dec 2026 05:59:52 -0500 [thread overview]
Message-ID: <20261203105952.3324247-1-sashal@kernel.org> (raw)
With clang 23 and CONFIG_WARN_CONTEXT_ANALYSIS, which drivers/bluetooth
is opted into, btintel_pcie_yoyo_send_hcmds() triggers two warnings, and
with CONFIG_WERROR the build fails:
btintel_pcie.c:981:2: error: mutex 'data->hdev->req_lock' is not
held on every path through here [-Werror,-Wthread-safety-analysis]
btintel_pcie.c:1049:3: error: releasing mutex 'data->hdev->req_lock'
that was not held [-Werror,-Wthread-safety-analysis]
The function takes hdev->req_lock only when its caller does not hold it,
and releases it at the end under the same condition. The analysis cannot
match a conditional lock with a later conditional unlock in the same
function.
Move the part that runs under req_lock into
btintel_pcie_yoyo_send_hcmds_locked(). Callers that hold the lock go
straight to it, and the path that takes the lock releases it
unconditionally. No functional change.
Fixes: 738af1958d2e ("Bluetooth: btintel_pcie: Dispatch yoyo triggers at timepoints")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Based on bluetooth-next (738af1958d2e).
The two mac_access_lock errors of the same kind, in
btintel_pcie_apply_yoyo_config_sets(), are still there after this
patch. Rosen Penev's patch fixes those:
https://lore.kernel.org/all/20261126000439.318058-1-rosenp@gmail.com/
It needs "git am -3" on today's bluetooth-next, and can go in before or
after this one. With both applied drivers/bluetooth builds on x86_64
allmodconfig with clang 23.1.6.
drivers/bluetooth/btintel_pcie.c | 111 +++++++++++++++++--------------
1 file changed, 60 insertions(+), 51 deletions(-)
diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c
index ab24c3c75f1b0..a5bef0b24773f 100644
--- a/drivers/bluetooth/btintel_pcie.c
+++ b/drivers/bluetooth/btintel_pcie.c
@@ -923,65 +923,20 @@ static void btintel_pcie_release_mac_access(struct btintel_pcie_data *data)
}
}
-/* btintel_pcie_yoyo_send_hcmds - Send all HCI commands configured for a timepoint */
-static void btintel_pcie_yoyo_send_hcmds(struct btintel_pcie_data *data,
- enum btintel_pcie_dbg_timepoint tp,
- bool req_locked)
+/* Send the HCI commands configured for @tp. The caller holds hdev->req_lock. */
+static void btintel_pcie_yoyo_send_hcmds_locked(struct btintel_pcie_data *data,
+ enum btintel_pcie_dbg_timepoint tp)
{
struct btintel_pcie_yoyo_hcmd *hcmd;
- struct hci_dev *hdev;
struct sk_buff *skb;
u8 plen;
u16 opcode;
- if (!data)
- return;
-
- hdev = data->hdev;
- if (!hdev)
- return;
-
- /* __hci_cmd_sync() requires req_lock, taken before yoyo.lock to match
- * the order setup established. Suspend and resume do not hold it, so
- * take it only when the timepoint has commands to send.
- */
- if (!req_locked) {
- bool found = false;
-
- mutex_lock(&data->yoyo.lock);
- if (data->yoyo.enabled) {
- list_for_each_entry(hcmd, &data->yoyo.hcmd_list, list) {
- if (hcmd->time_point == tp) {
- found = true;
- break;
- }
- }
- }
- mutex_unlock(&data->yoyo.lock);
-
- if (!found)
- return;
-
- hci_req_sync_lock(hdev);
-
- /* A closed device rejects the commands and a user channel
- * consumes their completion, so __hci_cmd_sync() would only
- * fail or time out into a controller reset.
- */
- if (!test_bit(HCI_UP, &hdev->flags) ||
- hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
- bt_dev_dbg(hdev, "YoYo: hdev down or user channel, tp %u commands skipped",
- tp);
- hci_req_sync_unlock(hdev);
- return;
- }
- }
-
/* Held across __hci_cmd_sync() so cleanup cannot free entries in use */
mutex_lock(&data->yoyo.lock);
if (!data->yoyo.enabled) {
mutex_unlock(&data->yoyo.lock);
- goto unlock;
+ return;
}
list_for_each_entry(hcmd, &data->yoyo.hcmd_list, list) {
@@ -1044,9 +999,63 @@ static void btintel_pcie_yoyo_send_hcmds(struct btintel_pcie_data *data,
}
mutex_unlock(&data->yoyo.lock);
-unlock:
- if (!req_locked)
+}
+
+/* btintel_pcie_yoyo_send_hcmds - Send all HCI commands configured for a timepoint */
+static void btintel_pcie_yoyo_send_hcmds(struct btintel_pcie_data *data,
+ enum btintel_pcie_dbg_timepoint tp,
+ bool req_locked)
+{
+ struct btintel_pcie_yoyo_hcmd *hcmd;
+ struct hci_dev *hdev;
+ bool found = false;
+
+ if (!data)
+ return;
+
+ hdev = data->hdev;
+ if (!hdev)
+ return;
+
+ if (req_locked) {
+ btintel_pcie_yoyo_send_hcmds_locked(data, tp);
+ return;
+ }
+
+ /* __hci_cmd_sync() requires req_lock, taken before yoyo.lock to match
+ * the order setup established. Suspend and resume do not hold it, so
+ * take it only when the timepoint has commands to send.
+ */
+ mutex_lock(&data->yoyo.lock);
+ if (data->yoyo.enabled) {
+ list_for_each_entry(hcmd, &data->yoyo.hcmd_list, list) {
+ if (hcmd->time_point == tp) {
+ found = true;
+ break;
+ }
+ }
+ }
+ mutex_unlock(&data->yoyo.lock);
+
+ if (!found)
+ return;
+
+ hci_req_sync_lock(hdev);
+
+ /* A closed device rejects the commands and a user channel
+ * consumes their completion, so __hci_cmd_sync() would only
+ * fail or time out into a controller reset.
+ */
+ if (!test_bit(HCI_UP, &hdev->flags) ||
+ hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
+ bt_dev_dbg(hdev, "YoYo: hdev down or user channel, tp %u commands skipped",
+ tp);
hci_req_sync_unlock(hdev);
+ return;
+ }
+
+ btintel_pcie_yoyo_send_hcmds_locked(data, tp);
+ hci_req_sync_unlock(hdev);
}
static void
base-commit: 738af1958d2e7205008ca818352199ae8e454509
--
2.53.0
next reply other threads:[~2026-12-03 10:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 10:59 Sasha Levin [this message]
2026-12-03 16:16 ` [PATCH] Bluetooth: btintel_pcie: Fix context analysis errors on req_lock Luiz Augusto von Dentz
2026-12-03 17:53 ` Sasha Levin
2026-12-03 18:01 ` Luiz Augusto von Dentz
2026-12-03 18:15 ` Sasha Levin
2026-12-03 19:31 ` Nick Desaulniers
2026-12-03 18:52 ` Pauli Virtanen
2026-12-03 18:55 ` Luiz Augusto von Dentz
2026-12-03 19:17 ` Sasha Levin
2026-12-03 19:32 ` Pauli Virtanen
2026-12-04 2:14 ` bluez.test.bot
2026-12-04 16:10 ` [PATCH] " patchwork-bot+bluetooth
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=20261203105952.3324247-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=ajay.k.v@intel.com \
--cc=justinstitt@google.com \
--cc=kiran.k@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=rosenp@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.