Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bluetooth: hci_sync: Split hci_dev_open_sync

This splits hci_dev_open_sync so each stage is handle by its own
function so it is easier to identify each stage.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

+141 -114
+141 -114
net/bluetooth/hci_sync.c
··· 3875 3875 "advertised, but not supported.") 3876 3876 }; 3877 3877 3878 - int hci_dev_open_sync(struct hci_dev *hdev) 3878 + /* This function handles hdev setup stage: 3879 + * 3880 + * Calls hdev->setup 3881 + * Setup address if HCI_QUIRK_USE_BDADDR_PROPERTY is set. 3882 + */ 3883 + static int hci_dev_setup_sync(struct hci_dev *hdev) 3879 3884 { 3880 3885 int ret = 0; 3886 + bool invalid_bdaddr; 3887 + size_t i; 3888 + 3889 + if (!hci_dev_test_flag(hdev, HCI_SETUP) && 3890 + !test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) 3891 + return 0; 3892 + 3893 + bt_dev_dbg(hdev, ""); 3894 + 3895 + hci_sock_dev_event(hdev, HCI_DEV_SETUP); 3896 + 3897 + if (hdev->setup) 3898 + ret = hdev->setup(hdev); 3899 + 3900 + for (i = 0; i < ARRAY_SIZE(hci_broken_table); i++) { 3901 + if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) 3902 + bt_dev_warn(hdev, "%s", hci_broken_table[i].desc); 3903 + } 3904 + 3905 + /* The transport driver can set the quirk to mark the 3906 + * BD_ADDR invalid before creating the HCI device or in 3907 + * its setup callback. 3908 + */ 3909 + invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); 3910 + 3911 + if (!ret) { 3912 + if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) { 3913 + if (!bacmp(&hdev->public_addr, BDADDR_ANY)) 3914 + hci_dev_get_bd_addr_from_property(hdev); 3915 + 3916 + if (bacmp(&hdev->public_addr, BDADDR_ANY) && 3917 + hdev->set_bdaddr) { 3918 + ret = hdev->set_bdaddr(hdev, 3919 + &hdev->public_addr); 3920 + 3921 + /* If setting of the BD_ADDR from the device 3922 + * property succeeds, then treat the address 3923 + * as valid even if the invalid BD_ADDR 3924 + * quirk indicates otherwise. 3925 + */ 3926 + if (!ret) 3927 + invalid_bdaddr = false; 3928 + } 3929 + } 3930 + } 3931 + 3932 + /* The transport driver can set these quirks before 3933 + * creating the HCI device or in its setup callback. 3934 + * 3935 + * For the invalid BD_ADDR quirk it is possible that 3936 + * it becomes a valid address if the bootloader does 3937 + * provide it (see above). 3938 + * 3939 + * In case any of them is set, the controller has to 3940 + * start up as unconfigured. 3941 + */ 3942 + if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || 3943 + invalid_bdaddr) 3944 + hci_dev_set_flag(hdev, HCI_UNCONFIGURED); 3945 + 3946 + /* For an unconfigured controller it is required to 3947 + * read at least the version information provided by 3948 + * the Read Local Version Information command. 3949 + * 3950 + * If the set_bdaddr driver callback is provided, then 3951 + * also the original Bluetooth public device address 3952 + * will be read using the Read BD Address command. 3953 + */ 3954 + if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) 3955 + return hci_unconf_init_sync(hdev); 3956 + 3957 + return ret; 3958 + } 3959 + 3960 + /* This function handles hdev init stage: 3961 + * 3962 + * Calls hci_dev_setup_sync to perform setup stage 3963 + * Calls hci_init_sync to perform HCI command init sequence 3964 + */ 3965 + static int hci_dev_init_sync(struct hci_dev *hdev) 3966 + { 3967 + int ret; 3968 + 3969 + bt_dev_dbg(hdev, ""); 3970 + 3971 + atomic_set(&hdev->cmd_cnt, 1); 3972 + set_bit(HCI_INIT, &hdev->flags); 3973 + 3974 + ret = hci_dev_setup_sync(hdev); 3975 + 3976 + if (hci_dev_test_flag(hdev, HCI_CONFIG)) { 3977 + /* If public address change is configured, ensure that 3978 + * the address gets programmed. If the driver does not 3979 + * support changing the public address, fail the power 3980 + * on procedure. 3981 + */ 3982 + if (bacmp(&hdev->public_addr, BDADDR_ANY) && 3983 + hdev->set_bdaddr) 3984 + ret = hdev->set_bdaddr(hdev, &hdev->public_addr); 3985 + else 3986 + ret = -EADDRNOTAVAIL; 3987 + } 3988 + 3989 + if (!ret) { 3990 + if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && 3991 + !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { 3992 + ret = hci_init_sync(hdev); 3993 + if (!ret && hdev->post_init) 3994 + ret = hdev->post_init(hdev); 3995 + } 3996 + } 3997 + 3998 + /* If the HCI Reset command is clearing all diagnostic settings, 3999 + * then they need to be reprogrammed after the init procedure 4000 + * completed. 4001 + */ 4002 + if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && 4003 + !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && 4004 + hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) 4005 + ret = hdev->set_diag(hdev, true); 4006 + 4007 + if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { 4008 + msft_do_open(hdev); 4009 + aosp_do_open(hdev); 4010 + } 4011 + 4012 + clear_bit(HCI_INIT, &hdev->flags); 4013 + 4014 + return ret; 4015 + } 4016 + 4017 + int hci_dev_open_sync(struct hci_dev *hdev) 4018 + { 4019 + int ret; 3881 4020 3882 4021 bt_dev_dbg(hdev, ""); 3883 4022 ··· 4069 3930 set_bit(HCI_RUNNING, &hdev->flags); 4070 3931 hci_sock_dev_event(hdev, HCI_DEV_OPEN); 4071 3932 4072 - atomic_set(&hdev->cmd_cnt, 1); 4073 - set_bit(HCI_INIT, &hdev->flags); 4074 - 4075 - if (hci_dev_test_flag(hdev, HCI_SETUP) || 4076 - test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) { 4077 - bool invalid_bdaddr; 4078 - size_t i; 4079 - 4080 - hci_sock_dev_event(hdev, HCI_DEV_SETUP); 4081 - 4082 - if (hdev->setup) 4083 - ret = hdev->setup(hdev); 4084 - 4085 - for (i = 0; i < ARRAY_SIZE(hci_broken_table); i++) { 4086 - if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) 4087 - bt_dev_warn(hdev, "%s", 4088 - hci_broken_table[i].desc); 4089 - } 4090 - 4091 - /* The transport driver can set the quirk to mark the 4092 - * BD_ADDR invalid before creating the HCI device or in 4093 - * its setup callback. 4094 - */ 4095 - invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, 4096 - &hdev->quirks); 4097 - 4098 - if (ret) 4099 - goto setup_failed; 4100 - 4101 - if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) { 4102 - if (!bacmp(&hdev->public_addr, BDADDR_ANY)) 4103 - hci_dev_get_bd_addr_from_property(hdev); 4104 - 4105 - if (bacmp(&hdev->public_addr, BDADDR_ANY) && 4106 - hdev->set_bdaddr) { 4107 - ret = hdev->set_bdaddr(hdev, 4108 - &hdev->public_addr); 4109 - 4110 - /* If setting of the BD_ADDR from the device 4111 - * property succeeds, then treat the address 4112 - * as valid even if the invalid BD_ADDR 4113 - * quirk indicates otherwise. 4114 - */ 4115 - if (!ret) 4116 - invalid_bdaddr = false; 4117 - } 4118 - } 4119 - 4120 - setup_failed: 4121 - /* The transport driver can set these quirks before 4122 - * creating the HCI device or in its setup callback. 4123 - * 4124 - * For the invalid BD_ADDR quirk it is possible that 4125 - * it becomes a valid address if the bootloader does 4126 - * provide it (see above). 4127 - * 4128 - * In case any of them is set, the controller has to 4129 - * start up as unconfigured. 4130 - */ 4131 - if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || 4132 - invalid_bdaddr) 4133 - hci_dev_set_flag(hdev, HCI_UNCONFIGURED); 4134 - 4135 - /* For an unconfigured controller it is required to 4136 - * read at least the version information provided by 4137 - * the Read Local Version Information command. 4138 - * 4139 - * If the set_bdaddr driver callback is provided, then 4140 - * also the original Bluetooth public device address 4141 - * will be read using the Read BD Address command. 4142 - */ 4143 - if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) 4144 - ret = hci_unconf_init_sync(hdev); 4145 - } 4146 - 4147 - if (hci_dev_test_flag(hdev, HCI_CONFIG)) { 4148 - /* If public address change is configured, ensure that 4149 - * the address gets programmed. If the driver does not 4150 - * support changing the public address, fail the power 4151 - * on procedure. 4152 - */ 4153 - if (bacmp(&hdev->public_addr, BDADDR_ANY) && 4154 - hdev->set_bdaddr) 4155 - ret = hdev->set_bdaddr(hdev, &hdev->public_addr); 4156 - else 4157 - ret = -EADDRNOTAVAIL; 4158 - } 4159 - 4160 - if (!ret) { 4161 - if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && 4162 - !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { 4163 - ret = hci_init_sync(hdev); 4164 - if (!ret && hdev->post_init) 4165 - ret = hdev->post_init(hdev); 4166 - } 4167 - } 4168 - 4169 - /* If the HCI Reset command is clearing all diagnostic settings, 4170 - * then they need to be reprogrammed after the init procedure 4171 - * completed. 4172 - */ 4173 - if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && 4174 - !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && 4175 - hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) 4176 - ret = hdev->set_diag(hdev, true); 4177 - 4178 - if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { 4179 - msft_do_open(hdev); 4180 - aosp_do_open(hdev); 4181 - } 4182 - 4183 - clear_bit(HCI_INIT, &hdev->flags); 4184 - 3933 + ret = hci_dev_init_sync(hdev); 4185 3934 if (!ret) { 4186 3935 hci_dev_hold(hdev); 4187 3936 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);