c
17 	hci_unregister_suspend_notifier(hdev);
18 
19 	hci_dev_do_close(hdev);
20 
21 	// Move msft_unregister after all operations on hdev are done
22 	if (!test_bit(HCI_INIT, &hdev->flags) &&
23 	    !hci_dev_test_flag(hdev, HCI_SETUP) &&
24 	    !hci_dev_test_flag(hdev, HCI_CONFIG)) {
25 		hci_dev_lock(hdev);
26 		mgmt_index_removed(hdev);
27 		hci_dev_unlock(hdev);
28 	}
29 
30 	/* mgmt_index_removed should take care of emptying the
31 	 * pending list */
32 	BUG_ON(!list_empty(&hdev->mgmt_pending));
33 
34 	hci_sock_dev_event(hdev, HCI_DEV_UNREG);
35 
36 	if (hdev->rfkill) {
37 		rfkill_unregister(hdev->rfkill);
38 		rfkill_destroy(hdev->rfkill);
39 	}
40 
41 	device_del(&hdev->dev);
42 
43 	// Now it's safe to call msft_unregister
44 	msft_unregister(hdev);
45 
46 	/* Actual cleanup is deferred until hci_release_dev(). */
47 	hci_dev_put(hdev);
