#include <linux/kernel.h>
#include <linux/string.h>
+#include <linux/err.h>
#include <linux/slab.h>
#include <linux/wait.h>
#include <linux/sched.h>
/*
* 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)
{
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)
zcomp_strm_single_create(comp);
if (!comp->stream) {
kfree(comp);
- return NULL;
+ return ERR_PTR(-ENOMEM);
}
return comp;
}
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
+#include <linux/err.h>
#include "zram_drv.h"
struct zcomp *comp;
struct zram_meta *meta;
struct zram *zram = dev_to_zram(dev);
- int err = -EINVAL;
+ int err;
disksize = memparse(buf, NULL);
if (!disksize)
return -ENOMEM;
comp = zcomp_create(zram->compressor, zram->max_comp_streams);
- if (!comp) {
+ if (IS_ERR(comp)) {
pr_info("Cannot initialise %s compressing backend\n",
zram->compressor);
- goto out_cleanup;
+ err = PTR_ERR(comp);
+ goto out_free_meta;
}
down_write(&zram->init_lock);
if (init_done(zram)) {
- up_write(&zram->init_lock);
pr_info("Cannot change disksize for initialized device\n");
err = -EBUSY;
- goto out_cleanup;
+ goto out_destroy_comp;
}
zram->meta = meta;
zram->disksize = disksize;
set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
up_write(&zram->init_lock);
-
return len;
-out_cleanup:
- if (comp)
- zcomp_destroy(comp);
+out_destroy_comp:
+ up_write(&zram->init_lock);
+ zcomp_destroy(comp);
+out_free_meta:
zram_meta_free(meta);
return err;
}