extcon: usbc-cros-ec: Use struct_size() helper in kzalloc()
authorGustavo A. R. Silva <gustavoars@kernel.org>
Tue, 25 Jan 2022 19:26:34 +0000 (13:26 -0600)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 13 May 2022 08:03:40 +0000 (17:03 +0900)
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 <gustavoars@kernel.org>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
drivers/extcon/extcon-usbc-cros-ec.c

index 5290cc2..fde1db6 100644 (file)
@@ -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;