zram tweaks

zram: remove down_write/up_write(&zram->lock)

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
zram: avoid access beyond the zram device

Function valid_io_request() should verify the entire request doesn't
exceed the zram device, otherwise it will cause invalid memory access.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
zram: destroy all devices on error recovery path in zram_init()

On error recovery path of zram_init(), it leaks the zram device object
causing the failure.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
zram: use zram->lock to protect zram_free_page() in swap free notify path

Date	Mon, 3 Jun 2013 23:42:15 +0800

zram_free_page() is protected by down_write(&zram->lock) when called by
zram_bvec_write(), but there's no such protection when called by
zram_slot_free_notify(), which may cause wrong states to zram object.

So enhance zram_slot_free_notify() to acquire writer lock on zram->lock
before calling zram_free_page().

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
zram: avoid invalid memory access in zram_exit()

Memory for zram->disk object may have already been freed after returning
from destroy_device(zram), then it's unsafe for zram_reset_device(zram)
to access zram->disk again.

Fix it by holding an extra reference to zram->disk before calling
destroy_device(zram).

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
zram: simplify and optimize zram_to_dev()

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>