* [PATCH 0/3] ALSA: use vmalloc_array() to simplify code
@ 2025-08-24 13:55 Qianfeng Rong
2025-08-24 13:55 ` [PATCH 1/3] ALSA: cs46xx: " Qianfeng Rong
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Qianfeng Rong @ 2025-08-24 13:55 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Qianfeng Rong, Philipp Stanner,
Andy Shevchenko, Thorsten Blum, open list:SOUND, open list
Remove array_size() calls and replace vmalloc() with vmalloc_array() to
simplify the code and maintain consistency with existing kmalloc_array()
usage.
vmalloc_array() is also optimized better, resulting in less instructions
being used [1].
Link: https://lore.kernel.org/lkml/abc66ec5-85a4-47e1-9759-2f60ab111971@vivo.com/ #1
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Qianfeng Rong (3):
ALSA: cs46xx: use vmalloc_array() to simplify code
ALSA: emu10k1: use vmalloc_array() to simplify code
ALSA: maestro3: use vmalloc_array() to simplify code
sound/pci/cs46xx/dsp_spos.c | 4 ++--
sound/pci/emu10k1/emu10k1_main.c | 8 ++++----
sound/pci/emu10k1/emufx.c | 2 +-
sound/pci/emu10k1/p16v.c | 2 +-
sound/pci/maestro3.c | 5 ++---
5 files changed, 10 insertions(+), 11 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] ALSA: cs46xx: use vmalloc_array() to simplify code
2025-08-24 13:55 [PATCH 0/3] ALSA: use vmalloc_array() to simplify code Qianfeng Rong
@ 2025-08-24 13:55 ` Qianfeng Rong
2025-08-24 13:55 ` [PATCH 2/3] ALSA: emu10k1: " Qianfeng Rong
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Qianfeng Rong @ 2025-08-24 13:55 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Qianfeng Rong, open list:SOUND,
open list
Remove array_size() calls and replace vmalloc() with vmalloc_array() in
cs46xx_dsp_spos_create() to simplify the code and maintain consistency
with existing kmalloc_array() usage.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
sound/pci/cs46xx/dsp_spos.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sound/pci/cs46xx/dsp_spos.c b/sound/pci/cs46xx/dsp_spos.c
index e07f85322f1c..0aa68f9dd2aa 100644
--- a/sound/pci/cs46xx/dsp_spos.c
+++ b/sound/pci/cs46xx/dsp_spos.c
@@ -228,8 +228,8 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
/* better to use vmalloc for this big table */
ins->symbol_table.symbols =
- vmalloc(array_size(DSP_MAX_SYMBOLS,
- sizeof(struct dsp_symbol_entry)));
+ vmalloc_array(DSP_MAX_SYMBOLS,
+ sizeof(struct dsp_symbol_entry));
ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL);
ins->modules = kmalloc_array(DSP_MAX_MODULES,
sizeof(struct dsp_module_desc),
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] ALSA: emu10k1: use vmalloc_array() to simplify code
2025-08-24 13:55 [PATCH 0/3] ALSA: use vmalloc_array() to simplify code Qianfeng Rong
2025-08-24 13:55 ` [PATCH 1/3] ALSA: cs46xx: " Qianfeng Rong
@ 2025-08-24 13:55 ` Qianfeng Rong
2025-08-24 13:55 ` [PATCH 3/3] ALSA: maestro3: " Qianfeng Rong
2025-08-25 11:01 ` [PATCH 0/3] ALSA: " Andy Shevchenko
3 siblings, 0 replies; 7+ messages in thread
From: Qianfeng Rong @ 2025-08-24 13:55 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Philipp Stanner, Andy Shevchenko,
Qianfeng Rong, Thorsten Blum, open list:SOUND, open list
Remove array_size() calls and replace vmalloc() with vmalloc_array() to
simplify the code and maintain consistency with existing kmalloc_array()
usage.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
sound/pci/emu10k1/emu10k1_main.c | 8 ++++----
sound/pci/emu10k1/emufx.c | 2 +-
sound/pci/emu10k1/p16v.c | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index bbe252b8916c..f6ae78956eca 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -1579,10 +1579,10 @@ int snd_emu10k1_create(struct snd_card *card,
(unsigned long)emu->ptb_pages.addr,
(unsigned long)(emu->ptb_pages.addr + emu->ptb_pages.bytes));
- emu->page_ptr_table = vmalloc(array_size(sizeof(void *),
- emu->max_cache_pages));
- emu->page_addr_table = vmalloc(array_size(sizeof(unsigned long),
- emu->max_cache_pages));
+ emu->page_ptr_table = vmalloc_array(emu->max_cache_pages,
+ sizeof(void *));
+ emu->page_addr_table = vmalloc_array(emu->max_cache_pages,
+ sizeof(unsigned long));
if (!emu->page_ptr_table || !emu->page_addr_table)
return -ENOMEM;
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 7db0660e6b61..130e713fe248 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -2648,7 +2648,7 @@ int snd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu)
if (! emu->tram_val_saved || ! emu->tram_addr_saved)
return -ENOMEM;
len = emu->audigy ? 2 * 1024 : 2 * 512;
- emu->saved_icode = vmalloc(array_size(len, 4));
+ emu->saved_icode = vmalloc_array(len, 4);
if (! emu->saved_icode)
return -ENOMEM;
return 0;
diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c
index e774174d10de..ca732e6464ec 100644
--- a/sound/pci/emu10k1/p16v.c
+++ b/sound/pci/emu10k1/p16v.c
@@ -795,7 +795,7 @@ int snd_p16v_mixer(struct snd_emu10k1 *emu)
int snd_p16v_alloc_pm_buffer(struct snd_emu10k1 *emu)
{
- emu->p16v_saved = vmalloc(array_size(NUM_CHS * 4, 0x80));
+ emu->p16v_saved = vmalloc_array(NUM_CHS * 4, 0x80);
if (! emu->p16v_saved)
return -ENOMEM;
return 0;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] ALSA: maestro3: use vmalloc_array() to simplify code
2025-08-24 13:55 [PATCH 0/3] ALSA: use vmalloc_array() to simplify code Qianfeng Rong
2025-08-24 13:55 ` [PATCH 1/3] ALSA: cs46xx: " Qianfeng Rong
2025-08-24 13:55 ` [PATCH 2/3] ALSA: emu10k1: " Qianfeng Rong
@ 2025-08-24 13:55 ` Qianfeng Rong
2025-08-25 11:01 ` [PATCH 0/3] ALSA: " Andy Shevchenko
3 siblings, 0 replies; 7+ messages in thread
From: Qianfeng Rong @ 2025-08-24 13:55 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Andy Shevchenko, Qianfeng Rong,
Philipp Stanner, open list:SOUND, open list
Remove array_size() calls and replace vmalloc() with vmalloc_array() in
snd_m3_create() to simplify the code.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
sound/pci/maestro3.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index e092097599ff..0170b432402b 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -2580,9 +2580,8 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
if (IS_ENABLED(CONFIG_PM_SLEEP)) {
chip->suspend_mem =
- vmalloc(array_size(sizeof(u16),
- REV_B_CODE_MEMORY_LENGTH +
- REV_B_DATA_MEMORY_LENGTH));
+ vmalloc_array(REV_B_CODE_MEMORY_LENGTH +
+ REV_B_DATA_MEMORY_LENGTH, sizeof(u16));
if (!chip->suspend_mem)
dev_warn(card->dev, "can't allocate apm buffer\n");
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] ALSA: use vmalloc_array() to simplify code
2025-08-24 13:55 [PATCH 0/3] ALSA: use vmalloc_array() to simplify code Qianfeng Rong
` (2 preceding siblings ...)
2025-08-24 13:55 ` [PATCH 3/3] ALSA: maestro3: " Qianfeng Rong
@ 2025-08-25 11:01 ` Andy Shevchenko
2025-08-25 11:46 ` Qianfeng Rong
3 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2025-08-25 11:01 UTC (permalink / raw)
To: Qianfeng Rong
Cc: Jaroslav Kysela, Takashi Iwai, Philipp Stanner, Thorsten Blum,
open list:SOUND, open list
On Sun, Aug 24, 2025 at 09:55:09PM +0800, Qianfeng Rong wrote:
> Remove array_size() calls and replace vmalloc() with vmalloc_array() to
> simplify the code and maintain consistency with existing kmalloc_array()
> usage.
>
> vmalloc_array() is also optimized better, resulting in less instructions
> being used [1].
Have you considered using sizeof(*...) where it makes sense?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] ALSA: use vmalloc_array() to simplify code
2025-08-25 11:01 ` [PATCH 0/3] ALSA: " Andy Shevchenko
@ 2025-08-25 11:46 ` Qianfeng Rong
2025-08-25 11:50 ` Philipp Stanner
0 siblings, 1 reply; 7+ messages in thread
From: Qianfeng Rong @ 2025-08-25 11:46 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jaroslav Kysela, Takashi Iwai, Philipp Stanner, Thorsten Blum,
open list:SOUND, open list
在 2025/8/25 19:01, Andy Shevchenko 写道:
> On Sun, Aug 24, 2025 at 09:55:09PM +0800, Qianfeng Rong wrote:
>> Remove array_size() calls and replace vmalloc() with vmalloc_array() to
>> simplify the code and maintain consistency with existing kmalloc_array()
>> usage.
>>
>> vmalloc_array() is also optimized better, resulting in less instructions
>> being used [1].
> Have you considered using sizeof(*...) where it makes sense?
I believe that sizeof(*...) should preferably not be mixed with this patch;
instead, it should be addressed in a separate, independent patch that
covers all relevant instances.
Additionally, I understand that not everyone prefers using sizeof(*...), as
it reduces readability. What do you think, Andy?
Best regards,
Qianfeng
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] ALSA: use vmalloc_array() to simplify code
2025-08-25 11:46 ` Qianfeng Rong
@ 2025-08-25 11:50 ` Philipp Stanner
0 siblings, 0 replies; 7+ messages in thread
From: Philipp Stanner @ 2025-08-25 11:50 UTC (permalink / raw)
To: Qianfeng Rong, Andy Shevchenko
Cc: Jaroslav Kysela, Takashi Iwai, Philipp Stanner, Thorsten Blum,
open list:SOUND, open list
On Mon, 2025-08-25 at 19:46 +0800, Qianfeng Rong wrote:
>
> 在 2025/8/25 19:01, Andy Shevchenko 写道:
> > On Sun, Aug 24, 2025 at 09:55:09PM +0800, Qianfeng Rong wrote:
> > > Remove array_size() calls and replace vmalloc() with vmalloc_array() to
> > > simplify the code and maintain consistency with existing kmalloc_array()
> > > usage.
> > >
> > > vmalloc_array() is also optimized better, resulting in less instructions
> > > being used [1].
> > Have you considered using sizeof(*...) where it makes sense?
> I believe that sizeof(*...) should preferably not be mixed with this patch;
> instead, it should be addressed in a separate, independent patch that
> covers all relevant instances.
>
> Additionally, I understand that not everyone prefers using sizeof(*...), as
> it reduces readability. What do you think, Andy?
I agree that should be addressed in a separate patch, if at all.
As for sizeof(*foo), one gets used to it. I think it's preferred in the
kernel often because it's more difficult to introduce bugs like so:
long *foo;
foo = kmalloc(sizeof(long) * 9001);
When you later change long *foo to int *foo and forget about the malloc
place, you'll get an overflow.
foo = kmalloc(sizeof(*foo) …) can never have that problem.
Regards
P.
>
> Best regards,
> Qianfeng
> >
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-08-25 11:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-24 13:55 [PATCH 0/3] ALSA: use vmalloc_array() to simplify code Qianfeng Rong
2025-08-24 13:55 ` [PATCH 1/3] ALSA: cs46xx: " Qianfeng Rong
2025-08-24 13:55 ` [PATCH 2/3] ALSA: emu10k1: " Qianfeng Rong
2025-08-24 13:55 ` [PATCH 3/3] ALSA: maestro3: " Qianfeng Rong
2025-08-25 11:01 ` [PATCH 0/3] ALSA: " Andy Shevchenko
2025-08-25 11:46 ` Qianfeng Rong
2025-08-25 11:50 ` Philipp Stanner
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).