Messages in this thread Patch in this message | | | From | Sergey Senozhatsky <> | Subject | [PATCH 6/8] zram: allow automatic new zram device_id assignment | Date | Thu, 26 Feb 2015 23:10:41 +0900 |
| |
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.senozhatsky@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
| |