mirror of
https://github.com/torvalds/linux.git
synced 2026-10-07 22:37:45 -04:00
bitmap_zero() is called after bitmap_alloc() in perf code. But bitmap_alloc() internally uses calloc() which guarantees that allocated area is zeroed. So following bitmap_zero is unneeded. Drop it. This happened because of confusing name for bitmap allocator. It should has name bitmap_zalloc instead of bitmap_alloc. This series: https://lkml.org/lkml/2018/6/18/841 introduces a new API for bitmap allocations in kernel, and functions there are named correctly. Following patch propogates the API to tools, and fixes naming issue. Signed-off-by: Yury Norov <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andriy Shevchenko <[email protected]> Cc: David Ahern <[email protected]> Cc: David Carrillo-Cisneros <[email protected]> Cc: Dmitry Torokhov <[email protected]> Cc: Jin Yao <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kate Stewart <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Mike Snitzer <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Philippe Ombredanne <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/compiler.h>
|
|
#include <linux/bitmap.h>
|
|
#include "tests.h"
|
|
#include "cpumap.h"
|
|
#include "debug.h"
|
|
|
|
#define NBITS 100
|
|
|
|
static unsigned long *get_bitmap(const char *str, int nbits)
|
|
{
|
|
struct cpu_map *map = cpu_map__new(str);
|
|
unsigned long *bm = NULL;
|
|
int i;
|
|
|
|
bm = bitmap_alloc(nbits);
|
|
|
|
if (map && bm) {
|
|
for (i = 0; i < map->nr; i++)
|
|
set_bit(map->map[i], bm);
|
|
}
|
|
|
|
if (map)
|
|
cpu_map__put(map);
|
|
return bm;
|
|
}
|
|
|
|
static int test_bitmap(const char *str)
|
|
{
|
|
unsigned long *bm = get_bitmap(str, NBITS);
|
|
char buf[100];
|
|
int ret;
|
|
|
|
bitmap_scnprintf(bm, NBITS, buf, sizeof(buf));
|
|
pr_debug("bitmap: %s\n", buf);
|
|
|
|
ret = !strcmp(buf, str);
|
|
free(bm);
|
|
return ret;
|
|
}
|
|
|
|
int test__bitmap_print(struct test *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,5"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3,5,7,9,11,13,15,17,19,21-40"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("2-5"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1,3-6,8-10,24,35-37"));
|
|
TEST_ASSERT_VAL("failed to convert map", test_bitmap("1-10,12-20,22-30,32-40"));
|
|
return 0;
|
|
}
|