linux-imx/drivers/input
Erick Archer c727e46f0c Input: ff-core - prefer struct_size over open coded arithmetic
[ Upstream commit a08b8f8557 ]

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-07-11 12:49:06 +02:00
..
gameport Input: gameport - add ISA and HAS_IOPORT dependencies 2023-07-05 17:32:34 -07:00
joystick Input: xpad - add support for ASUS ROG RAIKIRI 2024-06-12 11:11:27 +02:00
keyboard Input: gpio_keys_polled - suppress deferred probe error for gpio 2024-03-26 18:19:15 -04:00
misc Input: pm8xxx-vibrator - correct VIB_MAX_LEVELS calculation 2024-06-12 11:12:37 +02:00
mouse Input: cyapa - add missing input core locking to suspend/resume functions 2024-06-12 11:12:40 +02:00
rmi4 Input: synaptics-rmi4 - fail probing if memory allocation for "phys" fails 2024-04-13 13:07:33 +02:00
serio Input: i8042 - add Fujitsu Lifebook U728 to i8042 quirk table 2024-03-01 13:34:53 +01:00
tablet Input: pegasus-notetaker - check pipe type when probing 2023-04-09 19:19:14 -07:00
tests Input: tests - add test to cover all input_grab_device() function 2023-05-23 14:50:28 -07:00
touchscreen Input: ili210x - fix ili251x_read_touch_data() return value 2024-07-05 09:33:43 +02:00
apm-power.c
evbug.c
evdev.c
ff-core.c Input: ff-core - prefer struct_size over open coded arithmetic 2024-07-11 12:49:06 +02:00
ff-memless.c
input-compat.c
input-compat.h
input-core-private.h
input-leds.c
input-mt.c
input-poller.c
input-poller.h
input.c Input: try trimming too long modalias strings 2024-06-12 11:11:18 +02:00
joydev.c
Kconfig Input: tests - modular KUnit tests should not depend on KUNIT=y 2023-05-02 10:39:00 -07:00
Makefile Input: Add KUnit tests for some of the input core helper functions 2023-04-01 22:47:04 -07:00
matrix-keymap.c
mousedev.c
sparse-keymap.c
touchscreen.c
vivaldi-fmap.c