linux/sound/usb
Len Baker f02f2f1bf9 ALSA: usx2y: Prefer struct_size over open coded arithmetic
As noted in the "Deprecated Interfaces, Language Features, Attributes,
and Conventions" documentation [1], size calculations (especially
multiplication) should not be performed in memory allocator (or similar)
function arguments due to the risk of them overflowing. This could lead
to values wrapping around and a smaller allocation being made than the
caller was expecting. Using those allocations could lead to linear
overflows of heap memory and other misbehaviors.

In this case this is not actually dynamic size: all the operands
involved in the calculation are constant values. However it is better to
refactor this anyway, just to keep the open-coded math idiom out of
code.

So, use the struct_size() helper to do the arithmetic instead of the
argument "size + size * count" in the kzalloc() function.

Also, take the opportunity to refactor the declaration variables to make
it more easy to read.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Len Baker <len.baker@gmx.com>
Link: https://lore.kernel.org/r/20210919133727.44694-1-len.baker@gmx.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-09-21 18:38:11 +02:00
..
6fire module: remove never implemented MODULE_SUPPORTED_DEVICE 2021-03-17 13:16:18 -07:00
bcd2000 ALSA: Convert strlcpy to strscpy when return value is unused 2021-01-08 09:30:05 +01:00
caiaq module: remove never implemented MODULE_SUPPORTED_DEVICE 2021-03-17 13:16:18 -07:00
hiface module: remove never implemented MODULE_SUPPORTED_DEVICE 2021-03-17 13:16:18 -07:00
line6 ALSA: line6: Fix racy initialization of LINE6 MIDI 2021-05-19 16:25:57 +02:00
misc module: remove never implemented MODULE_SUPPORTED_DEVICE 2021-03-17 13:16:18 -07:00
usx2y ALSA: usx2y: Prefer struct_size over open coded arithmetic 2021-09-21 18:38:11 +02:00
card.c ALSA: usb-audio: Unify mixer resume and reset_resume procedure 2021-09-13 15:00:31 +02:00
card.h ALSA: usb-audio: Work around for XRUN with low latency playback 2021-08-27 22:34:59 +02:00
clock.c ALSA: usb-audio: Move clock setup quirk into quirk_flags 2021-08-02 09:05:59 +02:00
clock.h ALSA: usb-audio: Constify audioformat pointer references 2020-11-23 15:15:36 +01:00
endpoint.c Merge branch 'for-linus' into for-next 2021-08-30 08:04:04 +02:00
endpoint.h ALSA: usb-audio: Remove the repeated declaration 2021-05-30 09:30:46 +02:00
format.c ALSA: usb-audio: Move rate validation quirk into quirk_flags 2021-08-02 09:06:03 +02:00
format.h
helper.c ALSA: usb-audio: Add snd_usb_get_host_interface() helper 2020-11-23 15:13:47 +01:00
helper.h ALSA: usb-audio: Add snd_usb_get_host_interface() helper 2020-11-23 15:13:47 +01:00
implicit.c ALSA: usb-audio: Move playback_first flag into quirk_flags 2021-08-02 09:05:58 +02:00
implicit.h ALSA: usb-audio: Factor out the implicit feedback quirk code 2020-11-23 15:17:00 +01:00
Kconfig
Makefile ALSA: usb-audio: Factor out the implicit feedback quirk code 2020-11-23 15:17:00 +01:00
media.c ALSA: usb-audio: fix spelling mistakes 2021-07-05 19:33:54 +02:00
media.h
midi.c ALSA: usb-audio: Fix potential out-of-bounce access in MIDI EP parser 2021-05-11 11:10:37 +02:00
midi.h ALSA: usb-audio: generate midi streaming substream names from jack names 2021-03-01 09:21:54 +01:00
mixer_maps.c ALSA: usb-audio: Move ignore_ctl_error check into quirk_flags 2021-08-02 09:06:05 +02:00
mixer_quirks.c ALSA: usb-audio: Unify mixer resume and reset_resume procedure 2021-09-13 15:00:31 +02:00
mixer_quirks.h
mixer_s1810c.c ALSA: usb-audio: fix spelling mistakes 2021-07-05 19:33:54 +02:00
mixer_s1810c.h ALSA: usb-audio: Add support for Presonus Studio 1810c 2020-02-15 09:46:16 +01:00
mixer_scarlett_gen2.c ALSA: scarlett2: Fix line out/speaker switching notifications 2021-07-24 10:05:30 +02:00
mixer_scarlett_gen2.h ALSA: usb-audio: scarlett2: Improve driver startup messages 2021-05-21 16:22:52 +02:00
mixer_scarlett.c ALSA: usb-audio: fix spelling mistakes 2021-07-05 19:33:54 +02:00
mixer_scarlett.h
mixer_us16x08.c ALSA: Convert strlcpy to strscpy when return value is unused 2021-01-08 09:30:05 +01:00
mixer_us16x08.h
mixer.c ALSA: usb-audio: Unify mixer resume and reset_resume procedure 2021-09-13 15:00:31 +02:00
mixer.h ALSA: usb-audio: Unify mixer resume and reset_resume procedure 2021-09-13 15:00:31 +02:00
pcm.c ALSA: usb-audio: Add lowlatency module option 2021-08-29 09:41:27 +02:00
pcm.h ALSA: usb-audio: Make snd_usb_pcm_delay() static 2021-06-02 09:01:17 +02:00
power.c
power.h
proc.c ALSA: usb-audio: Show sync endpoint information in proc outputs 2020-11-23 15:16:45 +01:00
proc.h
quirks-table.h ALSA: usb-audio: Move autosuspend quirk into quirk_flags 2021-08-02 09:06:04 +02:00
quirks.c ALSA: usb-audio: Add registration quirk for JBL Quantum 800 2021-09-01 22:42:28 +02:00
quirks.h ALSA: usb-audio: Move interface setup delay into quirk_flags 2021-08-02 09:06:02 +02:00
stream.c ALSA: usb-audio: Move tx_length quirk handling to quirk_flags 2021-08-02 09:05:57 +02:00
stream.h
usbaudio.h Merge branch 'for-linus' into for-next 2021-08-30 08:04:04 +02:00
validate.c