[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZJTYWQ5NA726baWK@work>
Date: Thu, 22 Jun 2023 17:25:13 -0600
From: "Gustavo A. R. Silva" <gustavoars@...nel.org>
To: "David S. Miller" <davem@...emloft.net>
Cc: sparclinux@...r.kernel.org, linux-kernel@...r.kernel.org,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
linux-hardening@...r.kernel.org
Subject: [PATCH][next] openprom: Use struct_size() helper
Prefer struct_size() over open-coded versions.
Link: https://github.com/KSPP/linux/issues/160
Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>
---
drivers/sbus/char/openprom.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
index 30b9751aad30..de56c8fec373 100644
--- a/drivers/sbus/char/openprom.c
+++ b/drivers/sbus/char/openprom.c
@@ -76,7 +76,9 @@ static int copyin(struct openpromio __user *info, struct openpromio **opp_p)
if (bufsize > OPROMMAXPARAM)
bufsize = OPROMMAXPARAM;
- if (!(*opp_p = kzalloc(sizeof(int) + bufsize + 1, GFP_KERNEL)))
+ *opp_p = kzalloc(struct_size(*opp_p, oprom_array, bufsize + 1),
+ GFP_KERNEL);
+ if (!*opp_p)
return -ENOMEM;
if (copy_from_user(&(*opp_p)->oprom_array,
@@ -95,7 +97,9 @@ static int getstrings(struct openpromio __user *info, struct openpromio **opp_p)
if (!info || !opp_p)
return -EFAULT;
- if (!(*opp_p = kzalloc(sizeof(int) + OPROMMAXPARAM + 1, GFP_KERNEL)))
+ *opp_p = kzalloc(struct_size(*opp_p, oprom_array, OPROMMAXPARAM + 1),
+ GFP_KERNEL);
+ if (!*opp_p)
return -ENOMEM;
(*opp_p)->oprom_size = 0;
--
2.34.1
Powered by blists - more mailing lists