kernel_samsung_a53x/drivers/input
Erick Archer 3a115f26d8 Input: ff-core - prefer struct_size over open coded arithmetic
[ Upstream commit a08b8f8557ad88ffdff8905e5da972afe52e3307 ]

This is an effort to get rid of all multiplications from allocation
functions in order to prevent integer overflows [1][2].

As the "ff" variable is a pointer to "struct ff_device" and this
structure ends in a flexible array:

struct ff_device {
	[...]
	struct file *effect_owners[] __counted_by(max_effects);
};

the preferred way in the kernel is to use the struct_size() helper to
do the arithmetic instead of the calculation "size + count * size" in
the kzalloc() function.

The struct_size() helper returns SIZE_MAX on overflow. So, refactor
the comparison to take advantage of this.

This way, the code is more readable and safer.

This code was detected with the help of Coccinelle, and audited and
modified manually.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
Link: https://github.com/KSPP/linux/issues/160 [2]
Signed-off-by: Erick Archer <erick.archer@outlook.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/AS8PR02MB72371E646714BAE2E51A6A378B152@AS8PR02MB7237.eurprd02.prod.outlook.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-19 14:19:40 +01:00
..
gameport
input_boost
joystick Input: xpad - add Razer Wolverine V2 support 2024-11-18 12:12:17 +01:00
keyboard Input: gpio_keys_polled - suppress deferred probe error for gpio 2024-11-19 08:44:36 +01:00
misc Input: pm8xxx-vibrator - correct VIB_MAX_LEVELS calculation 2024-11-19 12:27:05 +01:00
mouse
rmi4 Input: synaptics-rmi4 - fail probing if memory allocation for "phys" fails 2024-11-19 09:23:14 +01:00
sec_input
serio Input: ioc3kbd - add device table 2024-11-19 12:27:05 +01:00
tablet
touchscreen Input: ili210x - fix ili251x_read_touch_data() return value 2024-11-19 14:19:30 +01:00
apm-power.c
evbug.c
evdev.c
ff-core.c Input: ff-core - prefer struct_size over open coded arithmetic 2024-11-19 14:19:40 +01:00
ff-memless.c
input-compat.c
input-compat.h
input-leds.c
input-mt.c
input-polldev.c
input-poller.c
input-poller.h
input.c Input: try trimming too long modalias strings 2024-11-19 14:19:02 +01:00
joydev.c
Kconfig
Makefile
matrix-keymap.c
mousedev.c
sparse-keymap.c