zram: introduce comp algorithm fallback functionality
[cascardo/linux.git] / drivers / block / zram / zram_drv.c
index 9fa15bb..c93aeb8 100644 (file)
@@ -365,6 +365,9 @@ static ssize_t comp_algorithm_store(struct device *dev,
        struct zram *zram = dev_to_zram(dev);
        size_t sz;
 
+       if (!zcomp_available_algorithm(buf))
+               return -EINVAL;
+
        down_write(&zram->init_lock);
        if (init_done(zram)) {
                up_write(&zram->init_lock);
@@ -378,9 +381,6 @@ static ssize_t comp_algorithm_store(struct device *dev,
        if (sz > 0 && zram->compressor[sz - 1] == '\n')
                zram->compressor[sz - 1] = 0x00;
 
-       if (!zcomp_available_algorithm(zram->compressor))
-               len = -EINVAL;
-
        up_write(&zram->init_lock);
        return len;
 }