Skip to content

Commit 57e0076

Browse files
minchanktorvalds
authored andcommitted
zram: fix return value on writeback_store
writeback_store's return value is overwritten by submit_bio_wait's return value. Thus, writeback_store will return zero since there was no IO error. In the end, write syscall from userspace will see the zero as return value, which could make the process stall to keep trying the write until it will succeed. Link: https://lkml.kernel.org/r/[email protected] Fixes: 3b82a05("drivers/block/zram/zram_drv.c: fix error return codes not being returned in writeback_store") Signed-off-by: Minchan Kim <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Cc: Colin Ian King <[email protected]> Cc: John Dias <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e1baddf commit 57e0076

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ static ssize_t writeback_store(struct device *dev,
627627
struct bio_vec bio_vec;
628628
struct page *page;
629629
ssize_t ret = len;
630-
int mode;
630+
int mode, err;
631631
unsigned long blk_idx = 0;
632632

633633
if (sysfs_streq(buf, "idle"))
@@ -728,12 +728,17 @@ static ssize_t writeback_store(struct device *dev,
728728
* XXX: A single page IO would be inefficient for write
729729
* but it would be not bad as starter.
730730
*/
731-
ret = submit_bio_wait(&bio);
732-
if (ret) {
731+
err = submit_bio_wait(&bio);
732+
if (err) {
733733
zram_slot_lock(zram, index);
734734
zram_clear_flag(zram, index, ZRAM_UNDER_WB);
735735
zram_clear_flag(zram, index, ZRAM_IDLE);
736736
zram_slot_unlock(zram, index);
737+
/*
738+
* Return last IO error unless every IO were
739+
* not suceeded.
740+
*/
741+
ret = err;
737742
continue;
738743
}
739744

0 commit comments

Comments
 (0)