diff mbox series

mtd:Fix issue where write_cached_data() fails but write() still returns success

Message ID 1584674111-101462-1-git-send-email-nixiaoming@huawei.com
State Accepted
Delegated to: Miquel Raynal
Headers show
Series mtd:Fix issue where write_cached_data() fails but write() still returns success | expand

Commit Message

Xiaoming Ni March 20, 2020, 3:15 a.m. UTC
mtdblock_flush()
	-->write_cached_data()
		--->erase_write()
		     mtdblock: erase of region [0x40000, 0x20000] on "xxx" failed

Because mtdblock_flush() always returns 0,
even if write_cached_data() fails and data is not written to the device,
syscall_write() still returns success

Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
 drivers/mtd/mtdblock.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Miquel Raynal March 24, 2020, 10:05 p.m. UTC | #1
On Fri, 2020-03-20 at 03:15:11 UTC, Xiaoming Ni wrote:
> mtdblock_flush()
> 	-->write_cached_data()
> 		--->erase_write()
> 		     mtdblock: erase of region [0x40000, 0x20000] on "xxx" failed
> 
> Because mtdblock_flush() always returns 0,
> even if write_cached_data() fails and data is not written to the device,
> syscall_write() still returns success
> 
> Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel
Miquel Raynal March 24, 2020, 10:06 p.m. UTC | #2
Hi Xiaoming,

Xiaoming Ni <nixiaoming@huawei.com> wrote on Fri, 20 Mar 2020 11:15:11
+0800:

> mtdblock_flush()
> 	-->write_cached_data()
> 		--->erase_write()  
> 		     mtdblock: erase of region [0x40000, 0x20000] on "xxx" failed
> 
> Because mtdblock_flush() always returns 0,
> even if write_cached_data() fails and data is not written to the device,
> syscall_write() still returns success

I reworded a bit the commit log and also added a ' ' after 'mtd:' in
the title when applying.

Thanks,
Miquèl
Xiaoming Ni March 25, 2020, 7:53 a.m. UTC | #3
On 2020/3/25 6:06, Miquel Raynal wrote:
> Hi Xiaoming,
> 
> Xiaoming Ni <nixiaoming@huawei.com> wrote on Fri, 20 Mar 2020 11:15:11
> +0800:
> 
>> mtdblock_flush()
>> 	-->write_cached_data()
>> 		--->erase_write()
>> 		     mtdblock: erase of region [0x40000, 0x20000] on "xxx" failed
>>
>> Because mtdblock_flush() always returns 0,
>> even if write_cached_data() fails and data is not written to the device,
>> syscall_write() still returns success
> 
> I reworded a bit the commit log and also added a ' ' after 'mtd:' in
> the title when applying.
> 
> Thanks,
> Miquèl

Your revised commit log is more accurate and clearer, thanks for your 
correction
Thanks.
Xiaoming Ni
diff mbox series

Patch

diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index c06b532..078e0f6 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)