aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/mgmt.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2011-02-19 10:06:02 -0500
committerGustavo F. Padovan <padovan@profusion.mobi>2011-02-21 15:22:45 -0500
commita664b5bc77fbc80c163de5606114659d3cbeb043 (patch)
tree4cf0b60af8a38ea3f1d8a00caf4d82289333b680 /net/bluetooth/mgmt.c
parenta958355699dd90ba69951bdf55dda00e3e97222c (diff)
Bluetooth: Fix unnecessary list traversal in mgmt_pending_remove
All of the places that need to call mgmt_pending_remove already have a pointer to the pending command, so searching for the command in the list doesn't make sense. The added benefit is that many places that previously had to call list_del + mgmt_pending_free can just call mgmt_pending_remove now. Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r--net/bluetooth/mgmt.c42
1 files changed, 14 insertions, 28 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 46e2c39c895..982becd33ee 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -290,14 +290,8 @@ static struct pending_cmd *mgmt_pending_find(u16 opcode, int index)
290 return NULL; 290 return NULL;
291} 291}
292 292
293static void mgmt_pending_remove(u16 opcode, int index) 293static void mgmt_pending_remove(struct pending_cmd *cmd)
294{ 294{
295 struct pending_cmd *cmd;
296
297 cmd = mgmt_pending_find(opcode, index);
298 if (cmd == NULL)
299 return;
300
301 list_del(&cmd->list); 295 list_del(&cmd->list);
302 mgmt_pending_free(cmd); 296 mgmt_pending_free(cmd);
303} 297}
@@ -401,7 +395,7 @@ static int set_discoverable(struct sock *sk, unsigned char *data, u16 len)
401 395
402 err = hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); 396 err = hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
403 if (err < 0) 397 if (err < 0)
404 mgmt_pending_remove(MGMT_OP_SET_DISCOVERABLE, dev_id); 398 mgmt_pending_remove(cmd);
405 399
406failed: 400failed:
407 hci_dev_unlock_bh(hdev); 401 hci_dev_unlock_bh(hdev);
@@ -459,7 +453,7 @@ static int set_connectable(struct sock *sk, unsigned char *data, u16 len)
459 453
460 err = hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan); 454 err = hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
461 if (err < 0) 455 if (err < 0)
462 mgmt_pending_remove(MGMT_OP_SET_CONNECTABLE, dev_id); 456 mgmt_pending_remove(cmd);
463 457
464failed: 458failed:
465 hci_dev_unlock_bh(hdev); 459 hci_dev_unlock_bh(hdev);
@@ -881,7 +875,7 @@ static int disconnect(struct sock *sk, unsigned char *data, u16 len)
881 875
882 err = hci_send_cmd(hdev, HCI_OP_DISCONNECT, sizeof(dc), &dc); 876 err = hci_send_cmd(hdev, HCI_OP_DISCONNECT, sizeof(dc), &dc);
883 if (err < 0) 877 if (err < 0)
884 mgmt_pending_remove(MGMT_OP_DISCONNECT, dev_id); 878 mgmt_pending_remove(cmd);
885 879
886failed: 880failed:
887 hci_dev_unlock_bh(hdev); 881 hci_dev_unlock_bh(hdev);
@@ -983,7 +977,7 @@ static int pin_code_reply(struct sock *sk, unsigned char *data, u16 len)
983 977
984 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply); 978 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_REPLY, sizeof(reply), &reply);
985 if (err < 0) 979 if (err < 0)
986 mgmt_pending_remove(MGMT_OP_PIN_CODE_REPLY, dev_id); 980 mgmt_pending_remove(cmd);
987 981
988failed: 982failed:
989 hci_dev_unlock_bh(hdev); 983 hci_dev_unlock_bh(hdev);
@@ -1026,7 +1020,7 @@ static int pin_code_neg_reply(struct sock *sk, unsigned char *data, u16 len)
1026 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, sizeof(bdaddr_t), 1020 err = hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, sizeof(bdaddr_t),
1027 &cp->bdaddr); 1021 &cp->bdaddr);
1028 if (err < 0) 1022 if (err < 0)
1029 mgmt_pending_remove(MGMT_OP_PIN_CODE_NEG_REPLY, dev_id); 1023 mgmt_pending_remove(cmd);
1030 1024
1031failed: 1025failed:
1032 hci_dev_unlock_bh(hdev); 1026 hci_dev_unlock_bh(hdev);
@@ -1107,8 +1101,7 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status)
1107 1101
1108 hci_conn_put(conn); 1102 hci_conn_put(conn);
1109 1103
1110 list_del(&cmd->list); 1104 mgmt_pending_remove(cmd);
1111 mgmt_pending_free(cmd);
1112} 1105}
1113 1106
1114static void pairing_complete_cb(struct hci_conn *conn, u8 status) 1107static void pairing_complete_cb(struct hci_conn *conn, u8 status)
@@ -1230,10 +1223,8 @@ static int user_confirm_reply(struct sock *sk, unsigned char *data, u16 len,
1230 } 1223 }
1231 1224
1232 err = hci_send_cmd(hdev, hci_op, sizeof(cp->bdaddr), &cp->bdaddr); 1225 err = hci_send_cmd(hdev, hci_op, sizeof(cp->bdaddr), &cp->bdaddr);
1233 if (err < 0) { 1226 if (err < 0)
1234 list_del(&cmd->list); 1227 mgmt_pending_remove(cmd);
1235 mgmt_pending_free(cmd);
1236 }
1237 1228
1238failed: 1229failed:
1239 hci_dev_unlock_bh(hdev); 1230 hci_dev_unlock_bh(hdev);
@@ -1494,8 +1485,7 @@ static void disconnect_rsp(struct pending_cmd *cmd, void *data)
1494 *sk = cmd->sk; 1485 *sk = cmd->sk;
1495 sock_hold(*sk); 1486 sock_hold(*sk);
1496 1487
1497 list_del(&cmd->list); 1488 mgmt_pending_remove(cmd);
1498 mgmt_pending_free(cmd);
1499} 1489}
1500 1490
1501int mgmt_disconnected(u16 index, bdaddr_t *bdaddr) 1491int mgmt_disconnected(u16 index, bdaddr_t *bdaddr)
@@ -1528,8 +1518,7 @@ int mgmt_disconnect_failed(u16 index)
1528 1518
1529 err = cmd_status(cmd->sk, MGMT_OP_DISCONNECT, EIO); 1519 err = cmd_status(cmd->sk, MGMT_OP_DISCONNECT, EIO);
1530 1520
1531 list_del(&cmd->list); 1521 mgmt_pending_remove(cmd);
1532 mgmt_pending_free(cmd);
1533 1522
1534 return err; 1523 return err;
1535} 1524}
@@ -1571,8 +1560,7 @@ int mgmt_pin_code_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status)
1571 1560
1572 err = cmd_complete(cmd->sk, MGMT_OP_PIN_CODE_REPLY, &rp, sizeof(rp)); 1561 err = cmd_complete(cmd->sk, MGMT_OP_PIN_CODE_REPLY, &rp, sizeof(rp));
1573 1562
1574 list_del(&cmd->list); 1563 mgmt_pending_remove(cmd);
1575 mgmt_pending_free(cmd);
1576 1564
1577 return err; 1565 return err;
1578} 1566}
@@ -1594,8 +1582,7 @@ int mgmt_pin_code_neg_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status)
1594 err = cmd_complete(cmd->sk, MGMT_OP_PIN_CODE_NEG_REPLY, 1582 err = cmd_complete(cmd->sk, MGMT_OP_PIN_CODE_NEG_REPLY,
1595 &rp, sizeof(rp)); 1583 &rp, sizeof(rp));
1596 1584
1597 list_del(&cmd->list); 1585 mgmt_pending_remove(cmd);
1598 mgmt_pending_free(cmd);
1599 1586
1600 return err; 1587 return err;
1601} 1588}
@@ -1629,8 +1616,7 @@ static int confirm_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status,
1629 rp.status = status; 1616 rp.status = status;
1630 err = cmd_complete(cmd->sk, opcode, &rp, sizeof(rp)); 1617 err = cmd_complete(cmd->sk, opcode, &rp, sizeof(rp));
1631 1618
1632 list_del(&cmd->list); 1619 mgmt_pending_remove(cmd);
1633 mgmt_pending_free(cmd);
1634 1620
1635 return err; 1621 return err;
1636} 1622}