* [PATCH][next] enetc: Use struct_size() helper in kzalloc()
@ 2020-06-17 18:53 Gustavo A. R. Silva
2020-06-18 10:04 ` Claudiu Manoil
2020-06-19 3:36 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2020-06-17 18:53 UTC (permalink / raw)
To: Claudiu Manoil, David S. Miller, Jakub Kicinski
Cc: netdev, linux-kernel, 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.
This code was detected with the help of Coccinelle and, audited and
fixed manually.
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/ethernet/freescale/enetc/enetc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 298c55786fd9..61dbf19075fb 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -1687,7 +1687,7 @@ int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
int enetc_alloc_msix(struct enetc_ndev_priv *priv)
{
struct pci_dev *pdev = priv->si->pdev;
- int size, v_tx_rings;
+ int v_tx_rings;
int i, n, err, nvec;
nvec = ENETC_BDR_INT_BASE_IDX + priv->bdr_int_num;
@@ -1702,15 +1702,13 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv)
/* # of tx rings per int vector */
v_tx_rings = priv->num_tx_rings / priv->bdr_int_num;
- size = sizeof(struct enetc_int_vector) +
- sizeof(struct enetc_bdr) * v_tx_rings;
for (i = 0; i < priv->bdr_int_num; i++) {
struct enetc_int_vector *v;
struct enetc_bdr *bdr;
int j;
- v = kzalloc(size, GFP_KERNEL);
+ v = kzalloc(struct_size(v, tx_ring, v_tx_rings), GFP_KERNEL);
if (!v) {
err = -ENOMEM;
goto fail;
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH][next] enetc: Use struct_size() helper in kzalloc()
2020-06-17 18:53 [PATCH][next] enetc: Use struct_size() helper in kzalloc() Gustavo A. R. Silva
@ 2020-06-18 10:04 ` Claudiu Manoil
2020-06-19 3:36 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Claudiu Manoil @ 2020-06-18 10:04 UTC (permalink / raw)
To: Gustavo A. R. Silva, David S. Miller, Jakub Kicinski
Cc: netdev, linux-kernel, Gustavo A. R. Silva
>-----Original Message-----
>From: Gustavo A. R. Silva <gustavoars@kernel.org>
>Sent: Wednesday, June 17, 2020 9:53 PM
[...]
>Subject: [PATCH][next] enetc: 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.
>
>This code was detected with the help of Coccinelle and, audited and
>fixed manually.
>
>Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Claudiu Manoil <claudiu.manoil@nxp.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] enetc: Use struct_size() helper in kzalloc()
2020-06-17 18:53 [PATCH][next] enetc: Use struct_size() helper in kzalloc() Gustavo A. R. Silva
2020-06-18 10:04 ` Claudiu Manoil
@ 2020-06-19 3:36 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-06-19 3:36 UTC (permalink / raw)
To: gustavoars; +Cc: claudiu.manoil, kuba, netdev, linux-kernel, gustavo
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Date: Wed, 17 Jun 2020 13:53:17 -0500
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
>
> This code was detected with the help of Coccinelle and, audited and
> fixed manually.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Applied to net-next, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-19 3:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 18:53 [PATCH][next] enetc: Use struct_size() helper in kzalloc() Gustavo A. R. Silva
2020-06-18 10:04 ` Claudiu Manoil
2020-06-19 3:36 ` David Miller
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).