aboutsummaryrefslogtreecommitdiff
path: root/libflash
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2019-10-03 15:23:40 +0930
committerOliver O'Halloran <oohall@gmail.com>2019-10-14 16:27:10 +1100
commitaa52f9439b91db5949c04acb8e1d2d21c37ddba5 (patch)
tree3f35074227b5b1817cbc3d8b2868138a61198b83 /libflash
parentbdbbfcacccdb768db587ef73a2a28cf3dc8ceda9 (diff)
downloadskiboot-aa52f9439b91db5949c04acb8e1d2d21c37ddba5.zip
skiboot-aa52f9439b91db5949c04acb8e1d2d21c37ddba5.tar.gz
skiboot-aa52f9439b91db5949c04acb8e1d2d21c37ddba5.tar.bz2
blocklevel: smart_write: Avoid reuse of formal parameters
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>
Diffstat (limited to 'libflash')
-rw-r--r--libflash/blocklevel.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/libflash/blocklevel.c b/libflash/blocklevel.c
index f63fb5d..07d3399 100644
--- a/libflash/blocklevel.c
+++ b/libflash/blocklevel.c
@@ -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;
@@ -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;
@@ -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 */
@@ -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;
}