[PATCH 0/3] ALSA: use vmalloc_array() to simplify code

Qianfeng Rong posted 3 patches 1 month, 1 week ago
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(-)
[PATCH 0/3] ALSA: use vmalloc_array() to simplify code
Posted by Qianfeng Rong 1 month, 1 week ago
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
Re: [PATCH 0/3] ALSA: use vmalloc_array() to simplify code
Posted by Andy Shevchenko 1 month, 1 week ago
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
Re: [PATCH 0/3] ALSA: use vmalloc_array() to simplify code
Posted by Qianfeng Rong 1 month, 1 week ago
在 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
>
Re: [PATCH 0/3] ALSA: use vmalloc_array() to simplify code
Posted by Philipp Stanner 1 month, 1 week ago
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
> >