From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796295596; b=LV7Pc0QPVTa2z5FoR5WWT32Yfudos5DuuuX7RltZRbNDUOj2dkFMFmbI1G7TGQ7IqiFE Zn41Zp4YnOD4XK9v9+kaf6J04ZTJINat/Ept5xIqjGeoJ6NCBRALIAjB0oUzT6UcXWeJi 1ElekORpxK1BMwHOdHrrYtcMKn+mzzjcoWWH3EnQhZ7zx16uP/bXMYZYB5C+1bdu1RSK5 IjofxWeJnuE+LjEYbZJPtE+SDyY7dsp9ztecpHv6LY83qmSjhkzzb55uPmUueYnr8dRZg wM7mxNAaBTj1fEqnL4dB0UI3zC5tIQOemiJEmY4J4Ok59TQjcCF7q58H/+Xnq5LcM7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796295596; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=R5I8ZkRLOlgFWs2eN1qF4b7E6/x4lAPJgl0DkB9LBgo=; b=glL1VUP0mP0VG2B8/8bzNDFdi3K9GGdX3JQt6c9uXxJ/MGhePGgzZGdfsdMXWdVWN75J QYaqdUaBL3OEL6igc0I9hehGaZ+o9jWRdCO1YaUwbgaT0B9SE5hsRTiG5KuGEh3sQ7/yN BicVnsLsctMbDkGB7ouC57mbG2gXYjxBUcxO3sf3IAYMK8nt/XekBsF3M3+nMl6ozrA3y 0mnNn2FDsu8CnWxyRe/xHzDhlHAgaOO56jSFHFAXj3SDy/wFVKCy4mGmaldVBxGa2KcmJ VkvKHU6U7GFc1mYlk4sNe+J6H8QJYfw8WTSlmOwOKImfbIW8WnqyaqG8pHoBCHXjiWw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OCZuRtuT; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00154606A322; Thu, 3 Dec 2026 10:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OCZuRtuT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BA621F000C1; Thu, 3 Dec 2026 10:59:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796295595; bh=R5I8ZkRLOlgFWs2eN1qF4b7E6/x4lAPJgl0DkB9LBgo=; h=From:To:Cc:Subject:Date; b=OCZuRtuT6pc+KvRImbOEyBXzExkWfytZEqbilrb3YEwuz1o+4rsjnb9baeVjReCHl XlWi7PnkhVt2XuXOgugDfVDQlzZ+6zSNcHwT9/p7gIJmakWFzMBozieA4QQCL+IOPL c2MSo0PCzpVpO9c6ebBAV3AsjUme+JiVwYAb8F2jRYh17SLJ8CIEM7xO9qRwn5cGBv kHF+0xeB/VjF0CcicpdEUoML06ngH1Y4LUmZYlYCDawm2XLfhxthljX26PLrpVqTNn AEeyhquYsuxt+AKuIoSHa4kTPLGpwJCe4s/aNPLqYWY7sb72IKgdo/fXUiCBtadHSO LKibyUMJ96eRw== From: Sasha Levin To: Luiz Augusto von Dentz , Marcel Holtmann Cc: Ajay KV , Kiran K , Rosen Penev , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , 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 Message-ID: <20261203105952.3324247-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: llvm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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