Fix stopping inquiry before adapter object is initialized

This can cause errors on command complete since the adapter object could
not be found to set its mode.
diff --git a/plugins/hciops.c b/plugins/hciops.c
index e4f0b5d..f7c5948 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -457,6 +457,29 @@
 	memset(dev->eir, 0, sizeof(dev->eir));
 }
 
+static int hciops_stop_inquiry(int index)
+{
+	struct dev_info *dev = &devs[index];
+	struct hci_dev_info di;
+	int err;
+
+	DBG("hci%d", index);
+
+	if (hci_devinfo(index, &di) < 0)
+		return -errno;
+
+	if (hci_test_bit(HCI_INQUIRY, &di.flags))
+		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
+						OCF_INQUIRY_CANCEL, 0, 0);
+	else
+		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
+					OCF_EXIT_PERIODIC_INQUIRY, 0, 0);
+	if (err < 0)
+		err = -errno;
+
+	return err;
+}
+
 static gboolean init_adapter(int index)
 {
 	struct dev_info *dev = &devs[index];
@@ -496,6 +519,9 @@
 	hciops_set_discoverable(index, discoverable);
 	hciops_set_pairable(index, pairable);
 
+	if (dev->already_up)
+		hciops_stop_inquiry(index);
+
 done:
 	btd_adapter_unref(adapter);
 	return TRUE;
@@ -2602,29 +2628,6 @@
 	}
 }
 
-static int hciops_stop_inquiry(int index)
-{
-	struct dev_info *dev = &devs[index];
-	struct hci_dev_info di;
-	int err;
-
-	DBG("hci%d", index);
-
-	if (hci_devinfo(index, &di) < 0)
-		return -errno;
-
-	if (hci_test_bit(HCI_INQUIRY, &di.flags))
-		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
-						OCF_INQUIRY_CANCEL, 0, 0);
-	else
-		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
-					OCF_EXIT_PERIODIC_INQUIRY, 0, 0);
-	if (err < 0)
-		err = -errno;
-
-	return err;
-}
-
 static gboolean init_known_adapters(gpointer user_data)
 {
 	struct hci_dev_list_req *dl;
@@ -2666,7 +2669,6 @@
 			continue;
 
 		init_conn_list(dr->dev_id);
-		hciops_stop_inquiry(dr->dev_id);
 
 		dev->pending = 0;
 		hci_set_bit(PENDING_VERSION, &dev->pending);