When dealing with env data not aligned to flash blocks flash_write_buf()
has to use an extra buffer. It reads existing flash content to it,
modifies required part and writes it back.
While reading and writing a size stored in "write_total" is used. It's
what should be used when allocating the buffer too.
In some cases allocating memory of "erase_len" size could result in
allocating too big buffer. That wouldn't break anything but it was
making code less intuitive.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block back again.
*/
if (write_total > count) {
- data = malloc(erase_len);
+ data = malloc(write_total);
if (!data) {
fprintf(stderr,
"Cannot malloc %zu bytes: %s\n",
- erase_len, strerror(errno));
+ write_total, strerror(errno));
return -1;
}