diff mbox series

[v1] Bluetooth: MGMT: Fix MGMT_OP_ADD_DEVICE invalid device flags

Message ID 20250429191319.2234877-1-luiz.dentz@gmail.com
State New
Headers show
Series [v1] Bluetooth: MGMT: Fix MGMT_OP_ADD_DEVICE invalid device flags | expand

Commit Message

Luiz Augusto von Dentz April 29, 2025, 7:13 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Device flags could be updated in the meantime while MGMT_OP_ADD_DEVICE
is pending on hci_update_passive_scan_sync so instead of setting the
current_flags as cmd->user_data just do a lookup using
hci_conn_params_lookup and use the latest stored flags.

Fixes: a182d9c84f9c ("Bluetooth: MGMT: Fix Add Device to responding before completing")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 net/bluetooth/mgmt.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

patchwork-bot+bluetooth@kernel.org May 1, 2025, 1:50 p.m. UTC | #1
Hello:

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

On Tue, 29 Apr 2025 15:13:19 -0400 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> Device flags could be updated in the meantime while MGMT_OP_ADD_DEVICE
> is pending on hci_update_passive_scan_sync so instead of setting the
> current_flags as cmd->user_data just do a lookup using
> hci_conn_params_lookup and use the latest stored flags.
> 
> [...]

Here is the summary with links:
  - [v1] Bluetooth: MGMT: Fix MGMT_OP_ADD_DEVICE invalid device flags
    https://git.kernel.org/bluetooth/bluetooth-next/c/a1afd438e713

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c1e1e529e26c..46b22708dfbd 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -7506,11 +7506,16 @@  static void add_device_complete(struct hci_dev *hdev, void *data, int err)
 	struct mgmt_cp_add_device *cp = cmd->param;
 
 	if (!err) {
+		struct hci_conn_params *params;
+
+		params = hci_conn_params_lookup(hdev, &cp->addr.bdaddr,
+						le_addr_type(cp->addr.type));
+
 		device_added(cmd->sk, hdev, &cp->addr.bdaddr, cp->addr.type,
 			     cp->action);
 		device_flags_changed(NULL, hdev, &cp->addr.bdaddr,
 				     cp->addr.type, hdev->conn_flags,
-				     PTR_UINT(cmd->user_data));
+				     params ? params->flags : 0);
 	}
 
 	mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_ADD_DEVICE,
@@ -7613,8 +7618,6 @@  static int add_device(struct sock *sk, struct hci_dev *hdev,
 		goto unlock;
 	}
 
-	cmd->user_data = UINT_PTR(current_flags);
-
 	err = hci_cmd_sync_queue(hdev, add_device_sync, cmd,
 				 add_device_complete);
 	if (err < 0) {