blkparse: fix incorrectly sized memset in check_cpu_map
authorJeff Mahoney <jeffm@suse.com>
Thu, 21 Oct 2021 14:16:20 +0000 (10:16 -0400)
committerJens Axboe <axboe@kernel.dk>
Thu, 21 Oct 2021 14:45:17 +0000 (08:45 -0600)
The memset call in check_cpu_map always clears sizeof(unsigned long *)
regardless of what size was allocated.  Use calloc instead to allocate
the map so it's zeroed properly regardless of the size requested.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
blkparse.c

index 498857ccbf9a067e890ba43035e2b90a40a709d1..9d2029ace868359f28eff0aa60c7de9cd6713d7d 100644 (file)
@@ -2236,8 +2236,7 @@ static int check_cpu_map(struct per_dev_info *pdi)
        /*
         * create a map of the cpus we have traces for
         */
-       cpu_map = malloc(pdi->cpu_map_max / sizeof(long));
-       memset(cpu_map, 0, sizeof(*cpu_map));
+       cpu_map = calloc(1, pdi->cpu_map_max / sizeof(long));
        n = rb_first(&rb_sort_root);
        while (n) {
                __t = rb_entry(n, struct trace, rb_node);