[Skiboot] [PATCH 7/9] blocklevel: smart_write: Avoid reuse of formal parameters

Andrew Jeffery andrew at aj.id.au
Thu Oct 3 15:53:40 AEST 2019


Lays the ground-work for fixing unaligned writes to ECC protected
partitions.

Signed-off-by: Andrew Jeffery <andrew at aj.id.au>
---
 libflash/blocklevel.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/libflash/blocklevel.c b/libflash/blocklevel.c
index f63fb5d266c6..07d339974462 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;
 	}
 
-- 
2.20.1



More information about the Skiboot mailing list