summaryrefslogtreecommitdiffstats
path: root/drivers/bluetooth
diff options
context:
space:
mode:
authorMatthias Kaehlcke <mka@chromium.org>2019-03-11 14:38:31 -0400
committerMarcel Holtmann <marcel@holtmann.org>2019-04-23 12:09:07 -0400
commit4fdd5a4f8b4407c21897dbfba9d0ee77eb80a42c (patch)
treeca09ef8d7b5514ac0ea040f8ceae93bf0ebd6429 /drivers/bluetooth
parent9aebfd4a2200ab8075e44379c758bccefdc589bb (diff)
Bluetooth: hci_qca: Add helper function to get the chip family
Many functions obtain a 'struct qca_serdev' only to read the btsoc_type field. Add a helper function that encapsulates this. This also fixes crashes observed on platforms with ROME controllers that are instantiated through ldisc and not as serdev clients. The crashes are caused by NULL pointer dereferentiations, which stem from the driver's assumption that a QCA HCI device is always associated with a serdev device. Fixes: fa9ad876b8e0 ("Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990") Reported-by: Balakrishna Godavarthi <bgodavar@codeaurora.org> Signed-off-by: Matthias Kaehlcke <mka@chromium.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'drivers/bluetooth')
-rw-r--r--drivers/bluetooth/hci_qca.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index 237aea34b69f..4ea995d610d2 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -174,6 +174,21 @@ static int qca_power_setup(struct hci_uart *hu, bool on);
174static void qca_power_shutdown(struct hci_uart *hu); 174static void qca_power_shutdown(struct hci_uart *hu);
175static int qca_power_off(struct hci_dev *hdev); 175static int qca_power_off(struct hci_dev *hdev);
176 176
177static enum qca_btsoc_type qca_soc_type(struct hci_uart *hu)
178{
179 enum qca_btsoc_type soc_type;
180
181 if (hu->serdev) {
182 struct qca_serdev *qsd = serdev_device_get_drvdata(hu->serdev);
183
184 soc_type = qsd->btsoc_type;
185 } else {
186 soc_type = QCA_ROME;
187 }
188
189 return soc_type;
190}
191
177static void __serial_clock_on(struct tty_struct *tty) 192static void __serial_clock_on(struct tty_struct *tty)
178{ 193{
179 /* TODO: Some chipset requires to enable UART clock on client 194 /* TODO: Some chipset requires to enable UART clock on client
@@ -963,7 +978,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
963{ 978{
964 struct hci_uart *hu = hci_get_drvdata(hdev); 979 struct hci_uart *hu = hci_get_drvdata(hdev);
965 struct qca_data *qca = hu->priv; 980 struct qca_data *qca = hu->priv;
966 struct qca_serdev *qcadev;
967 struct sk_buff *skb; 981 struct sk_buff *skb;
968 u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 }; 982 u8 cmd[] = { 0x01, 0x48, 0xFC, 0x01, 0x00 };
969 983
@@ -985,8 +999,6 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
985 skb_queue_tail(&qca->txq, skb); 999 skb_queue_tail(&qca->txq, skb);
986 hci_uart_tx_wakeup(hu); 1000 hci_uart_tx_wakeup(hu);
987 1001
988 qcadev = serdev_device_get_drvdata(hu->serdev);
989
990 /* Wait for the baudrate change request to be sent */ 1002 /* Wait for the baudrate change request to be sent */
991 1003
992 while (!skb_queue_empty(&qca->txq)) 1004 while (!skb_queue_empty(&qca->txq))
@@ -996,7 +1008,7 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate)
996 msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS)); 1008 msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS));
997 1009
998 /* Give the controller time to process the request */ 1010 /* Give the controller time to process the request */
999 if (qcadev->btsoc_type == QCA_WCN3990) 1011 if (qca_soc_type(hu) == QCA_WCN3990)
1000 msleep(10); 1012 msleep(10);
1001 else 1013 else
1002 msleep(300); 1014 msleep(300);
@@ -1072,10 +1084,7 @@ static unsigned int qca_get_speed(struct hci_uart *hu,
1072 1084
1073static int qca_check_speeds(struct hci_uart *hu) 1085static int qca_check_speeds(struct hci_uart *hu)
1074{ 1086{
1075 struct qca_serdev *qcadev; 1087 if (qca_soc_type(hu) == QCA_WCN3990) {
1076
1077 qcadev = serdev_device_get_drvdata(hu->serdev);
1078 if (qcadev->btsoc_type == QCA_WCN3990) {
1079 if (!qca_get_speed(hu, QCA_INIT_SPEED) && 1088 if (!qca_get_speed(hu, QCA_INIT_SPEED) &&
1080 !qca_get_speed(hu, QCA_OPER_SPEED)) 1089 !qca_get_speed(hu, QCA_OPER_SPEED))
1081 return -EINVAL; 1090 return -EINVAL;
@@ -1091,7 +1100,6 @@ static int qca_check_speeds(struct hci_uart *hu)
1091static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type) 1100static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
1092{ 1101{
1093 unsigned int speed, qca_baudrate; 1102 unsigned int speed, qca_baudrate;
1094 struct qca_serdev *qcadev;
1095 int ret = 0; 1103 int ret = 0;
1096 1104
1097 if (speed_type == QCA_INIT_SPEED) { 1105 if (speed_type == QCA_INIT_SPEED) {
@@ -1099,6 +1107,8 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
1099 if (speed) 1107 if (speed)
1100 host_set_baudrate(hu, speed); 1108 host_set_baudrate(hu, speed);
1101 } else { 1109 } else {
1110 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1111
1102 speed = qca_get_speed(hu, QCA_OPER_SPEED); 1112 speed = qca_get_speed(hu, QCA_OPER_SPEED);
1103 if (!speed) 1113 if (!speed)
1104 return 0; 1114 return 0;
@@ -1106,8 +1116,7 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
1106 /* Disable flow control for wcn3990 to deassert RTS while 1116 /* Disable flow control for wcn3990 to deassert RTS while
1107 * changing the baudrate of chip and host. 1117 * changing the baudrate of chip and host.
1108 */ 1118 */
1109 qcadev = serdev_device_get_drvdata(hu->serdev); 1119 if (soc_type == QCA_WCN3990)
1110 if (qcadev->btsoc_type == QCA_WCN3990)
1111 hci_uart_set_flow_control(hu, true); 1120 hci_uart_set_flow_control(hu, true);
1112 1121
1113 qca_baudrate = qca_get_baudrate_value(speed); 1122 qca_baudrate = qca_get_baudrate_value(speed);
@@ -1119,7 +1128,7 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type)
1119 host_set_baudrate(hu, speed); 1128 host_set_baudrate(hu, speed);
1120 1129
1121error: 1130error:
1122 if (qcadev->btsoc_type == QCA_WCN3990) 1131 if (soc_type == QCA_WCN3990)
1123 hci_uart_set_flow_control(hu, false); 1132 hci_uart_set_flow_control(hu, false);
1124 } 1133 }
1125 1134
@@ -1181,12 +1190,10 @@ static int qca_setup(struct hci_uart *hu)
1181 struct hci_dev *hdev = hu->hdev; 1190 struct hci_dev *hdev = hu->hdev;
1182 struct qca_data *qca = hu->priv; 1191 struct qca_data *qca = hu->priv;
1183 unsigned int speed, qca_baudrate = QCA_BAUDRATE_115200; 1192 unsigned int speed, qca_baudrate = QCA_BAUDRATE_115200;
1184 struct qca_serdev *qcadev; 1193 enum qca_btsoc_type soc_type = qca_soc_type(hu);
1185 int ret; 1194 int ret;
1186 int soc_ver = 0; 1195 int soc_ver = 0;
1187 1196
1188 qcadev = serdev_device_get_drvdata(hu->serdev);
1189
1190 ret = qca_check_speeds(hu); 1197 ret = qca_check_speeds(hu);
1191 if (ret) 1198 if (ret)
1192 return ret; 1199 return ret;
@@ -1194,7 +1201,7 @@ static int qca_setup(struct hci_uart *hu)
1194 /* Patch downloading has to be done without IBS mode */ 1201 /* Patch downloading has to be done without IBS mode */
1195 clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags); 1202 clear_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
1196 1203
1197 if (qcadev->btsoc_type == QCA_WCN3990) { 1204 if (soc_type == QCA_WCN3990) {
1198 bt_dev_info(hdev, "setting up wcn3990"); 1205 bt_dev_info(hdev, "setting up wcn3990");
1199 1206
1200 /* Enable NON_PERSISTENT_SETUP QUIRK to ensure to execute 1207 /* Enable NON_PERSISTENT_SETUP QUIRK to ensure to execute
@@ -1225,7 +1232,7 @@ static int qca_setup(struct hci_uart *hu)
1225 qca_baudrate = qca_get_baudrate_value(speed); 1232 qca_baudrate = qca_get_baudrate_value(speed);
1226 } 1233 }
1227 1234
1228 if (qcadev->btsoc_type != QCA_WCN3990) { 1235 if (soc_type != QCA_WCN3990) {
1229 /* Get QCA version information */ 1236 /* Get QCA version information */
1230 ret = qca_read_soc_version(hdev, &soc_ver); 1237 ret = qca_read_soc_version(hdev, &soc_ver);
1231 if (ret) 1238 if (ret)
@@ -1234,7 +1241,7 @@ static int qca_setup(struct hci_uart *hu)
1234 1241
1235 bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver); 1242 bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
1236 /* Setup patch / NVM configurations */ 1243 /* Setup patch / NVM configurations */
1237 ret = qca_uart_setup(hdev, qca_baudrate, qcadev->btsoc_type, soc_ver); 1244 ret = qca_uart_setup(hdev, qca_baudrate, soc_type, soc_ver);
1238 if (!ret) { 1245 if (!ret) {
1239 set_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags); 1246 set_bit(STATE_IN_BAND_SLEEP_ENABLED, &qca->flags);
1240 qca_debugfs_init(hdev); 1247 qca_debugfs_init(hdev);
@@ -1250,7 +1257,7 @@ static int qca_setup(struct hci_uart *hu)
1250 } 1257 }
1251 1258
1252 /* Setup bdaddr */ 1259 /* Setup bdaddr */
1253 if (qcadev->btsoc_type == QCA_WCN3990) 1260 if (soc_type == QCA_WCN3990)
1254 hu->hdev->set_bdaddr = qca_set_bdaddr; 1261 hu->hdev->set_bdaddr = qca_set_bdaddr;
1255 else 1262 else
1256 hu->hdev->set_bdaddr = qca_set_bdaddr_rome; 1263 hu->hdev->set_bdaddr = qca_set_bdaddr_rome;