* [PATCH] dm: Use vmalloc_array to simplify code
@ 2025-08-05 9:14 Qianfeng Rong
2025-08-05 12:08 ` Markus Elfring
2025-08-11 11:23 ` Mikulas Patocka
0 siblings, 2 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-05 9:14 UTC (permalink / raw)
To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, dm-devel,
linux-kernel
Cc: Qianfeng Rong
Remove array_size() calls and replace vmalloc() with
vmalloc_array() to simplify the code.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
drivers/md/dm-cache-policy-smq.c | 2 +-
drivers/md/dm-region-hash.c | 2 +-
drivers/md/dm-switch.c | 4 ++--
drivers/md/dm-thin.c | 4 ++--
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/md/dm-cache-policy-smq.c b/drivers/md/dm-cache-policy-smq.c
index 2ed894155cab..7e1e8cc0e33a 100644
--- a/drivers/md/dm-cache-policy-smq.c
+++ b/drivers/md/dm-cache-policy-smq.c
@@ -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;
diff --git a/drivers/md/dm-region-hash.c b/drivers/md/dm-region-hash.c
index a4550975c27d..e9b47b659976 100644
--- a/drivers/md/dm-region-hash.c
+++ b/drivers/md/dm-region-hash.c
@@ -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);
diff --git a/drivers/md/dm-switch.c b/drivers/md/dm-switch.c
index bb1a70b5a215..50a52ca50b34 100644
--- a/drivers/md/dm-switch.c
+++ b/drivers/md/dm-switch.c
@@ -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;
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 007bb93e5fca..c84149ba4e38 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -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);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] dm: Use vmalloc_array to simplify code
2025-08-05 9:14 [PATCH] dm: Use vmalloc_array to simplify code Qianfeng Rong
@ 2025-08-05 12:08 ` Markus Elfring
2025-08-05 12:43 ` Qianfeng Rong
2025-08-11 11:23 ` Mikulas Patocka
1 sibling, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2025-08-05 12:08 UTC (permalink / raw)
To: Qianfeng Rong, dm-devel
Cc: LKML, Alasdair Kergon, Mike Snitzer, Mikulas Patocka
> Remove array_size() calls and replace vmalloc() with
> vmalloc_array() to simplify the code.
You may occasionally put more than 52 characters into text lines
of such a change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n658
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dm: Use vmalloc_array to simplify code
2025-08-05 12:08 ` Markus Elfring
@ 2025-08-05 12:43 ` Qianfeng Rong
0 siblings, 0 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-08-05 12:43 UTC (permalink / raw)
To: Markus Elfring, dm-devel
Cc: LKML, Alasdair Kergon, Mike Snitzer, Mikulas Patocka
在 2025/8/5 20:08, Markus Elfring 写道:
> [You don't often get email from markus.elfring@web.de. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
>> Remove array_size() calls and replace vmalloc() with
>> vmalloc_array() to simplify the code.
> You may occasionally put more than 52 characters into text lines
> of such a change description.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.16#n658
Ok,Will do in the next version.
>
> Regards,
> Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dm: Use vmalloc_array to simplify code
2025-08-05 9:14 [PATCH] dm: Use vmalloc_array to simplify code Qianfeng Rong
2025-08-05 12:08 ` Markus Elfring
@ 2025-08-11 11:23 ` Mikulas Patocka
1 sibling, 0 replies; 4+ messages in thread
From: Mikulas Patocka @ 2025-08-11 11:23 UTC (permalink / raw)
To: Qianfeng Rong; +Cc: Alasdair Kergon, Mike Snitzer, dm-devel, linux-kernel
Applied.thanks.
Mikulas
On Tue, 5 Aug 2025, Qianfeng Rong wrote:
> Remove array_size() calls and replace vmalloc() with
> vmalloc_array() to simplify the code.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
> drivers/md/dm-cache-policy-smq.c | 2 +-
> drivers/md/dm-region-hash.c | 2 +-
> drivers/md/dm-switch.c | 4 ++--
> drivers/md/dm-thin.c | 4 ++--
> 4 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/md/dm-cache-policy-smq.c b/drivers/md/dm-cache-policy-smq.c
> index 2ed894155cab..7e1e8cc0e33a 100644
> --- a/drivers/md/dm-cache-policy-smq.c
> +++ b/drivers/md/dm-cache-policy-smq.c
> @@ -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;
>
> diff --git a/drivers/md/dm-region-hash.c b/drivers/md/dm-region-hash.c
> index a4550975c27d..e9b47b659976 100644
> --- a/drivers/md/dm-region-hash.c
> +++ b/drivers/md/dm-region-hash.c
> @@ -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);
> diff --git a/drivers/md/dm-switch.c b/drivers/md/dm-switch.c
> index bb1a70b5a215..50a52ca50b34 100644
> --- a/drivers/md/dm-switch.c
> +++ b/drivers/md/dm-switch.c
> @@ -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;
> diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
> index 007bb93e5fca..c84149ba4e38 100644
> --- a/drivers/md/dm-thin.c
> +++ b/drivers/md/dm-thin.c
> @@ -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);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-11 11:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-05 9:14 [PATCH] dm: Use vmalloc_array to simplify code Qianfeng Rong
2025-08-05 12:08 ` Markus Elfring
2025-08-05 12:43 ` Qianfeng Rong
2025-08-11 11:23 ` Mikulas Patocka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).