* [PATCH] powerpc/powernv/pci: Use kmalloc_array() in two functions
@ 2016-08-24 20:36 SF Markus Elfring
2016-08-25 17:51 ` walter harms
2017-01-27 0:40 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: SF Markus Elfring @ 2016-08-24 20:36 UTC (permalink / raw)
To: linuxppc-dev, Alexey Kardashevskiy, Alistair Popple,
Benjamin Herrenschmidt, Gavin Shan, Ian Munsie, Michael Ellerman,
Paul Mackerras, Wei Yang
Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 24 Aug 2016 22:26:37 +0200
A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus reuse the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
arch/powerpc/platforms/powernv/pci-ioda.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index fd9444f..2366552 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1305,7 +1305,9 @@ static int pnv_pci_vf_assign_m64(struct pci_dev *pdev, u16 num_vfs)
else
m64_bars = 1;
- pdn->m64_map = kmalloc(sizeof(*pdn->m64_map) * m64_bars, GFP_KERNEL);
+ pdn->m64_map = kmalloc_array(m64_bars,
+ sizeof(*pdn->m64_map),
+ GFP_KERNEL);
if (!pdn->m64_map)
return -ENOMEM;
/* Initialize the m64_map to IODA_INVALID_M64 */
@@ -1572,8 +1574,9 @@ int pnv_pci_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
/* Allocating pe_num_map */
if (pdn->m64_single_mode)
- pdn->pe_num_map = kmalloc(sizeof(*pdn->pe_num_map) * num_vfs,
- GFP_KERNEL);
+ pdn->pe_num_map = kmalloc_array(num_vfs,
+ sizeof(*pdn->pe_num_map),
+ GFP_KERNEL);
else
pdn->pe_num_map = kmalloc(sizeof(*pdn->pe_num_map), GFP_KERNEL);
--
2.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/powernv/pci: Use kmalloc_array() in two functions
2016-08-24 20:36 [PATCH] powerpc/powernv/pci: Use kmalloc_array() in two functions SF Markus Elfring
@ 2016-08-25 17:51 ` walter harms
2017-01-27 0:40 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: walter harms @ 2016-08-25 17:51 UTC (permalink / raw)
Cc: linuxppc-dev, Alexey Kardashevskiy, Alistair Popple,
Benjamin Herrenschmidt, Gavin Shan, Ian Munsie, Michael Ellerman,
Paul Mackerras, Wei Yang, LKML, kernel-janitors, Julia Lawall,
Paolo Bonzini
Am 24.08.2016 22:36, schrieb SF Markus Elfring:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 24 Aug 2016 22:26:37 +0200
>
> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus reuse the corresponding function "kmalloc_array".
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> arch/powerpc/platforms/powernv/pci-ioda.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
> index fd9444f..2366552 100644
> --- a/arch/powerpc/platforms/powernv/pci-ioda.c
> +++ b/arch/powerpc/platforms/powernv/pci-ioda.c
> @@ -1305,7 +1305,9 @@ static int pnv_pci_vf_assign_m64(struct pci_dev *pdev, u16 num_vfs)
> else
> m64_bars = 1;
>
> - pdn->m64_map = kmalloc(sizeof(*pdn->m64_map) * m64_bars, GFP_KERNEL);
> + pdn->m64_map = kmalloc_array(m64_bars,
> + sizeof(*pdn->m64_map),
> + GFP_KERNEL);
> if (!pdn->m64_map)
> return -ENOMEM;
> /* Initialize the m64_map to IODA_INVALID_M64 */
> @@ -1572,8 +1574,9 @@ int pnv_pci_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
>
> /* Allocating pe_num_map */
> if (pdn->m64_single_mode)
> - pdn->pe_num_map = kmalloc(sizeof(*pdn->pe_num_map) * num_vfs,
> - GFP_KERNEL);
> + pdn->pe_num_map = kmalloc_array(num_vfs,
> + sizeof(*pdn->pe_num_map),
> + GFP_KERNEL);
> else
> pdn->pe_num_map = kmalloc(sizeof(*pdn->pe_num_map), GFP_KERNEL);
>
what is the value of num_vfs in the !pdn->m64_single_mode case ?
otherwise someone could make it like:
if (!pdn->m64_single_mode)
num_vfs=1;
pdn->pe_num_map = kmalloc_array(num_vfs, ....
so it looks a bit oversophisticated.
re,
wh
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: powerpc/powernv/pci: Use kmalloc_array() in two functions
2016-08-24 20:36 [PATCH] powerpc/powernv/pci: Use kmalloc_array() in two functions SF Markus Elfring
2016-08-25 17:51 ` walter harms
@ 2017-01-27 0:40 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2017-01-27 0:40 UTC (permalink / raw)
To: SF Markus Elfring, linuxppc-dev, Alexey Kardashevskiy,
Alistair Popple, Benjamin Herrenschmidt, Gavin Shan, Ian Munsie,
Paul Mackerras, Wei Yang
Cc: Julia Lawall, kernel-janitors, LKML, Paolo Bonzini
On Wed, 2016-08-24 at 20:36:54 UTC, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 24 Aug 2016 22:26:37 +0200
>
> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus reuse the corresponding function "kmalloc_array".
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/fb37e12896c1ba0407012fe8cdc0b0
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-01-27 0:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-24 20:36 [PATCH] powerpc/powernv/pci: Use kmalloc_array() in two functions SF Markus Elfring
2016-08-25 17:51 ` walter harms
2017-01-27 0:40 ` Michael Ellerman
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).