[Skiboot] [PATCH 6/9] blocklevel: smart_write: Deny writes intersecting ECC protected regions

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


Other code paths don't handle writes spanning mixed regions, and it's a
headache, so deny it here too.

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

diff --git a/libflash/blocklevel.c b/libflash/blocklevel.c
index a72bed7422ae..f63fb5d266c6 100644
--- a/libflash/blocklevel.c
+++ b/libflash/blocklevel.c
@@ -512,6 +512,7 @@ int blocklevel_smart_write(struct blocklevel_device *bl, uint64_t pos, const voi
 	uint64_t ecc_start;
 	void *erase_buf;
 	int rc = 0;
+	int ecc_protection;
 
 	if (!buf || !bl) {
 		errno = EINVAL;
@@ -529,7 +530,14 @@ int blocklevel_smart_write(struct blocklevel_device *bl, uint64_t pos, const voi
 	if (rc)
 		return rc;
 
-	if (ecc_protected(bl, pos, len, &ecc_start)) {
+	ecc_protection = ecc_protected(bl, pos, len, &ecc_start);
+	if (ecc_protection == -1) {
+		FL_ERR("%s: Can't cope with partial ecc\n", __func__);
+		errno = EINVAL;
+		return FLASH_ERR_PARM_ERROR;
+	}
+
+	if (ecc_protection) {
 		FL_DBG("%s: region has ECC\n", __func__);
 
 		len = ecc_buffer_size(len);
-- 
2.20.1



More information about the Skiboot mailing list