Skip to content

Commit 884ebbb

Browse files
joerchancarlescufi
authored andcommitted
Bluetooth: host: Fix unexpected control flow
Fix unexpected control flow in host keys module. A continue in a do while false act the same as a break. This entire construct can be replaced with a simple if else control flow. Fixes: #38014 Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
1 parent 3a8190a commit 884ebbb

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

subsys/bluetooth/host/keys.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,24 +396,21 @@ static int keys_set(const char *name, size_t len_rd, settings_read_cb read_cb,
396396
return -ENOMEM;
397397
}
398398
if (len != BT_KEYS_STORAGE_LEN) {
399-
do {
399+
if (IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST) &&
400+
len == BT_KEYS_STORAGE_LEN_COMPAT) {
400401
/* Load shorter structure for compatibility with old
401402
* records format with no counter.
402403
*/
403-
if (IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST) &&
404-
len == BT_KEYS_STORAGE_LEN_COMPAT) {
405-
BT_WARN("Keys for %s have no aging counter",
406-
bt_addr_le_str(&addr));
407-
memcpy(keys->storage_start, val, len);
408-
continue;
409-
}
410-
404+
BT_WARN("Keys for %s have no aging counter",
405+
bt_addr_le_str(&addr));
406+
memcpy(keys->storage_start, val, len);
407+
} else {
411408
BT_ERR("Invalid key length %zd != %zu", len,
412409
BT_KEYS_STORAGE_LEN);
413410
bt_keys_clear(keys);
414411

415412
return -EINVAL;
416-
} while (0);
413+
}
417414
} else {
418415
memcpy(keys->storage_start, val, len);
419416
}

0 commit comments

Comments
 (0)