aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/zram/zcomp.c
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>2014-04-07 18:38:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-07 19:36:02 -0400
commitfcfa8d95cacf5cbbe6dee6b8d229fe86142266e0 (patch)
treeac63d65c9d0c9d8831eec5f07b4c491b18559d0c /drivers/block/zram/zcomp.c
parentd61f98c70e8b0d324e8e83be2ed546d6295e63f3 (diff)
zram: return error-valued pointer from zcomp_create()
Instead of returning just NULL, return ERR_PTR from zcomp_create() if compressing backend creation has failed. ERR_PTR(-EINVAL) for unsupported compression algorithm request, ERR_PTR(-ENOMEM) for allocation (zcomp or compression stream) error. Perform IS_ERR() check of returned from zcomp_create() value in disksize_store() and set return code to PTR_ERR(). Change suggested by Jerome Marchand. [akpm@linux-foundation.org: clean up error recovery flow] Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Reported-by: Jerome Marchand <jmarchan@redhat.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Nitin Gupta <ngupta@vflare.org> Cc: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/zram/zcomp.c')
-rw-r--r--drivers/block/zram/zcomp.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index d5919031ca8b..5647d8fe1dc1 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -9,6 +9,7 @@
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/string.h> 11#include <linux/string.h>
12#include <linux/err.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13#include <linux/wait.h> 14#include <linux/wait.h>
14#include <linux/sched.h> 15#include <linux/sched.h>
@@ -319,9 +320,10 @@ void zcomp_destroy(struct zcomp *comp)
319 320
320/* 321/*
321 * search available compressors for requested algorithm. 322 * search available compressors for requested algorithm.
322 * allocate new zcomp and initialize it. return NULL 323 * allocate new zcomp and initialize it. return compressing
323 * if requested algorithm is not supported or in case 324 * backend pointer or ERR_PTR if things went bad. ERR_PTR(-EINVAL)
324 * of init error 325 * if requested algorithm is not supported, ERR_PTR(-ENOMEM) in
326 * case of allocation error.
325 */ 327 */
326struct zcomp *zcomp_create(const char *compress, int max_strm) 328struct zcomp *zcomp_create(const char *compress, int max_strm)
327{ 329{
@@ -330,11 +332,11 @@ struct zcomp *zcomp_create(const char *compress, int max_strm)
330 332
331 backend = find_backend(compress); 333 backend = find_backend(compress);
332 if (!backend) 334 if (!backend)
333 return NULL; 335 return ERR_PTR(-EINVAL);
334 336
335 comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL); 337 comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL);
336 if (!comp) 338 if (!comp)
337 return NULL; 339 return ERR_PTR(-ENOMEM);
338 340
339 comp->backend = backend; 341 comp->backend = backend;
340 if (max_strm > 1) 342 if (max_strm > 1)
@@ -343,7 +345,7 @@ struct zcomp *zcomp_create(const char *compress, int max_strm)
343 zcomp_strm_single_create(comp); 345 zcomp_strm_single_create(comp);
344 if (!comp->stream) { 346 if (!comp->stream) {
345 kfree(comp); 347 kfree(comp);
346 return NULL; 348 return ERR_PTR(-ENOMEM);
347 } 349 }
348 return comp; 350 return comp;
349} 351}