]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Bluetooth: Refactor stop_discovery
authorAndre Guedes <andre.guedes@openbossa.org>
Tue, 20 Mar 2012 18:15:36 +0000 (15:15 -0300)
committerGustavo Padovan <gustavo@padovan.org>
Wed, 28 Mar 2012 15:28:50 +0000 (12:28 -0300)
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>
net/bluetooth/mgmt.c

index d93f2bfa623bafe85d3e9c752f8a19f1306839cb..44a500c29f4d4920e01aa525fd47e71b9a001b22 100644 (file)
@@ -2401,31 +2401,39 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
                goto unlock;
        }
 
-       if (hdev->discovery.state == DISCOVERY_FINDING) {
+       switch (hdev->discovery.state) {
+       case DISCOVERY_FINDING:
                if (test_bit(HCI_INQUIRY, &hdev->flags))
                        err = hci_cancel_inquiry(hdev);
                else
                        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);
-               else
-                       hci_discovery_set_state(hdev, DISCOVERY_STOPPING);
-               goto unlock;
-       }
+                       err = cmd_complete(sk, hdev->id,
+                                               MGMT_OP_STOP_DISCOVERY, 0,
+                                               &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);
-       if (!e) {
-               mgmt_pending_remove(cmd);
-               err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, 0,
-                                  &mgmt_cp->type, sizeof(mgmt_cp->type));
-               hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
-               goto unlock;
+               bacpy(&cp.bdaddr, &e->data.bdaddr);
+               err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL,
+                                       sizeof(cp), &cp);
+
+               break;
+
+       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)
                mgmt_pending_remove(cmd);
        else