Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: MGMT: Retain the selected legacy advertising schedule ID
@ 2026-11-19 11:23 Zhao Li
  2026-11-19 18:50 ` patchwork-bot+bluetooth
  0 siblings, 1 reply; 2+ messages in thread
From: Zhao Li @ 2026-11-19 11:23 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: linux-bluetooth, linux-kernel, Zhao Li, stable

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: stable@vger.kernel.org # needs adjustments for <= 6.5
Signed-off-by: Zhao Li <enderaoelyther@gmail.com>
---
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(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 6ed3bf6f1738..075252d72cbb 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -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
-- 
2.56.1


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

* Re: [PATCH] Bluetooth: MGMT: Retain the selected legacy advertising schedule ID
  2026-11-19 11:23 [PATCH] Bluetooth: MGMT: Retain the selected legacy advertising schedule ID Zhao Li
@ 2026-11-19 18:50 ` patchwork-bot+bluetooth
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+bluetooth @ 2026-11-19 18:50 UTC (permalink / raw)
  To: Zhao Li; +Cc: marcel, luiz.dentz, linux-bluetooth, linux-kernel, stable

Hello:

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

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.
> 
> 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-11-19 18:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 11:23 [PATCH] Bluetooth: MGMT: Retain the selected legacy advertising schedule ID Zhao Li
2026-11-19 18:50 ` 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