]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dm: use vmalloc_array() to simplify code
authorQianfeng Rong <rongqianfeng@vivo.com>
Wed, 6 Aug 2025 12:27:04 +0000 (20:27 +0800)
committerMikulas Patocka <mpatocka@redhat.com>
Tue, 19 Aug 2025 09:12:50 +0000 (11:12 +0200)
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>
drivers/md/dm-cache-policy-smq.c
drivers/md/dm-region-hash.c
drivers/md/dm-switch.c
drivers/md/dm-thin.c

index 2ed894155cabbe944fdcbcdb25c456304baf14ed..7e1e8cc0e33a3c37661fec4a941181575acfc3ec 100644 (file)
@@ -590,7 +590,7 @@ static int h_init(struct smq_hash_table *ht, struct entry_space *es, unsigned in
        nr_buckets = roundup_pow_of_two(max(nr_entries / 4u, 16u));
        ht->hash_bits = __ffs(nr_buckets);
 
-       ht->buckets = vmalloc(array_size(nr_buckets, sizeof(*ht->buckets)));
+       ht->buckets = vmalloc_array(nr_buckets, sizeof(*ht->buckets));
        if (!ht->buckets)
                return -ENOMEM;
 
index a4550975c27d0fc8adc5f12641756eb8f8fc0968..e9b47b659976af7b1357de95b3eee854856633df 100644 (file)
@@ -206,7 +206,7 @@ struct dm_region_hash *dm_region_hash_create(
        rh->shift = RH_HASH_SHIFT;
        rh->prime = RH_HASH_MULT;
 
-       rh->buckets = vmalloc(array_size(nr_buckets, sizeof(*rh->buckets)));
+       rh->buckets = vmalloc_array(nr_buckets, sizeof(*rh->buckets));
        if (!rh->buckets) {
                DMERR("unable to allocate region hash bucket memory");
                kfree(rh);
index bb1a70b5a2152b054004008ea6ac2744101d3664..50a52ca50b34c4bb643d6e888e28cce09b3bb014 100644 (file)
@@ -114,8 +114,8 @@ static int alloc_region_table(struct dm_target *ti, unsigned int nr_paths)
                return -EINVAL;
        }
 
-       sctx->region_table = vmalloc(array_size(nr_slots,
-                                               sizeof(region_table_slot_t)));
+       sctx->region_table = vmalloc_array(nr_slots,
+                                          sizeof(region_table_slot_t));
        if (!sctx->region_table) {
                ti->error = "Cannot allocate region table";
                return -ENOMEM;
index 007bb93e5fca681cc3b939fd6ad57e65a4f0ac17..c84149ba4e38e92135fc325b6781d1313f4aaaf8 100644 (file)
@@ -3031,8 +3031,8 @@ static struct pool *pool_create(struct mapped_device *pool_md,
        }
 
        pool->cell_sort_array =
-               vmalloc(array_size(CELL_SORT_ARRAY_SIZE,
-                                  sizeof(*pool->cell_sort_array)));
+               vmalloc_array(CELL_SORT_ARRAY_SIZE,
+                             sizeof(*pool->cell_sort_array));
        if (!pool->cell_sort_array) {
                *error = "Error allocating cell sort array";
                err_p = ERR_PTR(-ENOMEM);