[PATCH 3.11 041/144] zram: avoid null access when fail to alloc meta

Luis Henriques luis.henriques at canonical.com
Tue Apr 1 11:14:05 UTC 2014


3.11.10.7 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: Minchan Kim <minchan at kernel.org>

commit db5d711e2db776f18219b033e5dc4fb7e4264dd7 upstream.

zram_meta_alloc could fail so caller should check it.  Otherwise, your
system will hang.

Signed-off-by: Minchan Kim <minchan at kernel.org>
Acked-by: Jerome Marchand <jmarchan at redhat.com>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
[ luis: backported to 3.11:
  - zram is a staging driver in 3.11 kernel ]
Signed-off-by: Luis Henriques <luis.henriques at canonical.com>
---
 drivers/staging/zram/zram_drv.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index fc540ea..9f1cb4e0 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -620,6 +620,8 @@ static ssize_t disksize_store(struct device *dev,
 
 	disksize = PAGE_ALIGN(disksize);
 	meta = zram_meta_alloc(disksize);
+	if (!meta)
+		return -ENOMEM;
 	down_write(&zram->init_lock);
 	if (zram->init_done) {
 		up_write(&zram->init_lock);
-- 
1.9.1





More information about the kernel-team mailing list