Skip to content

Commit

Permalink
mtd: Fix issue where write_cached_data() fails but write() still retu…
Browse files Browse the repository at this point in the history
…rns 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
  • Loading branch information
Xiaoming Ni authored and Miquel Raynal committed Mar 24, 2020
1 parent f1ffdbf commit 4e4a9a8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/mtd/mtdblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4e4a9a8

Please sign in to comment.