If no particular device_id was requested (passed -1 to zram_add()) during new 
zram
device creation, generate one automatically and return it back. So, 
schematically,
device creation can be done as:

        dev_id = ioctl ZRAM_CTL_ADD -1
        # dev_id == 1 or error code
        init device zram1

        dev_id = ioctl ZRAM_CTL_ADD -1
        # dev_id == 2 or error code
        init device zram2
        ...

Signed-off-by: Sergey Senozhatsky <sergey.senozhat...@gmail.com>
---
 drivers/block/zram/zram_drv.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 0154c2d4..5804dda 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1090,8 +1090,15 @@ static int zram_add(int device_id)
        if (!zram)
                return ret;
 
-       ret = idr_alloc(&zram_index_idr, zram, device_id,
+       if (device_id < 0) {
+               /* generate new device_id */
+               ret = idr_alloc(&zram_index_idr, zram, 0, 0, GFP_KERNEL);
+               device_id = ret;
+       } else {
+               /* use specific device_id */
+               ret = idr_alloc(&zram_index_idr, zram, device_id,
                        device_id + 1, GFP_KERNEL);
+       }
        if (ret < 0)
                goto out_free_dev;
 
-- 
2.3.1.167.g7f4ba4b

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to