* [PATCH 1/1] power: supply: cros_peripheral: Use struct_size() helper in kzalloc()
@ 2022-06-07 15:03 Xiaohui Zhang
2022-06-09 20:06 ` Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: Xiaohui Zhang @ 2022-06-07 15:03 UTC (permalink / raw)
To: Xiaohui Zhang, Sebastian Reichel, linux-pm, linux-kernel
Similar to the handling of cros_usbpd_charger_ec_command in commit 441d38c60fbe
("power: supply: cros_usbpd: Use struct_size() helper in kzalloc()"),
we thought a patch might be needed here as well.
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: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>
---
drivers/power/supply/cros_peripheral_charger.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c
index 9fe6d826148d..1379afd9698d 100644
--- a/drivers/power/supply/cros_peripheral_charger.c
+++ b/drivers/power/supply/cros_peripheral_charger.c
@@ -63,7 +63,7 @@ static int cros_pchg_ec_command(const struct charger_data *charger,
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;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] power: supply: cros_peripheral: Use struct_size() helper in kzalloc()
2022-06-07 15:03 [PATCH 1/1] power: supply: cros_peripheral: Use struct_size() helper in kzalloc() Xiaohui Zhang
@ 2022-06-09 20:06 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2022-06-09 20:06 UTC (permalink / raw)
To: Xiaohui Zhang; +Cc: linux-pm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1319 bytes --]
Hi,
On Tue, Jun 07, 2022 at 11:03:44PM +0800, Xiaohui Zhang wrote:
> Similar to the handling of cros_usbpd_charger_ec_command in commit 441d38c60fbe
> ("power: supply: cros_usbpd: Use struct_size() helper in kzalloc()"),
> we thought a patch might be needed here as well.
>
> 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: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>
Thanks, queued.
-- Sebastian
> drivers/power/supply/cros_peripheral_charger.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c
> index 9fe6d826148d..1379afd9698d 100644
> --- a/drivers/power/supply/cros_peripheral_charger.c
> +++ b/drivers/power/supply/cros_peripheral_charger.c
> @@ -63,7 +63,7 @@ static int cros_pchg_ec_command(const struct charger_data *charger,
> 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;
>
> --
> 2.17.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-09 20:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07 15:03 [PATCH 1/1] power: supply: cros_peripheral: Use struct_size() helper in kzalloc() Xiaohui Zhang
2022-06-09 20:06 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).