From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934388AbdAIJkM (ORCPT ); Mon, 9 Jan 2017 04:40:12 -0500 Received: from mx2.suse.de ([195.135.220.15]:40334 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754306AbdAIJkK (ORCPT ); Mon, 9 Jan 2017 04:40:10 -0500 Date: Mon, 9 Jan 2017 10:40:06 +0100 From: Michal Hocko To: SF Markus Elfring Cc: Andrew Morton , George Zhang , "Kirill A. Shutemov" , Masahiro Yamada , LKML , kernel-janitors@vger.kernel.org Subject: Re: [PATCH] VMCI: Use kmalloc_array() in qp_alloc_ppn_set() Message-ID: <20170109094006.GD7495@dhcp22.suse.cz> References: <9a04914a-138b-3f5d-b82a-8043b2602bd9@users.sourceforge.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9a04914a-138b-3f5d-b82a-8043b2602bd9@users.sourceforge.net> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun 08-01-17 17:37:08, SF Markus Elfring wrote: > From: Markus Elfring > Date: Sun, 8 Jan 2017 14:04:10 +0100 > > Multiplications for the size determination of memory allocations > indicated that array data structures should be processed. > Thus use the corresponding function "kmalloc_array". > > This issue was detected by using the Coccinelle software. I am surprised that Coccinelle found a single instance of this pattern. If there are more then I would suggest changing all of them at once along with the coccinelle program which has been used. > Signed-off-by: Markus Elfring > --- > drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c > index 498c0854305f..7b5c8a89cc54 100644 > --- a/drivers/misc/vmw_vmci/vmci_queue_pair.c > +++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c > @@ -486,13 +486,15 @@ static int qp_alloc_ppn_set(void *prod_q, > if (ppn_set->initialized) > return VMCI_ERROR_ALREADY_EXISTS; > > - produce_ppns = > - kmalloc(num_produce_pages * sizeof(*produce_ppns), GFP_KERNEL); > + produce_ppns = kmalloc_array(num_produce_pages, > + sizeof(*produce_ppns), > + GFP_KERNEL); > if (!produce_ppns) > return VMCI_ERROR_NO_MEM; > > - consume_ppns = > - kmalloc(num_consume_pages * sizeof(*consume_ppns), GFP_KERNEL); > + consume_ppns = kmalloc_array(num_consume_pages, > + sizeof(*consume_ppns), > + GFP_KERNEL); > if (!consume_ppns) { > kfree(produce_ppns); > return VMCI_ERROR_NO_MEM; > -- > 2.11.0 > -- Michal Hocko SUSE Labs