From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v5 4/4] Bluetooth: MGMT: Fix leaking instance on Add Extended Advertising Parameters
Date: Tue, 6 Oct 2026 10:15:02 -0400 [thread overview]
Message-ID: <20261006141502.3789138-4-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261006141502.3789138-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If queueing the command fails the instance is never removed, despite it
having already been added or modified by hci_add_adv_instance, so remove
it as it is done by add_ext_adv_params_complete on failure, signaling
it has been removed if it was previously added.
Fixes: cba6b758711c ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 2")
Assisted-by: OpenCode:claude-opus-5.5
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
net/bluetooth/mgmt.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 93872a5fc39c..ce091bf84642 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -9361,14 +9361,15 @@ static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev,
data, data_len);
if (!cmd) {
err = -ENOMEM;
- hci_remove_adv_instance(hdev, cp->instance);
- goto unlock;
+ goto remove;
}
err = hci_cmd_sync_queue(hdev, add_ext_adv_params_sync, cmd,
add_ext_adv_params_complete);
- if (err < 0)
+ if (err < 0) {
mgmt_pending_free(cmd);
+ goto remove;
+ }
} else {
rp.instance = cp->instance;
rp.tx_power = HCI_ADV_TX_POWER_NO_PREFERENCE;
@@ -9379,6 +9380,18 @@ static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev,
MGMT_STATUS_SUCCESS, &rp, sizeof(rp));
}
+ goto unlock;
+
+remove:
+ /* The instance may have been modified already so remove it, like it
+ * is done in add_ext_adv_params_complete, signaling it has been
+ * removed if it was previously added.
+ */
+ if (!adv->pending)
+ mgmt_advertising_removed(sk, hdev, cp->instance);
+
+ hci_remove_adv_instance(hdev, cp->instance);
+
unlock:
hci_dev_unlock(hdev);
--
2.55.0
next prev parent reply other threads:[~2026-10-06 14:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 14:14 [PATCH v5 1/4] Bluetooth: MGMT: Fix advertising instances with Global Advertising Luiz Augusto von Dentz
2026-10-06 14:15 ` [PATCH v5 2/4] Bluetooth: HCI: Fix tracking of instances sharing handle 0x00 Luiz Augusto von Dentz
2026-10-06 14:15 ` [PATCH v5 3/4] Bluetooth: MGMT: Fix pending state of instances added without HCI traffic Luiz Augusto von Dentz
2026-10-06 14:15 ` Luiz Augusto von Dentz [this message]
2026-10-06 15:10 ` [PATCH v5 1/4] Bluetooth: MGMT: Fix advertising instances with Global Advertising patchwork-bot+bluetooth
2026-10-06 15:24 ` [v5,1/4] " bluez.test.bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261006141502.3789138-4-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.