summaryrefslogtreecommitdiff
path: root/drivers/mtd/mtdblock.c
diff options
context:
space:
mode:
authorXiaoming Ni <nixiaoming@huawei.com>2020-03-20 11:15:11 +0800
committerMiquel Raynal <miquel.raynal@bootlin.com>2020-03-24 23:02:30 +0100
commit4e4a9a828af29785fad12ecc11583769e1282024 (patch)
tree9b992e2e78e1ce48d37ff070d14caca0cc248a06 /drivers/mtd/mtdblock.c
parentf1ffdbfad00a3c424cadfd307b5bb9c466638532 (diff)
downloadlwn-4e4a9a828af29785fad12ecc11583769e1282024.tar.gz
lwn-4e4a9a828af29785fad12ecc11583769e1282024.zip
mtd: Fix issue where write_cached_data() fails but write() still returns success
The following sequence is problematic: mtdblock_flush() -->write_cached_data() --->erase_write() mtdblock: erase of region [0x40000, 0x20000] on "xxx" failed Problem is: mtdblock_flush() always returns 0. Indeed, even if write_cached_data() fails and data is not written to the device, syscall_write() still returns success. Avoid this situation by actually returning the error coming out of write_cached_data(). Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/1584674111-101462-1-git-send-email-nixiaoming@huawei.com
Diffstat (limited to 'drivers/mtd/mtdblock.c')
-rw-r--r--drivers/mtd/mtdblock.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index c06b5322d470..078e0f67377d 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -294,12 +294,13 @@ static void mtdblock_release(struct mtd_blktrans_dev *mbd)
static int mtdblock_flush(struct mtd_blktrans_dev *dev)
{
struct mtdblk_dev *mtdblk = container_of(dev, struct mtdblk_dev, mbd);
+ int ret;
mutex_lock(&mtdblk->cache_mutex);
- write_cached_data(mtdblk);
+ ret = write_cached_data(mtdblk);
mutex_unlock(&mtdblk->cache_mutex);
mtd_sync(dev->mtd);
- return 0;
+ return ret;
}
static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)