Skip to content

Commit 5d46a0c

Browse files
jori-nordicstephanosio
authored andcommitted
Bluetooth: host: fix subtle bug in db_hash_process
Fixes a bug introduced in the previous refactoring: we would always mark all peers as change-unaware. Now we only do so when the hash has been recalculated. Signed-off-by: Jonathan Rico <[email protected]>
1 parent 9fdc86b commit 5d46a0c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,9 @@ static void sc_indicate(uint16_t start, uint16_t end);
876876

877877
static void db_hash_process(struct k_work *work)
878878
{
879-
if (!atomic_test_bit(gatt_sc.flags, DB_HASH_VALID)) {
879+
bool new_hash = !atomic_test_bit(gatt_sc.flags, DB_HASH_VALID);
880+
881+
if (new_hash) {
880882
db_hash_gen();
881883
}
882884

@@ -893,13 +895,15 @@ static void db_hash_process(struct k_work *work)
893895
return;
894896
}
895897

896-
if (!already_processed) {
898+
if (already_processed) {
897899
/* hash has been loaded from settings and we have already
898900
* executed the special case below once. we can now safely save
899-
* the calculated hash to settings.
901+
* the calculated hash to settings (if it has changed).
900902
*/
901-
set_all_change_unaware();
902-
db_hash_store();
903+
if (new_hash) {
904+
set_all_change_unaware();
905+
db_hash_store();
906+
}
903907
} else {
904908
/* this is only supposed to run once, on bootup, after the hash
905909
* has been loaded from settings.

0 commit comments

Comments
 (0)