From: Rosen Penev <rosenp@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Marcel Holtmann <marcel@holtmann.org>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Kiran K <kiran.k@intel.com>,
llvm@lists.linux.dev (open list:CLANG/LLVM BUILD
SUPPORT:Keyword:\b(?i:clang|llvm)\b)
Subject: [PATCH] Bluetooth: btintel_pcie: fix context analysis error in YoYo config sets
Date: Wed, 25 Nov 2026 16:04:39 -0800 [thread overview]
Message-ID: <20261126000439.318058-1-rosenp@gmail.com> (raw)
btintel_pcie_apply_yoyo_config_sets() takes mac_access_lock only for
PERIPH_MAC and DEVICE_MEM config sets, writes the pairs, and later drops
the lock under a second, identical type check. Clang's context analysis
cannot correlate the two conditions, so with CONTEXT_ANALYSIS enabled for
drivers/bluetooth the build fails:
drivers/bluetooth/btintel_pcie.c:1052:12: error: mutex 'data->mac_access_lock' is not held on every path through here [-Werror,-Wthread-safety-analysis]
drivers/bluetooth/btintel_pcie.c:1110:4: error: releasing mutex 'data->mac_access_lock' that was not held [-Werror,-Wthread-safety-analysis]
Move the pair-writing loop into a helper and take and release the lock
within a single switch case for the indirect config set types. No
functional change.
Fixes: 5bf3a9b6b720 ("Bluetooth: btintel_pcie: Serialize MAC access requests")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/bluetooth/btintel_pcie.c | 159 +++++++++++++++----------------
1 file changed, 79 insertions(+), 80 deletions(-)
diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c
index d7d0e890dfbb..7cbf6d2df491 100644
--- a/drivers/bluetooth/btintel_pcie.c
+++ b/drivers/bluetooth/btintel_pcie.c
@@ -997,6 +997,70 @@ static void btintel_pcie_yoyo_send_hcmds(struct btintel_pcie_data *data,
mutex_unlock(&data->yoyo.lock);
}
+static void
+btintel_pcie_yoyo_write_pairs(struct btintel_pcie_data *data,
+ struct btintel_pcie_yoyo_config_set *config_set,
+ resource_size_t bar0_len)
+{
+ u32 pair_addr, addr, value;
+ u32 i;
+
+ for (i = 0; i < config_set->num_pairs; i++) {
+ pair_addr = get_unaligned_le32(&config_set->pairs[i].address);
+
+ /* Calculate the effective address by adding the address offset */
+ if (check_add_overflow(pair_addr, config_set->addr_offset, &addr)) {
+ BT_WARN("YoYo: config set address overflow (0x%08x + 0x%08x)",
+ pair_addr, config_set->addr_offset);
+ continue;
+ }
+
+ value = get_unaligned_le32(&config_set->pairs[i].value);
+
+ switch (config_set->config_set_type) {
+ /* Direct Address Access (CSR) */
+ case BTINTEL_PCIE_CFGSET_CSR:
+ /* Validate the effective address for CSR access (Direct Address)
+ * addr not aligned to 4 bytes or exceeds the BAR0 length
+ */
+ if ((addr & (sizeof(u32) - 1)) ||
+ bar0_len < sizeof(u32) ||
+ addr > bar0_len - sizeof(u32)) {
+ BT_WARN("YoYo: bad CSR address 0x%08x for BAR0 length %llu",
+ addr, (unsigned long long)bar0_len);
+ continue;
+ }
+
+ BT_DBG("YoYo: CSR write [0x%08x] = 0x%08x", addr, value);
+ /* addr may be PRPH_DEV_* or HBUS_TARG_WRPTR */
+ spin_lock(&data->dev_mem_lock);
+ btintel_pcie_wr_reg32(data, addr, value);
+ spin_unlock(&data->dev_mem_lock);
+ break;
+ /* Indirect Address Access (Peripheral MAC and Device Memory) */
+ case BTINTEL_PCIE_CFGSET_PERIPH_MAC:
+ case BTINTEL_PCIE_CFGSET_DEVICE_MEM:
+ /* The config-set TLV comes from an untrusted external file;
+ * reject null or unaligned targets.
+ */
+ if (!addr || (addr & (sizeof(u32) - 1))) {
+ BT_WARN("YoYo: bad indirect address 0x%08x for type %u",
+ addr, config_set->config_set_type);
+ continue;
+ }
+
+ btintel_pcie_wr_dev_mem(data, addr, value);
+ BT_DBG("YoYo: indirect write type %u addr 0x%08x value 0x%08x",
+ config_set->config_set_type, addr, value);
+ break;
+ default:
+ BT_WARN("YoYo: unknown config_set type %u",
+ config_set->config_set_type);
+ break;
+ }
+ }
+}
+
static void
btintel_pcie_apply_yoyo_config_sets(struct btintel_pcie_data *data,
u32 time_point)
@@ -1004,7 +1068,6 @@ btintel_pcie_apply_yoyo_config_sets(struct btintel_pcie_data *data,
struct btintel_pcie_yoyo_config_set *config_set;
resource_size_t bar0_len;
int ret;
- u32 i;
if (!data)
return;
@@ -1016,98 +1079,34 @@ btintel_pcie_apply_yoyo_config_sets(struct btintel_pcie_data *data,
return;
list_for_each_entry(config_set, &data->yoyo.config_set_list, list) {
- u32 pair_addr, addr, value;
-
if (config_set->time_point != time_point)
continue;
switch (config_set->config_set_type) {
case BTINTEL_PCIE_CFGSET_CSR:
+ btintel_pcie_yoyo_write_pairs(data, config_set, bar0_len);
+ break;
case BTINTEL_PCIE_CFGSET_PERIPH_MAC:
case BTINTEL_PCIE_CFGSET_DEVICE_MEM:
- break;
- default:
- BT_WARN("YoYo: unknown/unsupported config_set type %u, skipping",
- config_set->config_set_type);
- continue;
- }
-
- if (config_set->config_set_type == BTINTEL_PCIE_CFGSET_PERIPH_MAC ||
- config_set->config_set_type == BTINTEL_PCIE_CFGSET_DEVICE_MEM) {
mutex_lock(&data->mac_access_lock);
ret = btintel_pcie_get_mac_access(data);
- if (ret) {
+ if (ret)
BT_WARN("YoYo: MAC access failed for config set (%d), skipping",
ret);
- /* get_mac_access() asserts MAC_ACCESS_REQ before it
- * polls, and leaves it set on timeout; drop it so the
- * request bit is not leaked.
- */
- btintel_pcie_release_mac_access(data);
- mutex_unlock(&data->mac_access_lock);
- continue;
- }
- }
-
- for (i = 0; i < config_set->num_pairs; i++) {
- pair_addr = get_unaligned_le32(&config_set->pairs[i].address);
-
- /* Calculate the effective address by adding the address offset */
- if (check_add_overflow(pair_addr, config_set->addr_offset, &addr)) {
- BT_WARN("YoYo: config set address overflow (0x%08x + 0x%08x)",
- pair_addr, config_set->addr_offset);
- continue;
- }
-
- value = get_unaligned_le32(&config_set->pairs[i].value);
-
- switch (config_set->config_set_type) {
- /* Direct Address Access (CSR) */
- case BTINTEL_PCIE_CFGSET_CSR:
- /* Validate the effective address for CSR access (Direct Address)
- * addr not aligned to 4 bytes or exceeds the BAR0 length
- */
- if ((addr & (sizeof(u32) - 1)) ||
- bar0_len < sizeof(u32) ||
- addr > bar0_len - sizeof(u32)) {
- BT_WARN("YoYo: bad CSR address 0x%08x for BAR0 length %llu",
- addr, (unsigned long long)bar0_len);
- continue;
- }
-
- BT_DBG("YoYo: CSR write [0x%08x] = 0x%08x", addr, value);
- /* addr may be PRPH_DEV_* or HBUS_TARG_WRPTR */
- spin_lock(&data->dev_mem_lock);
- btintel_pcie_wr_reg32(data, addr, value);
- spin_unlock(&data->dev_mem_lock);
- break;
- /* Indirect Address Access (Peripheral MAC and Device Memory) */
- case BTINTEL_PCIE_CFGSET_PERIPH_MAC:
- case BTINTEL_PCIE_CFGSET_DEVICE_MEM:
- /* The config-set TLV comes from an untrusted external file;
- * reject null or unaligned targets.
- */
- if (!addr || (addr & (sizeof(u32) - 1))) {
- BT_WARN("YoYo: bad indirect address 0x%08x for type %u",
- addr, config_set->config_set_type);
- continue;
- }
-
- btintel_pcie_wr_dev_mem(data, addr, value);
- BT_DBG("YoYo: indirect write type %u addr 0x%08x value 0x%08x",
- config_set->config_set_type, addr, value);
- break;
- default:
- BT_WARN("YoYo: unknown config_set type %u",
- config_set->config_set_type);
- break;
- }
- }
-
- if (config_set->config_set_type == BTINTEL_PCIE_CFGSET_PERIPH_MAC ||
- config_set->config_set_type == BTINTEL_PCIE_CFGSET_DEVICE_MEM) {
+ else
+ btintel_pcie_yoyo_write_pairs(data, config_set,
+ bar0_len);
+ /* get_mac_access() asserts MAC_ACCESS_REQ before it
+ * polls, and leaves it set on timeout; drop it in both
+ * cases so the request bit is not leaked.
+ */
btintel_pcie_release_mac_access(data);
mutex_unlock(&data->mac_access_lock);
+ break;
+ default:
+ BT_WARN("YoYo: unknown/unsupported config_set type %u, skipping",
+ config_set->config_set_type);
+ break;
}
}
}
--
2.56.1
next reply other threads:[~2026-11-26 0:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 0:04 Rosen Penev [this message]
2026-11-26 3:42 ` Bluetooth: btintel_pcie: fix context analysis error in YoYo config sets bluez.test.bot
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=20261126000439.318058-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=justinstitt@google.com \
--cc=kiran.k@intel.com \
--cc=linux-bluetooth@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 \
/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