mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
Bluetooth: hci_sync: Refactor remove Adv Monitor
Make use of hci_cmd_sync_queue for removing an advertisement monitor. Signed-off-by: Manish Mandlik <mmandlik@google.com> Reviewed-by: Miao-chen Chou <mcchou@google.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
committed by
Luiz Augusto von Dentz
parent
b747a83690
commit
7cf5c2978f
@@ -1880,11 +1880,6 @@ void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
|
||||
kfree(monitor);
|
||||
}
|
||||
|
||||
int hci_remove_adv_monitor_complete(struct hci_dev *hdev, u8 status)
|
||||
{
|
||||
return mgmt_remove_adv_monitor_complete(hdev, status);
|
||||
}
|
||||
|
||||
/* Assigns handle to a monitor, and if offloading is supported and power is on,
|
||||
* also attempts to forward the request to the controller.
|
||||
* This function requires the caller holds hci_req_sync_lock.
|
||||
@@ -1933,92 +1928,72 @@ int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
|
||||
|
||||
/* Attempts to tell the controller and free the monitor. If somehow the
|
||||
* controller doesn't have a corresponding handle, remove anyway.
|
||||
* Returns true if request is forwarded (result is pending), false otherwise.
|
||||
* This function requires the caller holds hdev->lock.
|
||||
* This function requires the caller holds hci_req_sync_lock.
|
||||
*/
|
||||
static bool hci_remove_adv_monitor(struct hci_dev *hdev,
|
||||
struct adv_monitor *monitor,
|
||||
u16 handle, int *err)
|
||||
static int hci_remove_adv_monitor(struct hci_dev *hdev,
|
||||
struct adv_monitor *monitor)
|
||||
{
|
||||
*err = 0;
|
||||
int status = 0;
|
||||
|
||||
switch (hci_get_adv_monitor_offload_ext(hdev)) {
|
||||
case HCI_ADV_MONITOR_EXT_NONE: /* also goes here when powered off */
|
||||
bt_dev_dbg(hdev, "%s remove monitor %d status %d", hdev->name,
|
||||
monitor->handle, status);
|
||||
goto free_monitor;
|
||||
|
||||
case HCI_ADV_MONITOR_EXT_MSFT:
|
||||
*err = msft_remove_monitor(hdev, monitor, handle);
|
||||
status = msft_remove_monitor(hdev, monitor);
|
||||
bt_dev_dbg(hdev, "%s remove monitor %d msft status %d",
|
||||
hdev->name, monitor->handle, status);
|
||||
break;
|
||||
}
|
||||
|
||||
/* In case no matching handle registered, just free the monitor */
|
||||
if (*err == -ENOENT)
|
||||
if (status == -ENOENT)
|
||||
goto free_monitor;
|
||||
|
||||
return (*err == 0);
|
||||
return status;
|
||||
|
||||
free_monitor:
|
||||
if (*err == -ENOENT)
|
||||
if (status == -ENOENT)
|
||||
bt_dev_warn(hdev, "Removing monitor with no matching handle %d",
|
||||
monitor->handle);
|
||||
hci_free_adv_monitor(hdev, monitor);
|
||||
|
||||
*err = 0;
|
||||
return false;
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Returns true if request is forwarded (result is pending), false otherwise.
|
||||
* This function requires the caller holds hdev->lock.
|
||||
*/
|
||||
bool hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle, int *err)
|
||||
/* This function requires the caller holds hci_req_sync_lock */
|
||||
int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle)
|
||||
{
|
||||
struct adv_monitor *monitor = idr_find(&hdev->adv_monitors_idr, handle);
|
||||
bool pending;
|
||||
|
||||
if (!monitor) {
|
||||
*err = -EINVAL;
|
||||
return false;
|
||||
}
|
||||
if (!monitor)
|
||||
return -EINVAL;
|
||||
|
||||
pending = hci_remove_adv_monitor(hdev, monitor, handle, err);
|
||||
if (!*err && !pending)
|
||||
hci_update_passive_scan(hdev);
|
||||
|
||||
bt_dev_dbg(hdev, "%s remove monitor handle %d, status %d, %spending",
|
||||
hdev->name, handle, *err, pending ? "" : "not ");
|
||||
|
||||
return pending;
|
||||
return hci_remove_adv_monitor(hdev, monitor);
|
||||
}
|
||||
|
||||
/* Returns true if request is forwarded (result is pending), false otherwise.
|
||||
* This function requires the caller holds hdev->lock.
|
||||
*/
|
||||
bool hci_remove_all_adv_monitor(struct hci_dev *hdev, int *err)
|
||||
/* This function requires the caller holds hci_req_sync_lock */
|
||||
int hci_remove_all_adv_monitor(struct hci_dev *hdev)
|
||||
{
|
||||
struct adv_monitor *monitor;
|
||||
int idr_next_id = 0;
|
||||
bool pending = false;
|
||||
bool update = false;
|
||||
int status = 0;
|
||||
|
||||
*err = 0;
|
||||
|
||||
while (!*err && !pending) {
|
||||
while (1) {
|
||||
monitor = idr_get_next(&hdev->adv_monitors_idr, &idr_next_id);
|
||||
if (!monitor)
|
||||
break;
|
||||
|
||||
pending = hci_remove_adv_monitor(hdev, monitor, 0, err);
|
||||
status = hci_remove_adv_monitor(hdev, monitor);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
if (!*err && !pending)
|
||||
update = true;
|
||||
idr_next_id++;
|
||||
}
|
||||
|
||||
if (update)
|
||||
hci_update_passive_scan(hdev);
|
||||
|
||||
bt_dev_dbg(hdev, "%s remove all monitors status %d, %spending",
|
||||
hdev->name, *err, pending ? "" : "not ");
|
||||
|
||||
return pending;
|
||||
return status;
|
||||
}
|
||||
|
||||
/* This function requires the caller holds hdev->lock */
|
||||
|
Reference in New Issue
Block a user