Bluetooth: Host: Fix wrong ID being stored

Fix an issue causing a wrong Bluetooth identity value to be stored. It
was happening because the `bt_dev.id_count` was incremented after the
settings being stored.

To fix this, `bt_dev.id_count` is now incremented right before the ID
creation and is decremented if the ID creation failed.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
This commit is contained in:
Théo Battrel 2023-06-14 15:28:42 +02:00 committed by Anas Nashif
parent 09085ef63c
commit 363676764a

View file

@ -1273,12 +1273,11 @@ int bt_id_create(bt_addr_le_t *addr, uint8_t *irk)
}
}
new_id = bt_dev.id_count;
new_id = bt_dev.id_count++;
err = id_create(new_id, addr, irk);
if (err) {
bt_dev.id_count--;
return err;
} else {
bt_dev.id_count++;
}
return new_id;