linux-sg2042/sound/usb/usx2y
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
..
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
us122l.c Merge branch 'topic/pci-rescan-prep-v2' into for-next 2021-05-25 08:50:03 +02:00
us122l.h ALSA: usx2y: Coding style fixes 2021-05-17 16:03:58 +02:00
usX2Yhwdep.c ALSA: usx2y: Fix shmem initialization 2021-05-17 16:05:10 +02:00
usX2Yhwdep.h ALSA: usx2y: Fix spaces 2021-05-17 16:03:46 +02:00
usb_stream.c ALSA: usx2y: Don't call free_pages_exact() with NULL address 2021-05-17 16:05:20 +02:00
usb_stream.h ALSA: usx2y: Coding style fixes 2021-05-17 16:03:58 +02:00
usbus428ctldefs.h ALSA: usx2y: Fix potential leaks of uninitialized memory 2021-05-17 16:04:10 +02:00
usbusx2y.c ALSA: usx2y: Cleanup probe and disconnect callbacks 2021-05-17 16:05:29 +02:00
usbusx2y.h ALSA: usx2y: Nuke pcm_list 2021-05-17 16:05:39 +02:00
usbusx2yaudio.c ALSA: usx2y: Prefer struct_size over open coded arithmetic 2021-09-21 18:38:11 +02:00
usx2y.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
usx2yhwdeppcm.c ALSA: usx2y: fix spelling mistakes 2021-07-05 19:30:33 +02:00
usx2yhwdeppcm.h ALSA: usx2y: Avoid camelCase 2021-05-17 16:03:34 +02:00