mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-14 10:21:49 +00:00
btstack_tlv_flash_sector: assert hal_flash_sector->get_alignment is satisfied
This commit is contained in:
parent
cc480b8fa8
commit
14f9effccb
@ -188,6 +188,16 @@ static void btstack_tlv_flash_sector_migrate(btstack_tlv_flash_sector_t * self){
|
||||
self->write_offset = next_write_pos;
|
||||
}
|
||||
|
||||
// returns 1 == ok
|
||||
static int btstack_tlv_flash_sector_verify_alignment(btstack_tlv_flash_sector_t * self, uint32_t value_size){
|
||||
uint32_t aligment = self->hal_flash_sector_impl->get_alignment(self->hal_flash_sector_context);
|
||||
if (value_size % aligment){
|
||||
log_error("Value size %u not a multiply of flash alignment %u", value_size, aligment);
|
||||
return 0;
|
||||
};
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Value for Tag
|
||||
* @param tag
|
||||
@ -199,6 +209,9 @@ static int btstack_tlv_flash_sector_get_tag(void * context, uint32_t tag, uint8_
|
||||
|
||||
btstack_tlv_flash_sector_t * self = (btstack_tlv_flash_sector_t *) context;
|
||||
|
||||
// abort if data size not aligned with flash requirements
|
||||
if (!btstack_tlv_flash_sector_verify_alignment(self, buffer_size)) return 0;
|
||||
|
||||
uint32_t tag_index = 0;
|
||||
uint32_t tag_len = 0;
|
||||
tlv_iterator_t it;
|
||||
@ -228,6 +241,9 @@ static void btstack_tlv_flash_sector_store_tag(void * context, uint32_t tag, con
|
||||
|
||||
btstack_tlv_flash_sector_t * self = (btstack_tlv_flash_sector_t *) context;
|
||||
|
||||
// abort if data size not aligned with flash requirements
|
||||
if (!btstack_tlv_flash_sector_verify_alignment(self, data_size)) return;
|
||||
|
||||
if (self->write_offset + 8 + data_size > self->hal_flash_sector_impl->get_size(self->hal_flash_sector_context)){
|
||||
btstack_tlv_flash_sector_migrate(self);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user