Skip to contentSkip to conversation

Bluetooth: MGMT: Retain the selected legacy advertising schedule ID

PATCH Applied Zhao Li 3 participants 3 messages Nov 19

Subsystems (3)
lore
Share & tools
lore

Zhao Li

author
#0 lore raw

PATCH 1/1 Bluetooth: MGMT: Retain the selected legacy advertising schedule ID

Updating the currently advertised legacy instance can schedule that same instance again instead of the next selected instance. Add Advertising stores the selected ID in the original request after mgmt_pending_new() has copied it, so the queued callback still reads the requested ID. Add Extended Advertising Data never passes the selected ID to its callback.

Pass the selected ID to both callbacks in the pending command's user data, and keep the request ID for the replies and completion cleanup. Extended advertising controllers do not rotate instances in software, so keep scheduling the requested instance there, as both callbacks do now, without cancelling the rotation timeout or looking up the next one.

Found by code review.

Fixes cba6b758711c ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 2")
Cc [email protected] # needs adjustments for <= 6.5

---
Tested in QEMU on bluetooth-next f42f5cae154b with vhci controllers and four new mgmt-tester cases. On an LE-only controller with instances 1 and 2, updating the advertised instance 1 through Add Advertising or Add Extended Advertising Data now makes the next LE Set Advertising Data carry instance 2's data; without this patch it carries instance 1's new data again. On an extended advertising controller, updating the current instance 2 sends LE Set Extended Advertising Data for handle 2 with the new data, with and without this patch. The rest of the mgmt-tester suite shows no difference beyond one LL Privacy case that times out intermittently on both kernels.

No new W=1, sparse or smatch warnings.

AI assistance was used.

 net/bluetooth/mgmt.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
net/bluetooth/mgmt.c +13 -6
index 6ed3bf6f1738..075252d72cbb 100644
@@ -9099,9 +9099,9 @@ static void add_advertising_complete(struct hci_dev *hdev, void *data, int err)
 static int add_advertising_sync(struct hci_dev *hdev, void *data)
 {
 	struct mgmt_pending_cmd *cmd = data;
-	struct mgmt_cp_add_advertising *cp = cmd->param;
+	u8 instance = PTR_UINT(cmd->user_data);
 
-	return hci_schedule_adv_instance_sync(hdev, cp->instance, true);
+	return hci_schedule_adv_instance_sync(hdev, instance, true);
 }
 
 static int add_advertising(struct sock *sk, struct hci_dev *hdev,
@@ -9185,7 +9185,9 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev,
 	if (hdev->adv_instance_cnt > prev_instance_cnt)
 		mgmt_advertising_added(sk, hdev, cp->instance);
 
-	if (hdev->cur_adv_instance == cp->instance) {
+	if (ext_adv_capable(hdev)) {
+		schedule_instance = cp->instance;
+	} else if (hdev->cur_adv_instance == cp->instance) {
 		/* If the currently advertised instance is being changed then
 		 * cancel the current advertising and schedule the next
 		 * instance. If there is only one instance then the overridden
@@ -9232,7 +9234,7 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev,
 		goto unlock;
 	}
 
-	cp->instance = schedule_instance;
+	cmd->user_data = UINT_PTR(schedule_instance);
 
 	err = hci_cmd_sync_queue(hdev, add_advertising_sync, cmd,
 				 add_advertising_complete);
@@ -9461,6 +9463,7 @@ static int add_ext_adv_data_sync(struct hci_dev *hdev, void *data)
 {
 	struct mgmt_pending_cmd *cmd = data;
 	struct mgmt_cp_add_ext_adv_data *cp = cmd->param;
+	u8 instance = PTR_UINT(cmd->user_data);
 	int err;
 
 	if (ext_adv_capable(hdev)) {
@@ -9475,7 +9478,7 @@ static int add_ext_adv_data_sync(struct hci_dev *hdev, void *data)
 		return hci_enable_ext_advertising_sync(hdev, cp->instance);
 	}
 
-	return hci_schedule_adv_instance_sync(hdev, cp->instance, true);
+	return hci_schedule_adv_instance_sync(hdev, instance, true);
 }
 
 static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data,
@@ -9537,7 +9540,9 @@ static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data,
 				  cp->data + cp->adv_data_len);
 
 	/* If using software rotation, determine next instance to use */
-	if (hdev->cur_adv_instance == cp->instance) {
+	if (ext_adv_capable(hdev)) {
+		schedule_instance = cp->instance;
+	} else if (hdev->cur_adv_instance == cp->instance) {
 		/* If the currently advertised instance is being changed
 		 * then cancel the current advertising and schedule the
 		 * next instance. If there is only one instance then the
@@ -9579,6 +9584,8 @@ static int add_ext_adv_data(struct sock *sk, struct hci_dev *hdev, void *data,
 		goto clear_new_instance;
 	}
 
+	cmd->user_data = UINT_PTR(schedule_instance);
+
 	err = hci_cmd_sync_queue(hdev, add_ext_adv_data_sync, cmd,
 				 add_ext_adv_data_complete);
 	if (err < 0) {

base-commit: f42f5cae154b90a0cb6d8232dc84c7614ca2e6a0

Signature · 1 line
2.56.1
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1216056/

---Test result---

Test Summary:

CheckPatch                    PASS      0.65 seconds
VerifyFixes                   PASS      0.07 seconds
VerifySignedoff               PASS      0.07 seconds
GitLint                       PASS      0.24 seconds
SubjectPrefix                 PASS      0.07 seconds
BuildKernel                   PASS      33.30 seconds
CheckAllWarning               PASS      37.87 seconds
CheckSparse                   PASS      39.81 seconds
BuildKernel32                 PASS      32.23 seconds
CheckKernelLLVM               PASS      34.75 seconds
TestRunnerSetup               PASS      785.31 seconds
TestRunner_mgmt-tester        PASS      89.71 seconds
TestRunner_mesh-tester        PASS      5.51 seconds
IncrementalBuild              PASS      30.63 seconds

https://github.com/bluez/bluetooth-next/pull/1159

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Zhao Li
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 6 lines · On Thu, 19 Nov 2026 19:23:59 +0800 you wrote:

Updating the currently advertised legacy instance can schedule that same instance again instead of the next selected instance. Add Advertising stores the selected ID in the original request after mgmt_pending_new() has copied it, so the queued callback still reads the requested ID. Add Extended Advertising Data never passes the selected ID to its callback.

Quoted 7 lines

Pass the selected ID to both callbacks in the pending command's user data, and keep the request ID for the replies and completion cleanup. Extended advertising controllers do not rotate instances in software, so keep scheduling the requested instance there, as both callbacks do now, without cancelling the rotation timeout or looking up the next one.

[...]

Here is the summary with links:
- Bluetooth: MGMT: Retain the selected legacy advertising schedule ID

    https://git.kernel.org/bluetooth/bluetooth-next/c/5052141b19fe

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html