zram: avoid NULL pointer access in concurrent situation
authorWeijie Yang <weijie.yang@samsung.com>
Wed, 29 Oct 2014 21:50:57 +0000 (14:50 -0700)
committerAlex Shi <alex.shi@linaro.org>
Mon, 11 May 2015 13:31:01 +0000 (21:31 +0800)
commitea56241654a2c7ef9a1122a7ad5c751527ed9b17
treebc3b0742b4132b355eedc0b4d76980f83e40c230
parentb900447eb093095e133ffacb6a7de29660e09eae
zram: avoid NULL pointer access in concurrent situation

There is a rare NULL pointer bug in mem_used_total_show() and
mem_used_max_store() in concurrent situation, like this:

zram is not initialized, process A is a mem_used_total reader which runs
periodically, while process B try to init zram.

process A  process B
  access meta, get a NULL value
init zram, done
  init_done() is true
  access meta->mem_pool, get a NULL pointer BUG

This patch fixes this issue.

Signed-off-by: Weijie Yang <weijie.yang@samsung.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 5a99e95b8d1cd47f6feddcdca6c71d22060df8a2)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
drivers/block/zram/zram_drv.c