summaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias.schiffer@ew.tq-group.com>2018-11-23 15:50:15 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-11-26 08:46:23 +0100
commitb5ef34499a3064680918d91ecdea74ddcf98716e (patch)
tree72ea9efd262299336ba47d61f65688a48a2f45e0 /drivers/mtd
parent1bce5f39c2ce0c79f0769f2e69d5e9caed28dfc2 (diff)
downloadbarebox-b5ef34499a3064680918d91ecdea74ddcf98716e.tar.gz
barebox-b5ef34499a3064680918d91ecdea74ddcf98716e.tar.xz
mtd: return EOPNOTSUPP when attempting to erase an MTD_NO_ERASE device
At least some MTD_NO_ERASE devices like MRAM do not specify a sensible erase block size; instead, erasesize is equal to the whole flash size. This leads to an EINVAL return from mtd_erase_align() whenever a partial erase is attempted. At least on the MRAM I tested, a full flash erase did not return an error, but it did not have any effect on the flash either. As erase seems to be entirely unsupported on this class of devices, and it is not necessary anyways, it's better to return early with EOPNOTSUPP. This fixes envfs_save() on a partitioned MRAM. Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/core.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 56e85b3d8f..d3cbe502fa 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -178,6 +178,9 @@ static int mtd_op_erase(struct cdev *cdev, loff_t count, loff_t offset)
loff_t addr;
int ret;
+ if (mtd->flags & MTD_NO_ERASE)
+ return -EOPNOTSUPP;
+
ret = mtd_erase_align(mtd, &count, &offset);
if (ret)
return ret;