From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wj0-x241.google.com ([2a00:1450:400c:c01::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cRQxo-0000tD-Gh for linux-mtd@lists.infradead.org; Wed, 11 Jan 2017 22:01:51 +0000 Received: by mail-wj0-x241.google.com with SMTP id dh1so108034wjb.3 for ; Wed, 11 Jan 2017 14:01:28 -0800 (PST) From: Marek Vasut Subject: Re: [PATCH 01/18] mtd-cfi_cmdset_0001: Use kmalloc_array() in cfi_intelext_partition_fixup() To: SF Markus Elfring , linux-mtd@lists.infradead.org, Boris Brezillon , Brian Norris , Cyrille Pitchen , David Woodhouse , Denys Vlasenko , Richard Weinberger References: <71189baa-8780-b80a-0b4d-9dae74763ba3@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org Message-ID: <31f8448f-aba7-965a-e924-e1ec63eecbaf@gmail.com> Date: Wed, 11 Jan 2017 22:59:52 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 01/11/2017 09:35 PM, SF Markus Elfring wrote: > From: Markus Elfring > Date: Tue, 10 Jan 2017 18:48:34 +0100 > > * A multiplication for the size determination of a memory allocation > indicated that an array data structure should be processed. > Thus use the corresponding function "kmalloc_array". > > This issue was detected by using the Coccinelle software. > > * Replace the specification of a data structure by a pointer dereference > to make the corresponding size determination a bit safer according to > the Linux coding style convention. > > Signed-off-by: Markus Elfring > --- > drivers/mtd/chips/cfi_cmdset_0001.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c > index 5e1b68cbcd0a..68227aa74d22 100644 > --- a/drivers/mtd/chips/cfi_cmdset_0001.c > +++ b/drivers/mtd/chips/cfi_cmdset_0001.c > @@ -746,7 +746,9 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd, > newcfi = kmalloc(sizeof(struct cfi_private) + numvirtchips * sizeof(struct flchip), GFP_KERNEL); > if (!newcfi) > return -ENOMEM; > - shared = kmalloc(sizeof(struct flchip_shared) * cfi->numchips, GFP_KERNEL); > + shared = kmalloc_array(cfi->numchips, > + sizeof(*shared), > + GFP_KERNEL); You can keep this on a single line, no need for the linebreak. It doesn't violate the 80-chars per line rule IMO. > if (!shared) { > kfree(newcfi); > return -ENOMEM; > -- Best regards, Marek Vasut