Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: cros_usbpd: Use struct_size() helper in kzalloc()

Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.

Also, address the following sparse warnings:
drivers/power/supply/cros_usbpd-charger.c:107:23: warning: using sizeof on a flexible structure

Link: https://github.com/KSPP/linux/issues/174
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Gustavo A. R. Silva and committed by
Sebastian Reichel
441d38c6 e783362e

+1 -1
+1 -1
drivers/power/supply/cros_usbpd-charger.c
··· 104 104 struct cros_ec_command *msg; 105 105 int ret; 106 106 107 - msg = kzalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL); 107 + msg = kzalloc(struct_size(msg, data, max(outsize, insize)), GFP_KERNEL); 108 108 if (!msg) 109 109 return -ENOMEM; 110 110