Bluetooth: Fix potential race condition in bt_pub_key_gen()
It's possible for the Public Key to be available by the time that the bt_hci_cmd_send_sync() returns, so we need to make sure the flags have the right values no matter what. Change-Id: I053093b6611af360f52b14ddca50d409388f9475 Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
231050a966
commit
696b89da0f
1 changed files with 5 additions and 4 deletions
|
@ -4247,19 +4247,20 @@ int bt_pub_key_gen(struct bt_pub_key_cb *new_cb)
|
||||||
new_cb->_next = pub_key_cb;
|
new_cb->_next = pub_key_cb;
|
||||||
pub_key_cb = new_cb;
|
pub_key_cb = new_cb;
|
||||||
|
|
||||||
if (atomic_test_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY)) {
|
if (atomic_test_and_set_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atomic_clear_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY);
|
||||||
|
|
||||||
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_P256_PUBLIC_KEY, NULL, NULL);
|
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_P256_PUBLIC_KEY, NULL, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
BT_ERR("Sending LE P256 Public Key command failed");
|
||||||
|
atomic_clear_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY);
|
||||||
pub_key_cb = NULL;
|
pub_key_cb = NULL;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_set_bit(bt_dev.flags, BT_DEV_PUB_KEY_BUSY);
|
|
||||||
atomic_clear_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY);
|
|
||||||
|
|
||||||
for (cb = pub_key_cb; cb; cb = cb->_next) {
|
for (cb = pub_key_cb; cb; cb = cb->_next) {
|
||||||
if (cb != new_cb) {
|
if (cb != new_cb) {
|
||||||
cb->func(NULL);
|
cb->func(NULL);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue