Bluetooth: Fix public key callback management

Clear the callback list once generation is complete and we've done
calling all callbacks. This lets us use bt_pub_key_gen() multiple
times, which before this patch could have resulted in a corrupt linked
list.

Also remove redundant callback dispatching from bt_pub_key_gen() since
the function checks for the PUB_KEY_BUSY flag in the beginning, i.e.
there cannot be other pending generation actions at this point in the
code.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2019-06-25 16:13:58 +03:00 committed by Johan Hedberg
commit d6c34c4644

View file

@ -3065,6 +3065,8 @@ static void le_pkey_complete(struct net_buf *buf)
for (cb = pub_key_cb; cb; cb = cb->_next) {
cb->func(evt->status ? NULL : evt->key);
}
pub_key_cb = NULL;
}
static void le_dhkey_complete(struct net_buf *buf)
@ -5850,7 +5852,6 @@ int bt_br_set_discoverable(bool enable)
#if defined(CONFIG_BT_ECC)
int bt_pub_key_gen(struct bt_pub_key_cb *new_cb)
{
struct bt_pub_key_cb *cb;
int err;
/*
@ -5882,12 +5883,6 @@ int bt_pub_key_gen(struct bt_pub_key_cb *new_cb)
return err;
}
for (cb = pub_key_cb; cb; cb = cb->_next) {
if (cb != new_cb) {
cb->func(NULL);
}
}
return 0;
}