Commit e0d9727e authored by Andre Guedes's avatar Andre Guedes Committed by Gustavo Padovan

Bluetooth: Refactor stop_discovery

This patch does a trivial code refactoring in stop_discovery
function by using a switch statement instead of an if-return-else
approach.
Signed-off-by: default avatarAndre Guedes <andre.guedes@openbossa.org>
Acked-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarGustavo Padovan <gustavo@padovan.org>
parent 7537e5c3
...@@ -2401,31 +2401,39 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, ...@@ -2401,31 +2401,39 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
goto unlock; goto unlock;
} }
if (hdev->discovery.state == DISCOVERY_FINDING) { switch (hdev->discovery.state) {
case DISCOVERY_FINDING:
if (test_bit(HCI_INQUIRY, &hdev->flags)) if (test_bit(HCI_INQUIRY, &hdev->flags))
err = hci_cancel_inquiry(hdev); err = hci_cancel_inquiry(hdev);
else else
err = hci_cancel_le_scan(hdev); err = hci_cancel_le_scan(hdev);
if (err < 0) break;
case DISCOVERY_RESOLVING:
e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY,
NAME_PENDING);
if (!e) {
mgmt_pending_remove(cmd); mgmt_pending_remove(cmd);
else err = cmd_complete(sk, hdev->id,
hci_discovery_set_state(hdev, DISCOVERY_STOPPING); MGMT_OP_STOP_DISCOVERY, 0,
goto unlock; &mgmt_cp->type,
} sizeof(mgmt_cp->type));
hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
goto unlock;
}
e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_PENDING); bacpy(&cp.bdaddr, &e->data.bdaddr);
if (!e) { err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL,
mgmt_pending_remove(cmd); sizeof(cp), &cp);
err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, 0,
&mgmt_cp->type, sizeof(mgmt_cp->type)); break;
hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
goto unlock; default:
BT_DBG("unknown discovery state %u", hdev->discovery.state);
err = -EFAULT;
} }
bacpy(&cp.bdaddr, &e->data.bdaddr);
err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp),
&cp);
if (err < 0) if (err < 0)
mgmt_pending_remove(cmd); mgmt_pending_remove(cmd);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment