Skip to content

Commit

Permalink
blocklevel: smart_write: Avoid reuse of formal parameters
Browse files Browse the repository at this point in the history
Lays the ground-work for fixing unaligned writes to ECC protected
partitions.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
amboar authored and oohal committed Oct 14, 2019
1 parent bdbbfca commit aa52f94
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions libflash/blocklevel.c
Expand Up @@ -508,6 +508,8 @@ int blocklevel_smart_write(struct blocklevel_device *bl, uint64_t pos, const voi
{
uint32_t erase_size;
const void *write_buf = buf;
uint64_t write_len;
uint64_t write_pos;
void *ecc_buf = NULL;
uint64_t ecc_start;
void *erase_buf;
Expand Down Expand Up @@ -556,6 +558,9 @@ int blocklevel_smart_write(struct blocklevel_device *bl, uint64_t pos, const voi
write_buf = ecc_buf;
}

write_pos = pos;
write_len = len;

erase_buf = malloc(erase_size);
if (!erase_buf) {
errno = ENOMEM;
Expand All @@ -567,10 +572,11 @@ int blocklevel_smart_write(struct blocklevel_device *bl, uint64_t pos, const voi
if (rc)
goto out_free;

while (len > 0) {
uint32_t erase_block = pos & ~(erase_size - 1);
uint32_t block_offset = pos & (erase_size - 1);
uint32_t chunk_size = erase_size > len ? len : erase_size;
while (write_len > 0) {
uint32_t erase_block = write_pos & ~(erase_size - 1);
uint32_t block_offset = write_pos & (erase_size - 1);
uint32_t chunk_size = erase_size > write_len ?
write_len : erase_size;
int cmp;

/* Write crosses an erase boundary, shrink the write to the boundary */
Expand Down Expand Up @@ -600,8 +606,9 @@ int blocklevel_smart_write(struct blocklevel_device *bl, uint64_t pos, const voi
} else {
FL_DBG("clean\n");
}
len -= chunk_size;
pos += chunk_size;

write_len -= chunk_size;
write_pos += chunk_size;
write_buf += chunk_size;
}

Expand Down

0 comments on commit aa52f94

Please sign in to comment.