Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752270AbdCHPHw (ORCPT ); Wed, 8 Mar 2017 10:07:52 -0500 Received: from mail-wr0-f175.google.com ([209.85.128.175]:32876 "EHLO mail-wr0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751394AbdCHPH1 (ORCPT ); Wed, 8 Mar 2017 10:07:27 -0500 MIME-Version: 1.0 In-Reply-To: References: From: Devesh Sharma Date: Wed, 8 Mar 2017 20:35:47 +0530 Message-ID: Subject: Re: [PATCH 17/26] IB/ocrdma: Use kmalloc_array() in ocrdma_create_srq() To: SF Markus Elfring Cc: linux-rdma , Devesh Sharma , Doug Ledford , Hal Rosenstock , Sean Hefty , Selvin Xavier , LKML , kernel-janitors@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1790 Lines: 42 On Wed, Mar 8, 2017 at 6:47 PM, SF Markus Elfring wrote: > From: Markus Elfring > Date: Wed, 8 Mar 2017 08:45:31 +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 type 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/infiniband/hw/ocrdma/ocrdma_verbs.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c > index bc9fb144e57b..ef670ac1cbe9 100644 > --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c > +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c > @@ -1910,8 +1910,9 @@ struct ib_srq *ocrdma_create_srq(struct ib_pd *ibpd, > > srq->bit_fields_len = (srq->rq.max_cnt / 32) + > (srq->rq.max_cnt % 32 ? 1 : 0); > - srq->idx_bit_fields = > - kmalloc(srq->bit_fields_len * sizeof(u32), GFP_KERNEL); Lets stick to kmalloc here? > + srq->idx_bit_fields = kmalloc_array(srq->bit_fields_len, > + sizeof(*srq->idx_bit_fields), > + GFP_KERNEL); > if (srq->idx_bit_fields == NULL) > goto arm_err; > memset(srq->idx_bit_fields, 0xff, > -- > 2.12.0 >