blk-mq: make sure that line break can be printed
authorMing Lei <ming.lei@redhat.com>
Mon, 4 Nov 2019 08:26:53 +0000 (16:26 +0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 4 Nov 2019 14:14:10 +0000 (07:14 -0700)
8962842ca5ab ("blk-mq: avoid sysfs buffer overflow with too many CPU cores")
avoids sysfs buffer overflow, and reserves one character for line break.
However, the last snprintf() doesn't get correct 'size' parameter passed
in, so fixed it.

Fixes: 8962842ca5ab ("blk-mq: avoid sysfs buffer overflow with too many CPU cores")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq-sysfs.c

index 4caa56d1bc857b2a3f1c2087dcbefafd2a3a0172..062229395a507caa133fc1b36a57f6cae5af810a 100644 (file)
@@ -175,7 +175,7 @@ static ssize_t blk_mq_hw_sysfs_cpus_show(struct blk_mq_hw_ctx *hctx, char *page)
                pos += ret;
        }
 
-       ret = snprintf(pos + page, size - pos, "\n");
+       ret = snprintf(pos + page, size + 1 - pos, "\n");
        return pos + ret;
 }