Skip to content

Commit 4e4a9a8

Browse files
nixiaomingmiquelraynal
authored andcommitted
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 <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent f1ffdbf commit 4e4a9a8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/mtd/mtdblock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,13 @@ static void mtdblock_release(struct mtd_blktrans_dev *mbd)
294294
static int mtdblock_flush(struct mtd_blktrans_dev *dev)
295295
{
296296
struct mtdblk_dev *mtdblk = container_of(dev, struct mtdblk_dev, mbd);
297+
int ret;
297298

298299
mutex_lock(&mtdblk->cache_mutex);
299-
write_cached_data(mtdblk);
300+
ret = write_cached_data(mtdblk);
300301
mutex_unlock(&mtdblk->cache_mutex);
301302
mtd_sync(dev->mtd);
302-
return 0;
303+
return ret;
303304
}
304305

305306
static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)

0 commit comments

Comments
 (0)