zram: return error-valued pointer from zcomp_create()
[firefly-linux-kernel-4.4.55.git] / drivers / block / zram / zcomp.c
index aad533a8bc55661471d6742b0aa68f10b00d9b41..5647d8fe1dc177c302154df9497abc86ed68c0fc 100644 (file)
@@ -9,12 +9,16 @@
 
 #include <linux/kernel.h>
 #include <linux/string.h>
+#include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/wait.h>
 #include <linux/sched.h>
 
 #include "zcomp.h"
 #include "zcomp_lzo.h"
+#ifdef CONFIG_ZRAM_LZ4_COMPRESS
+#include "zcomp_lz4.h"
+#endif
 
 /*
  * single zcomp_strm backend
@@ -41,6 +45,9 @@ struct zcomp_strm_multi {
 
 static struct zcomp_backend *backends[] = {
        &zcomp_lzo,
+#ifdef CONFIG_ZRAM_LZ4_COMPRESS
+       &zcomp_lz4,
+#endif
        NULL
 };
 
@@ -313,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)
 {
@@ -324,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)
@@ -337,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;
 }