CHROMIUM: Bluetooth: Move sysfs init to beginning of af_bluetooth

This allows the config sysfs file to be exposed very early without
waiting any real Bluetooth device to be recognized, since we want to be
able to set the LE splitter enabled/disabled state very early.

BUG=b:74813838
TEST=Without any Bluetooth device, run "modprobe bluetooth" and check
that /sys/devices/virtual/misc/hci_le exists.

Change-Id: I622e46be075d08f32bb3eada2972b9a09f6b9d57
Signed-off-by: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1344630
Reviewed-by: Dmitry Grinberg <dmitrygr@google.com>
diff --git a/include/net/bluetooth/hci_le_splitter.h b/include/net/bluetooth/hci_le_splitter.h
index 09e1169..22bef00 100644
--- a/include/net/bluetooth/hci_le_splitter.h
+++ b/include/net/bluetooth/hci_le_splitter.h
@@ -33,6 +33,7 @@
 
 #ifdef CONFIG_BT_HCI_LE_SPLITTER
 
+int hci_le_splitter_sysfs_init(void);
 void hci_le_splitter_init_start(struct hci_dev *hdev);
 int hci_le_splitter_init_done(struct hci_dev *hdev);
 void hci_le_splitter_init_fail(struct hci_dev *hdev);
@@ -77,6 +78,11 @@
 
 }
 
+static inline int hci_le_splitter_sysfs_init(void)
+{
+	return 0;
+}
+
 #endif
 
 #endif /* __HCI_LE_SPLITTER_H */
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 8f9c5e9..a5b1302 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -30,6 +30,7 @@
 #include <asm/ioctls.h>
 
 #include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_le_splitter.h>
 #include <linux/proc_fs.h>
 
 #include "leds.h"
@@ -774,6 +775,10 @@
 
 	BT_INFO("HCI device and connection manager initialized");
 
+	err = hci_le_splitter_sysfs_init();
+	if (err < 0)
+		goto error;
+
 	err = hci_sock_init();
 	if (err < 0)
 		goto error;
diff --git a/net/bluetooth/hci_le_splitter.c b/net/bluetooth/hci_le_splitter.c
index 1bf85dd..330e226 100644
--- a/net/bluetooth/hci_le_splitter.c
+++ b/net/bluetooth/hci_le_splitter.c
@@ -49,9 +49,6 @@
 /* "is chip in state to talk to second stack?" */
 static atomic_t chip_ready_for_second_stack = ATOMIC_INIT(0);
 
-/* "is one-time init done?" */
-static atomic_t one_time_init_done = ATOMIC_INIT(0);
-
 /* protects messages waiting to be read */
 static DEFINE_MUTEX(usr_msg_q_lock);
 static DECLARE_WAIT_QUEUE_HEAD(usr_msg_wait_q);
@@ -140,8 +137,6 @@
 
 void hci_le_splitter_init_start(struct hci_dev *hdev)
 {
-	int err;
-
 	mutex_lock(&hci_state_lock);
 
 	if (hci_le_splitter_set_our_dev(hdev))
@@ -149,18 +144,6 @@
 	else
 		pr_info("HCI splitter ignoring dev\n");
 
-	if (!atomic_cmpxchg(&one_time_init_done, 0, 1)) {
-
-		skb_queue_head_init(&usr_msg_q);
-		misc_register(&mdev);
-
-		err = device_create_file(mdev.this_device, &sysfs_attr);
-		if (err) {
-			pr_err("Cannot create sysfs file (%d) - on by default\n", err);
-			splitter_enable_state = SPLITTER_STATE_ENABLED;
-		}
-	}
-
 	mutex_unlock(&hci_state_lock);
 }
 
@@ -1075,3 +1058,19 @@
 	return ret;
 }
 
+int hci_le_splitter_sysfs_init(void)
+{
+	int err;
+
+	BT_INFO("Initializing LE splitter sysfs");
+	skb_queue_head_init(&usr_msg_q);
+	misc_register(&mdev);
+
+	err = device_create_file(mdev.this_device, &sysfs_attr);
+	if (err) {
+		pr_err("Cannot create sysfs file (%d) - off by default\n", err);
+		splitter_enable_state = SPLITTER_STATE_DISABLED;
+		return -1;
+	}
+	return 0;
+}