diff mbox series

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

Message ID 20191003055342.7868-7-andrew@aj.id.au
State Accepted
Headers show
Series Clean up issues with opal-gard | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (1785745d5a7eaefd7d0c135f2a3b0f5d86aefec5)
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present

Commit Message

Andrew Jeffery Oct. 3, 2019, 5:53 a.m. UTC
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@aj.id.au>
---
 libflash/blocklevel.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

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);