[PATCH v3 2/2] Bluetooth: Attempt to clear HCI_LE_ADV on adv set terminated error event

From: Archie Pusaka
Date: Thu Nov 11 2021 - 00:21:16 EST


From: Archie Pusaka <apusaka@xxxxxxxxxxxx>

We should clear the flag if the adv instance removed due to receiving
this error status is the last one we have.

Signed-off-by: Archie Pusaka <apusaka@xxxxxxxxxxxx>
Reviewed-by: Miao-chen Chou <mcchou@xxxxxxxxxxxx>

---

Changes in v3:
* Check adv->enabled rather than just checking for list empty

net/bluetooth/hci_event.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 7d875927c48b..6cf882e6d7e7 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -5532,7 +5532,7 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb)
{
struct hci_evt_le_ext_adv_set_term *ev = (void *) skb->data;
struct hci_conn *conn;
- struct adv_info *adv;
+ struct adv_info *adv, *n;

BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);

@@ -5558,6 +5558,13 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb)
hci_remove_adv_instance(hdev, ev->handle);
mgmt_advertising_removed(NULL, hdev, ev->handle);

+ list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) {
+ if (adv->enabled)
+ return;
+ }
+
+ /* We are no longer advertising, clear HCI_LE_ADV */
+ hci_dev_clear_flag(hdev, HCI_LE_ADV);
return;
}

--
2.34.0.rc0.344.g81b53c2807-goog