]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/block/zram/zram_drv.c
Merge tag 'iio-fixes-for-4.10a' of git://git.kernel.org/pub/scm/linux/kernel/git...
[karo-tx-linux.git] / drivers / block / zram / zram_drv.c
index 04365b17ee67fe668f4bfc1f5683846af999009a..15f58ab44d0b429fc7b5ebf0ba7e1cdfcc6c914d 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/err.h>
 #include <linux/idr.h>
 #include <linux/sysfs.h>
+#include <linux/cpuhotplug.h>
 
 #include "zram_drv.h"
 
@@ -1403,7 +1404,8 @@ static ssize_t hot_remove_store(struct class *class,
        zram = idr_find(&zram_index_idr, dev_id);
        if (zram) {
                ret = zram_remove(zram);
-               idr_remove(&zram_index_idr, dev_id);
+               if (!ret)
+                       idr_remove(&zram_index_idr, dev_id);
        } else {
                ret = -ENODEV;
        }
@@ -1412,8 +1414,14 @@ static ssize_t hot_remove_store(struct class *class,
        return ret ? ret : count;
 }
 
+/*
+ * NOTE: hot_add attribute is not the usual read-only sysfs attribute. In a
+ * sense that reading from this file does alter the state of your system -- it
+ * creates a new un-initialized zram device and returns back this device's
+ * device_id (or an error code if it fails to create a new device).
+ */
 static struct class_attribute zram_control_class_attrs[] = {
-       __ATTR_RO(hot_add),
+       __ATTR(hot_add, 0400, hot_add_show, NULL),
        __ATTR_WO(hot_remove),
        __ATTR_NULL,
 };
@@ -1436,15 +1444,22 @@ static void destroy_devices(void)
        idr_for_each(&zram_index_idr, &zram_remove_cb, NULL);
        idr_destroy(&zram_index_idr);
        unregister_blkdev(zram_major, "zram");
+       cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE);
 }
 
 static int __init zram_init(void)
 {
        int ret;
 
+       ret = cpuhp_setup_state_multi(CPUHP_ZCOMP_PREPARE, "block/zram:prepare",
+                                     zcomp_cpu_up_prepare, zcomp_cpu_dead);
+       if (ret < 0)
+               return ret;
+
        ret = class_register(&zram_control_class);
        if (ret) {
                pr_err("Unable to register zram-control class\n");
+               cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE);
                return ret;
        }
 
@@ -1452,6 +1467,7 @@ static int __init zram_init(void)
        if (zram_major <= 0) {
                pr_err("Unable to get major number\n");
                class_unregister(&zram_control_class);
+               cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE);
                return -EBUSY;
        }