Skip to content

Commit c379717

Browse files
qianfengrongMikulas Patocka
authored andcommitted
dm: use vmalloc_array() to simplify code
Remove array_size() calls and replace vmalloc() with vmalloc_array() to simplify the code. Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent a319147 commit c379717

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

drivers/md/dm-cache-policy-smq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ static int h_init(struct smq_hash_table *ht, struct entry_space *es, unsigned in
590590
nr_buckets = roundup_pow_of_two(max(nr_entries / 4u, 16u));
591591
ht->hash_bits = __ffs(nr_buckets);
592592

593-
ht->buckets = vmalloc(array_size(nr_buckets, sizeof(*ht->buckets)));
593+
ht->buckets = vmalloc_array(nr_buckets, sizeof(*ht->buckets));
594594
if (!ht->buckets)
595595
return -ENOMEM;
596596

drivers/md/dm-region-hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ struct dm_region_hash *dm_region_hash_create(
206206
rh->shift = RH_HASH_SHIFT;
207207
rh->prime = RH_HASH_MULT;
208208

209-
rh->buckets = vmalloc(array_size(nr_buckets, sizeof(*rh->buckets)));
209+
rh->buckets = vmalloc_array(nr_buckets, sizeof(*rh->buckets));
210210
if (!rh->buckets) {
211211
DMERR("unable to allocate region hash bucket memory");
212212
kfree(rh);

drivers/md/dm-switch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ static int alloc_region_table(struct dm_target *ti, unsigned int nr_paths)
114114
return -EINVAL;
115115
}
116116

117-
sctx->region_table = vmalloc(array_size(nr_slots,
118-
sizeof(region_table_slot_t)));
117+
sctx->region_table = vmalloc_array(nr_slots,
118+
sizeof(region_table_slot_t));
119119
if (!sctx->region_table) {
120120
ti->error = "Cannot allocate region table";
121121
return -ENOMEM;

drivers/md/dm-thin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,8 +3031,8 @@ static struct pool *pool_create(struct mapped_device *pool_md,
30313031
}
30323032

30333033
pool->cell_sort_array =
3034-
vmalloc(array_size(CELL_SORT_ARRAY_SIZE,
3035-
sizeof(*pool->cell_sort_array)));
3034+
vmalloc_array(CELL_SORT_ARRAY_SIZE,
3035+
sizeof(*pool->cell_sort_array));
30363036
if (!pool->cell_sort_array) {
30373037
*error = "Error allocating cell sort array";
30383038
err_p = ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)