aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/zram/zram_drv.c
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>2015-08-14 18:35:19 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-08-14 18:56:32 -0400
commit4ce321f574a97f3453bca5a4117610b43dabd3ee (patch)
tree0d615f7abf1f080f541a031015f24e7acfbee777 /drivers/block/zram/zram_drv.c
parentf9126ab9241f66562debf69c2c9d8fee32ddcc53 (diff)
zram: fix pool name truncation
zram_meta_alloc() constructs a pool name for zs_create_pool() call as snprintf(pool_name, sizeof(pool_name), "zram%d", device_id); However, it defines pool name buffer to be only 8 bytes long (minus trailing zero), which means that we can have only 1000 pool names: zram0 -- zram999. With CONFIG_ZSMALLOC_STAT enabled an attempt to create a device zram1000 can fail if device zram100 already exists, because snprintf() will truncate new pool name to zram100 and pass it debugfs_create_dir(), causing: debugfs dir <zram100> creation failed zram: Error creating memory pool ... and so on. Fix it by passing zram->disk->disk_name to zram_meta_alloc() instead of divice_id. We construct zram%d name earlier and keep it as a ->disk_name, no need to snprintf() it again. Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Minchan Kim <minchan@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/zram/zram_drv.c')
-rw-r--r--drivers/block/zram/zram_drv.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index fb655e8d1e3b..763301c7828c 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -496,10 +496,9 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize)
496 kfree(meta); 496 kfree(meta);
497} 497}
498 498
499static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize) 499static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
500{ 500{
501 size_t num_pages; 501 size_t num_pages;
502 char pool_name[8];
503 struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL); 502 struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
504 503
505 if (!meta) 504 if (!meta)
@@ -512,7 +511,6 @@ static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
512 goto out_error; 511 goto out_error;
513 } 512 }
514 513
515 snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);
516 meta->mem_pool = zs_create_pool(pool_name, GFP_NOIO | __GFP_HIGHMEM); 514 meta->mem_pool = zs_create_pool(pool_name, GFP_NOIO | __GFP_HIGHMEM);
517 if (!meta->mem_pool) { 515 if (!meta->mem_pool) {
518 pr_err("Error creating memory pool\n"); 516 pr_err("Error creating memory pool\n");
@@ -1031,7 +1029,7 @@ static ssize_t disksize_store(struct device *dev,
1031 return -EINVAL; 1029 return -EINVAL;
1032 1030
1033 disksize = PAGE_ALIGN(disksize); 1031 disksize = PAGE_ALIGN(disksize);
1034 meta = zram_meta_alloc(zram->disk->first_minor, disksize); 1032 meta = zram_meta_alloc(zram->disk->disk_name, disksize);
1035 if (!meta) 1033 if (!meta)
1036 return -ENOMEM; 1034 return -ENOMEM;
1037 1035