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(-)
Change array_size() to vmalloc_array(), Due to vmalloc_array()
is optimized better,uses fewer instructions, and handles
overflow more concisely
Signed-off-by: tanze <tanze@kylinos.cn>
---
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 b2fe2d164ba8..bdbd2dea1c4a 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -1574,10 +1574,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 37af7bf76347..091f6accfc44 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -2629,7 +2629,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 b74128e61254..79b097ada22b 100644
--- a/sound/pci/emu10k1/p16v.c
+++ b/sound/pci/emu10k1/p16v.c
@@ -791,7 +791,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.25.1
On Wed, Oct 22, 2025 at 05:27:38PM +0800, tanze wrote: > Change array_size() to vmalloc_array(), Due to vmalloc_array() > is optimized better,uses fewer instructions, and handles better, uses (mind a space after a comma) > overflow more concisely concisely. (mind a period at the end) ... > - emu->p16v_saved = vmalloc(array_size(NUM_CHS * 4, 0x80)); > + emu->p16v_saved = vmalloc_array(NUM_CHS * 4, 0x80); I think this should be emu->p16v_saved = vmalloc(array3_size(NUM_CHS, 4, 0x80)); Or, if we have vmalloc_array3(), which I doubt, use it. But since NUM_CHS sounds like a compile time constant, the above approach may work too. Anyway, this can be addressed later. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> -- With Best Regards, Andy Shevchenko
在 2025/10/23 14:35, Andy Shevchenko 写道: > On Wed, Oct 22, 2025 at 05:27:38PM +0800, tanze wrote: >> Change array_size() to vmalloc_array(), Due to vmalloc_array() >> is optimized better,uses fewer instructions, and handles > > better, uses > > (mind a space after a comma) > Thank you for pointing out the mistake. I will correct the error in the description in a subsequent version. >> overflow more concisely > > concisely. > > (mind a period at the end) > > ... > >> - emu->p16v_saved = vmalloc(array_size(NUM_CHS * 4, 0x80)); >> + emu->p16v_saved = vmalloc_array(NUM_CHS * 4, 0x80); > > I think this should be > > emu->p16v_saved = vmalloc(array3_size(NUM_CHS, 4, 0x80)); > > Or, if we have vmalloc_array3(), which I doubt, use it. > > But since NUM_CHS sounds like a compile time constant, the above approach may > work too. > Hi, Andy Shevchenko. I just checked the code and found that vmalloc_array3() does not exist yet. Initially, I only thought that vmalloc_array() is better and more concise than vmalloc(array3_size()). What do you think would be the better approach here? > Anyway, this can be addressed later. > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> > -- Best regards, Ze Tan
© 2016 - 2026 Red Hat, Inc.