Commit d9c78e9738ccd0017b10b8f44462aafb61904a4a

Authored by Adam Lee
Committed by Gustavo Padovan
1 parent 517828a879

Bluetooth: fix wrong use of PTR_ERR() in btusb

PTR_ERR() returns a signed long type value which is limited by IS_ERR(),
it must be a negative number whose range is [-MAX_ERRNO, 0).

The bug here returns negative numbers as error codes, then check it by
"if (ret < 0)", but -PTR_ERR() is actually positive. The wrong use here
leads to failure as below, even panic.

[   12.958920] Bluetooth: hci0 command 0xfc8e tx timeout
[   14.961765] Bluetooth: hci0 command 0xfc8e tx timeout
[   16.964688] Bluetooth: hci0 command 0xfc8e tx timeout
[   20.954501] Bluetooth: hci0 sending Intel patch command (0xfc8e) failed (-110)
[   22.957358] Bluetooth: hci0 command 0xfc8e tx timeout
[   30.948922] Bluetooth: hci0 sending Intel patch command (0xfc8e) failed (-110)
[   32.951780] Bluetooth: hci0 command 0xfc8e tx timeout
[   40.943359] Bluetooth: hci0 sending Intel patch command (0xfc8e) failed (-110)
[   42.946219] Bluetooth: hci0 command 0xfc8e tx timeout
[   50.937812] Bluetooth: hci0 sending Intel patch command (0xfc8e) failed (-110)
[   52.940670] Bluetooth: hci0 command 0xfc8e tx timeout
[   60.932236] Bluetooth: hci0 sending Intel patch command (0xfc8e) failed (-110)
[   62.935092] Bluetooth: hci0 command 0xfc8e tx timeout
[   70.926688] Bluetooth: hci0 sending Intel patch command (0xfc8e) failed (-110)
[   72.929545] Bluetooth: hci0 command 0xfc8e tx timeout
[   80.921111] Bluetooth: hci0 sending Intel patch command (0xfc8e) failed (-110)
[   82.923969] Bluetooth: hci0 command 0xfc2f tx timeout
[   90.915542] Bluetooth: hci0 sending Intel patch command (0xfc2f) failed (-110)
[   92.918406] Bluetooth: hci0 command 0xfc11 tx timeout
[  100.909955] Bluetooth: hci0 sending Intel patch command (0xfc11) failed (-110)
[  102.912858] Bluetooth: hci0 command 0xfc60 tx timeout
[  110.904394] Bluetooth: hci0 sending Intel patch command (0xfc60) failed (-110)
[  112.907293] Bluetooth: hci0 command 0xfc11 tx timeout
[  120.898831] Bluetooth: hci0 exiting Intel manufacturer mode failed (-110)
[  120.904757] bluetoothd[1030]: segfault at 4 ip 00007f8b2eb55236 sp 00007fff53ff6920 error 4 in bluetoothd[7f8b2eaff000+cb000]

Signed-off-by: Adam Lee <adam.lee@canonical.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Showing 1 changed file with 7 additions and 7 deletions Side-by-side Diff

drivers/bluetooth/btusb.c
... ... @@ -1093,7 +1093,7 @@
1093 1093 if (IS_ERR(skb)) {
1094 1094 BT_ERR("%s sending Intel patch command (0x%4.4x) failed (%ld)",
1095 1095 hdev->name, cmd->opcode, PTR_ERR(skb));
1096   - return -PTR_ERR(skb);
  1096 + return PTR_ERR(skb);
1097 1097 }
1098 1098  
1099 1099 /* It ensures that the returned event matches the event data read from
... ... @@ -1145,7 +1145,7 @@
1145 1145 if (IS_ERR(skb)) {
1146 1146 BT_ERR("%s sending initial HCI reset command failed (%ld)",
1147 1147 hdev->name, PTR_ERR(skb));
1148   - return -PTR_ERR(skb);
  1148 + return PTR_ERR(skb);
1149 1149 }
1150 1150 kfree_skb(skb);
1151 1151  
... ... @@ -1159,7 +1159,7 @@
1159 1159 if (IS_ERR(skb)) {
1160 1160 BT_ERR("%s reading Intel fw version command failed (%ld)",
1161 1161 hdev->name, PTR_ERR(skb));
1162   - return -PTR_ERR(skb);
  1162 + return PTR_ERR(skb);
1163 1163 }
1164 1164  
1165 1165 if (skb->len != sizeof(*ver)) {
... ... @@ -1217,7 +1217,7 @@
1217 1217 BT_ERR("%s entering Intel manufacturer mode failed (%ld)",
1218 1218 hdev->name, PTR_ERR(skb));
1219 1219 release_firmware(fw);
1220   - return -PTR_ERR(skb);
  1220 + return PTR_ERR(skb);
1221 1221 }
1222 1222  
1223 1223 if (skb->data[0]) {
... ... @@ -1274,7 +1274,7 @@
1274 1274 if (IS_ERR(skb)) {
1275 1275 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1276 1276 hdev->name, PTR_ERR(skb));
1277   - return -PTR_ERR(skb);
  1277 + return PTR_ERR(skb);
1278 1278 }
1279 1279 kfree_skb(skb);
1280 1280  
... ... @@ -1290,7 +1290,7 @@
1290 1290 if (IS_ERR(skb)) {
1291 1291 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1292 1292 hdev->name, PTR_ERR(skb));
1293   - return -PTR_ERR(skb);
  1293 + return PTR_ERR(skb);
1294 1294 }
1295 1295 kfree_skb(skb);
1296 1296  
... ... @@ -1308,7 +1308,7 @@
1308 1308 if (IS_ERR(skb)) {
1309 1309 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1310 1310 hdev->name, PTR_ERR(skb));
1311   - return -PTR_ERR(skb);
  1311 + return PTR_ERR(skb);
1312 1312 }
1313 1313 kfree_skb(skb);
1314 1314