Bluetooth: Simplify the error handling of Start Discovery command
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 4 Dec 2014 10:36:34 +0000 (11:36 +0100)
committerJohan Hedberg <johan.hedberg@intel.com>
Thu, 4 Dec 2014 10:50:21 +0000 (12:50 +0200)
The Start Discovery command has some complicated code when it comes
to error handling. With the future introduction of Start Service
Discovery simplifying this makes it easier to read.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
net/bluetooth/mgmt.c

index 77cf0ef0d8a31cff859bb8352a7fe290b8f0cb65..f3296371a310c5bef4a82182b39a97f3f829a666 100644 (file)
@@ -3771,14 +3771,8 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
                goto failed;
        }
 
-       if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags)) {
-               err = cmd_complete(sk, hdev->id, MGMT_OP_START_DISCOVERY,
-                                  MGMT_STATUS_BUSY, &cp->type,
-                                  sizeof(cp->type));
-               goto failed;
-       }
-
-       if (hdev->discovery.state != DISCOVERY_STOPPED) {
+       if (hdev->discovery.state != DISCOVERY_STOPPED ||
+           test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags)) {
                err = cmd_complete(sk, hdev->id, MGMT_OP_START_DISCOVERY,
                                   MGMT_STATUS_BUSY, &cp->type,
                                   sizeof(cp->type));
@@ -3909,10 +3903,12 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
        }
 
        err = hci_req_run(&req, start_discovery_complete);
-       if (err < 0)
+       if (err < 0) {
                mgmt_pending_remove(cmd);
-       else
-               hci_discovery_set_state(hdev, DISCOVERY_STARTING);
+               goto failed;
+       }
+
+       hci_discovery_set_state(hdev, DISCOVERY_STARTING);
 
 failed:
        hci_dev_unlock(hdev);