netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: hci_sync: Check the correct flag before starting a scan
@ 2024-01-02 18:08 Jonas Dreßler
  2024-01-04 17:41 ` Simon Horman
  2024-01-04 22:20 ` patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Jonas Dreßler @ 2024-01-02 18:08 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz
  Cc: Jonas Dreßler, linux-bluetooth, linux-kernel, netdev

There's a very confusing mistake in the code starting a HCI inquiry: We're
calling hci_dev_test_flag() to test for HCI_INQUIRY, but hci_dev_test_flag()
checks hdev->dev_flags instead of hdev->flags. HCI_INQUIRY is a bit that's
set on hdev->flags, not on hdev->dev_flags though.

HCI_INQUIRY equals the integer 7, and in hdev->dev_flags, 7 means
HCI_BONDABLE, so we were actually checking for HCI_BONDABLE here.

The mistake is only present in the synchronous code for starting an inquiry,
not in the async one. Also devices are typically bondable while doing an
inquiry, so that might be the reason why nobody noticed it so far.

Signed-off-by: Jonas Dreßler <verdre@v0yd.nl>
---
 net/bluetooth/hci_sync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index c920de0a2..4a5949a0e 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -5554,7 +5554,7 @@ static int hci_inquiry_sync(struct hci_dev *hdev, u8 length)
 
 	bt_dev_dbg(hdev, "");
 
-	if (hci_dev_test_flag(hdev, HCI_INQUIRY))
+	if (test_bit(HCI_INQUIRY, &hdev->flags))
 		return 0;
 
 	hci_dev_lock(hdev);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Bluetooth: hci_sync: Check the correct flag before starting a scan
  2024-01-02 18:08 [PATCH] Bluetooth: hci_sync: Check the correct flag before starting a scan Jonas Dreßler
@ 2024-01-04 17:41 ` Simon Horman
  2024-01-04 22:20 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2024-01-04 17:41 UTC (permalink / raw)
  To: Jonas Dreßler
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	linux-bluetooth, linux-kernel, netdev

On Tue, Jan 02, 2024 at 07:08:08PM +0100, Jonas Dreßler wrote:
> There's a very confusing mistake in the code starting a HCI inquiry: We're
> calling hci_dev_test_flag() to test for HCI_INQUIRY, but hci_dev_test_flag()
> checks hdev->dev_flags instead of hdev->flags. HCI_INQUIRY is a bit that's
> set on hdev->flags, not on hdev->dev_flags though.
> 
> HCI_INQUIRY equals the integer 7, and in hdev->dev_flags, 7 means
> HCI_BONDABLE, so we were actually checking for HCI_BONDABLE here.
> 
> The mistake is only present in the synchronous code for starting an inquiry,
> not in the async one. Also devices are typically bondable while doing an
> inquiry, so that might be the reason why nobody noticed it so far.
> 
> Signed-off-by: Jonas Dreßler <verdre@v0yd.nl>

FWIIW, I agree with this analysis and the proposed fix looks
correct to me.

Reviewed-by: Simon Horman <horms@kernel.org>

I do wonder if it is appropriate to treat this as a bug fix -
is there a use-visible problem? If so, the following seems appropriate to
me.

Fixes: abfeea476c68 ("Bluetooth: hci_sync: Convert MGMT_OP_START_DISCOVERY")

...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Bluetooth: hci_sync: Check the correct flag before starting a scan
  2024-01-02 18:08 [PATCH] Bluetooth: hci_sync: Check the correct flag before starting a scan Jonas Dreßler
  2024-01-04 17:41 ` Simon Horman
@ 2024-01-04 22:20 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2024-01-04 22:20 UTC (permalink / raw)
  To: =?utf-8?q?Jonas_Dre=C3=9Fler_=3Cverdre=40v0yd=2Enl=3E?=
  Cc: marcel, johan.hedberg, luiz.dentz, linux-bluetooth, linux-kernel,
	netdev

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Tue,  2 Jan 2024 19:08:08 +0100 you wrote:
> There's a very confusing mistake in the code starting a HCI inquiry: We're
> calling hci_dev_test_flag() to test for HCI_INQUIRY, but hci_dev_test_flag()
> checks hdev->dev_flags instead of hdev->flags. HCI_INQUIRY is a bit that's
> set on hdev->flags, not on hdev->dev_flags though.
> 
> HCI_INQUIRY equals the integer 7, and in hdev->dev_flags, 7 means
> HCI_BONDABLE, so we were actually checking for HCI_BONDABLE here.
> 
> [...]

Here is the summary with links:
  - Bluetooth: hci_sync: Check the correct flag before starting a scan
    https://git.kernel.org/bluetooth/bluetooth-next/c/626cef40faf0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-04 22:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-02 18:08 [PATCH] Bluetooth: hci_sync: Check the correct flag before starting a scan Jonas Dreßler
2024-01-04 17:41 ` Simon Horman
2024-01-04 22:20 ` patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).