• Sergey Senozhatsky's avatar
    zram: fix pool name truncation · 4ce321f5
    Sergey Senozhatsky authored
    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: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
    Cc: Minchan Kim <minchan@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    4ce321f5
zram_drv.c 33.9 KB