diff options
author | Andre Guedes <andre.guedes@openbossa.org> | 2012-03-20 14:15:36 -0400 |
---|---|---|
committer | Gustavo Padovan <gustavo@padovan.org> | 2012-05-08 23:41:33 -0400 |
commit | e0d9727edb3b66865989a1f592c06606392146ca (patch) | |
tree | e3b9f4fb92285fcca599899971e4b0dc665157dc /net/bluetooth/mgmt.c | |
parent | 7537e5c3064c5a5751a7b26aba82ad83c5e89190 (diff) |
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: Andre Guedes <andre.guedes@openbossa.org>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Gustavo Padovan <gustavo@padovan.org>
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r-- | net/bluetooth/mgmt.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 1d3e3d00d25f..2975a10fca07 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c | |||
@@ -2401,31 +2401,39 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, | |||
2401 | goto unlock; | 2401 | goto unlock; |
2402 | } | 2402 | } |
2403 | 2403 | ||
2404 | if (hdev->discovery.state == DISCOVERY_FINDING) { | 2404 | switch (hdev->discovery.state) { |
2405 | case DISCOVERY_FINDING: | ||
2405 | if (test_bit(HCI_INQUIRY, &hdev->flags)) | 2406 | if (test_bit(HCI_INQUIRY, &hdev->flags)) |
2406 | err = hci_cancel_inquiry(hdev); | 2407 | err = hci_cancel_inquiry(hdev); |
2407 | else | 2408 | else |
2408 | err = hci_cancel_le_scan(hdev); | 2409 | err = hci_cancel_le_scan(hdev); |
2409 | 2410 | ||
2410 | if (err < 0) | 2411 | break; |
2412 | |||
2413 | case DISCOVERY_RESOLVING: | ||
2414 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, | ||
2415 | NAME_PENDING); | ||
2416 | if (!e) { | ||
2411 | mgmt_pending_remove(cmd); | 2417 | mgmt_pending_remove(cmd); |
2412 | else | 2418 | err = cmd_complete(sk, hdev->id, |
2413 | hci_discovery_set_state(hdev, DISCOVERY_STOPPING); | 2419 | MGMT_OP_STOP_DISCOVERY, 0, |
2414 | goto unlock; | 2420 | &mgmt_cp->type, |
2415 | } | 2421 | sizeof(mgmt_cp->type)); |
2422 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); | ||
2423 | goto unlock; | ||
2424 | } | ||
2416 | 2425 | ||
2417 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_PENDING); | 2426 | bacpy(&cp.bdaddr, &e->data.bdaddr); |
2418 | if (!e) { | 2427 | err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, |
2419 | mgmt_pending_remove(cmd); | 2428 | sizeof(cp), &cp); |
2420 | err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, 0, | 2429 | |
2421 | &mgmt_cp->type, sizeof(mgmt_cp->type)); | 2430 | break; |
2422 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); | 2431 | |
2423 | goto unlock; | 2432 | default: |
2433 | BT_DBG("unknown discovery state %u", hdev->discovery.state); | ||
2434 | err = -EFAULT; | ||
2424 | } | 2435 | } |
2425 | 2436 | ||
2426 | bacpy(&cp.bdaddr, &e->data.bdaddr); | ||
2427 | err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp), | ||
2428 | &cp); | ||
2429 | if (err < 0) | 2437 | if (err < 0) |
2430 | mgmt_pending_remove(cmd); | 2438 | mgmt_pending_remove(cmd); |
2431 | else | 2439 | else |