zram: fix pool name truncation
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Fri, 14 Aug 2015 22:35:19 +0000 (15:35 -0700)
committerDanny Wood <danwood76@gmail.com>
Tue, 14 Sep 2021 19:02:56 +0000 (20:02 +0100)
commitce00e7b8cbba060a230a8fcb9d7bd8b6d8d3162c
treef8243a46abda89c0ea406f8b062bf33ceb730c16
parent6a57d62a52bdc7c4fa95b1a1f398bfd0311e2a65
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>
Change-Id: I4c42cc1134b09f93a824d15e589e66fee28af539
drivers/block/zram/zram_drv.c