zram: return error-valued pointer from zcomp_create()
[firefly-linux-kernel-4.4.55.git] / drivers / block / zram / zcomp.c
index d5919031ca8ba5498cf473671c65033a0d0041c6..5647d8fe1dc177c302154df9497abc86ed68c0fc 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <linux/kernel.h>
 #include <linux/string.h>
+#include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/wait.h>
 #include <linux/sched.h>
@@ -319,9 +320,10 @@ void zcomp_destroy(struct zcomp *comp)
 
 /*
  * search available compressors for requested algorithm.
- * allocate new zcomp and initialize it. return NULL
- * if requested algorithm is not supported or in case
- * of init error
+ * allocate new zcomp and initialize it. return compressing
+ * backend pointer or ERR_PTR if things went bad. ERR_PTR(-EINVAL)
+ * if requested algorithm is not supported, ERR_PTR(-ENOMEM) in
+ * case of allocation error.
  */
 struct zcomp *zcomp_create(const char *compress, int max_strm)
 {
@@ -330,11 +332,11 @@ struct zcomp *zcomp_create(const char *compress, int max_strm)
 
        backend = find_backend(compress);
        if (!backend)
-               return NULL;
+               return ERR_PTR(-EINVAL);
 
        comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL);
        if (!comp)
-               return NULL;
+               return ERR_PTR(-ENOMEM);
 
        comp->backend = backend;
        if (max_strm > 1)
@@ -343,7 +345,7 @@ struct zcomp *zcomp_create(const char *compress, int max_strm)
                zcomp_strm_single_create(comp);
        if (!comp->stream) {
                kfree(comp);
-               return NULL;
+               return ERR_PTR(-ENOMEM);
        }
        return comp;
 }