extcon: usbc-cros-ec: Use struct_size() helper in kzalloc()
Subsystems (2)
PATCH 1/1 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.
Also, address the following sparse warnings:drivers/extcon/extcon-usbc-cros-ec.c:71:23: warning: using sizeof on a flexible structure
--- drivers/extcon/extcon-usbc-cros-ec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/extcon/extcon-usbc-cros-ec.c +1 -1
@@ -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 ;
Signature · 1 line
2.27.0
Quoted 19 lines · Gustavo A. R. Silva
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/extcon/extcon-usbc-cros-ec.c:71:23: warning: using sizeof on a flexible structureSigned-off-by Gustavo A. R. Silva <[email protected]>--- drivers/extcon/extcon-usbc-cros-ec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/extcon/extcon-usbc-cros-ec.c +0
-0
drivers/extcon/extcon-usbc-cros-ec.c static int cros_ec_pd_command(struct cros_ec_extcon_info *info, · line 74
Quoted 8 lines
drivers/extcon/extcon-usbc-cros-ec.c +1
-1@@ -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 ;
Applied it. Thanks.
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Quoted 3 lines · Chanwoo Choi
On 1/26/22 4:26 AM, Gustavo A. R. Silva wrote:
Applied it. Thanks.
Great. :)
Thanks, Chanwoo.
--
Gustavo