Commit 5414e557fca545614ceedc3d3496f747457e2e3b

Authored by Nitin Gupta
Committed by Greg Kroah-Hartman
1 parent 0742cecbd4

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>

Showing 1 changed file with 4 additions and 0 deletions Side-by-side Diff

drivers/staging/zram/zram_drv.c
... ... @@ -227,6 +227,7 @@
227 227  
228 228 if (zram_test_flag(zram, index, ZRAM_ZERO)) {
229 229 handle_zero_page(page);
  230 + index++;
230 231 continue;
231 232 }
232 233  
233 234  
... ... @@ -235,12 +236,14 @@
235 236 pr_debug("Read before write: sector=%lu, size=%u",
236 237 (ulong)(bio->bi_sector), bio->bi_size);
237 238 /* Do nothing */
  239 + index++;
238 240 continue;
239 241 }
240 242  
241 243 /* Page is stored uncompressed since it's incompressible */
242 244 if (unlikely(zram_test_flag(zram, index, ZRAM_UNCOMPRESSED))) {
243 245 handle_uncompressed_page(zram, page, index);
  246 + index++;
244 247 continue;
245 248 }
246 249  
... ... @@ -320,6 +323,7 @@
320 323 mutex_unlock(&zram->lock);
321 324 zram_stat_inc(&zram->stats.pages_zero);
322 325 zram_set_flag(zram, index, ZRAM_ZERO);
  326 + index++;
323 327 continue;
324 328 }
325 329