From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756312AbcHYSAa (ORCPT ); Thu, 25 Aug 2016 14:00:30 -0400 Received: from mx01-fr.bfs.de ([193.174.231.67]:20243 "EHLO mx01-fr.bfs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755820AbcHYSA2 (ORCPT ); Thu, 25 Aug 2016 14:00:28 -0400 Message-ID: <57BF3038.3000801@bfs.de> Date: Thu, 25 Aug 2016 19:51:52 +0200 From: walter harms Reply-To: wharms@bfs.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.1.16) Gecko/20101125 SUSE/3.0.11 Thunderbird/3.0.11 MIME-Version: 1.0 CC: linuxppc-dev@lists.ozlabs.org, Alexey Kardashevskiy , Alistair Popple , Benjamin Herrenschmidt , Gavin Shan , Ian Munsie , Michael Ellerman , Paul Mackerras , Wei Yang , LKML , kernel-janitors@vger.kernel.org, Julia Lawall , Paolo Bonzini Subject: Re: [PATCH] powerpc/powernv/pci: Use kmalloc_array() in two functions References: <817567b2-cdf6-7f7b-6041-9a026ea10a0f@users.sourceforge.net> In-Reply-To: <817567b2-cdf6-7f7b-6041-9a026ea10a0f@users.sourceforge.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 24.08.2016 22:36, schrieb SF Markus Elfring: > From: Markus Elfring > 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 > --- > 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