Skip to contentSkip to conversation

cros_ec: Fix issue with cros_ec_flash_write command

PATCH New Moritz Fischer 1 participant 2 messages Sep 12, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cros_ec: Fix issue with cros_ec_flash_write command

This commit fixes an issue where data is written to an invalid memory location.
The issue has been introduced in commit 88364387 cros: add cros_ec_driver

Cc u-boot at lists.denx.de
---
 drivers/misc/cros_ec.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
drivers/misc/cros_ec.c +18 -7
index 44b4f59..6079e52 100644
@@ -760,15 +760,26 @@ int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, uint32_t size)
 static int cros_ec_flash_write_block(struct cros_ec_dev *dev,
 		const uint8_t *data, uint32_t offset, uint32_t size)
 {
-	struct ec_params_flash_write p;
+	struct ec_params_flash_write *p;
+	int ret;
 
-	p.offset = offset;
-	p.size = size;
-	assert(data && p.size <= EC_FLASH_WRITE_VER0_SIZE);
-	memcpy(&p + 1, data, p.size);
+	p = malloc(sizeof(*p) + size);
+	if (!p)
+		return -ENOMEM;
+
+
+	p->offset = offset;
+	p->size = size;
+	assert(data && p->size <= EC_FLASH_WRITE_VER0_SIZE);
+	memcpy(p + 1, data, p->size);
 
-	return ec_command_inptr(dev, EC_CMD_FLASH_WRITE, 0,
-			  &p, sizeof(p), NULL, 0) >= 0 ? 0 : -1;
+	ret = ec_command_inptr(dev, EC_CMD_FLASH_WRITE, 1,
+			  p, sizeof(*p) + size, NULL, 0) >= 0 ? 0 : -1;
+
+	free(p);
+
+
+	return ret;
 }
 
 /**
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 cros_ec: Fix issue with cros_ec_flash_write command

Hi Simon,

drivers/misc/cros_ec.c int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, uint32_t size) · line 777

Quoted 4 lines · Moritz Fischer
drivers/misc/cros_ec.c +2 -2
-       return ec_command_inptr(dev, EC_CMD_FLASH_WRITE, 0,
-                         &p, sizeof(p), NULL, 0) >= 0 ? 0 : -1;
+       ret = ec_command_inptr(dev, EC_CMD_FLASH_WRITE, 1,
+                         p, sizeof(*p) + size, NULL, 0) >= 0 ? 0 : -1;

This shouldn't touch the command version ... I'll resend v2 ... sorry for the noise ...

Moritz