Browse Source

staging: zram: fix data corruption issue

In zram_read() and zram_write() we were not incrementing the
index number and thus were reading/writing values from/to
incorrect sectors on zram disk, resulting in data corruption.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Nitin Gupta 14 năm trước cách đây
mục cha
commit
5414e557fc
1 tập tin đã thay đổi với 4 bổ sung0 xóa
  1. 4 0
      drivers/staging/zram/zram_drv.c

+ 4 - 0
drivers/staging/zram/zram_drv.c

@@ -227,6 +227,7 @@ static int zram_read(struct zram *zram, struct bio *bio)
 
 
 		if (zram_test_flag(zram, index, ZRAM_ZERO)) {
 		if (zram_test_flag(zram, index, ZRAM_ZERO)) {
 			handle_zero_page(page);
 			handle_zero_page(page);
+			index++;
 			continue;
 			continue;
 		}
 		}
 
 
@@ -235,12 +236,14 @@ static int zram_read(struct zram *zram, struct bio *bio)
 			pr_debug("Read before write: sector=%lu, size=%u",
 			pr_debug("Read before write: sector=%lu, size=%u",
 				(ulong)(bio->bi_sector), bio->bi_size);
 				(ulong)(bio->bi_sector), bio->bi_size);
 			/* Do nothing */
 			/* Do nothing */
+			index++;
 			continue;
 			continue;
 		}
 		}
 
 
 		/* Page is stored uncompressed since it's incompressible */
 		/* Page is stored uncompressed since it's incompressible */
 		if (unlikely(zram_test_flag(zram, index, ZRAM_UNCOMPRESSED))) {
 		if (unlikely(zram_test_flag(zram, index, ZRAM_UNCOMPRESSED))) {
 			handle_uncompressed_page(zram, page, index);
 			handle_uncompressed_page(zram, page, index);
+			index++;
 			continue;
 			continue;
 		}
 		}
 
 
@@ -320,6 +323,7 @@ static int zram_write(struct zram *zram, struct bio *bio)
 			mutex_unlock(&zram->lock);
 			mutex_unlock(&zram->lock);
 			zram_stat_inc(&zram->stats.pages_zero);
 			zram_stat_inc(&zram->stats.pages_zero);
 			zram_set_flag(zram, index, ZRAM_ZERO);
 			zram_set_flag(zram, index, ZRAM_ZERO);
+			index++;
 			continue;
 			continue;
 		}
 		}