From: Gustavo A. R. Silva Date: Tue, 25 Jan 2022 19:26:34 +0000 (-0600) Subject: extcon: usbc-cros-ec: Use struct_size() helper in kzalloc() X-Git-Tag: v6.1-rc5~1160^2~77^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8ae4471d38c4952d8eb67ce60e3988c4ccb25dc6;p=platform%2Fkernel%2Flinux-starfive.git extcon: usbc-cros-ec: 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. Signed-off-by: Gustavo A. R. Silva Signed-off-by: Chanwoo Choi --- diff --git a/drivers/extcon/extcon-usbc-cros-ec.c b/drivers/extcon/extcon-usbc-cros-ec.c index 5290cc2..fde1db6 100644 --- a/drivers/extcon/extcon-usbc-cros-ec.c +++ b/drivers/extcon/extcon-usbc-cros-ec.c @@ -68,7 +68,7 @@ static int cros_ec_pd_command(struct cros_ec_extcon_info *info, struct cros_ec_command *msg; int ret; - msg = kzalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL); + msg = kzalloc(struct_size(msg, data, max(outsize, insize)), GFP_KERNEL); if (!msg) return -ENOMEM;