Re: [PATCH 02/26] IB/ocrdma: Use kcalloc() in ocrdma_mbx_alloc_pd_range()
From: Doug Ledford
Date: Thu Apr 20 2017 - 16:41:33 EST
On Wed, 2017-03-08 at 16:03 +0200, Yuval Shaia wrote:
> On Wed, Mar 08, 2017 at 01:41:00PM +0100, SF Markus Elfring wrote:
> >
> > From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
> > Date: Tue, 7 Mar 2017 18:23:54 +0100
> >
> > * Multiplications for the size determination of memory allocations
> > Â indicated that array data structures should be processed.
> > Â Thus reuse the corresponding function "kcalloc".
> >
> > Â This issue was detected by using the Coccinelle software.
> >
> > * Delete the local variable "pd_bitmap_size" which became
> > unnecessary with
> > Â this refactoring.
> >
> > Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
> > ---
> > Âdrivers/infiniband/hw/ocrdma/ocrdma_hw.c | 16 ++++++++--------
> > Â1 file changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
> > b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
> > index cbac41b15d94..d5a3127b6df8 100644
> > --- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
> > +++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
> > @@ -1505,7 +1505,6 @@ int ocrdma_mbx_dealloc_pd(struct ocrdma_dev
> > *dev, struct ocrdma_pd *pd)
> > Âstatic int ocrdma_mbx_alloc_pd_range(struct ocrdma_dev *dev)
> > Â{
> > Â int status = -ENOMEM;
> > - size_t pd_bitmap_size;
> > Â struct ocrdma_alloc_pd_range *cmd;
> > Â struct ocrdma_alloc_pd_range_rsp *rsp;
> > Â
> > @@ -1527,10 +1526,10 @@ static int ocrdma_mbx_alloc_pd_range(struct
> > ocrdma_dev *dev)
> > Â dev->pd_mgr->pd_dpp_start = rsp-
> > >dpp_page_pdid &
> > Â OCRDMA_ALLOC_PD_RNG_RSP_ST
> > ART_PDID_MASK;
> > Â dev->pd_mgr->max_dpp_pd = rsp->pd_count;
> > - pd_bitmap_size =
> > - BITS_TO_LONGS(rsp->pd_count) *
> > sizeof(long);
> > - dev->pd_mgr->pd_dpp_bitmap =
> > kzalloc(pd_bitmap_size,
> > - ÂÂÂÂÂGFP_K
> > ERNEL);
> > + dev->pd_mgr->pd_dpp_bitmap
> > + = kcalloc(BITS_TO_LONGS(rsp-
> > >pd_count),
> > + sizeof(lon
> > g),
> > + GFP_KERNEL
> > );
>
> kzalloc gives "clean" buffer.
> Just making sure that it is fine with you if the array is not
> "clean".
> (looking at _ocrdma_pd_mgr_get_bitmap i think it should).
kcalloc is documented to return memory set to 0.
> >
> > Â }
> > Â kfree(cmd);
> > Â }
> > @@ -1546,9 +1545,10 @@ static int ocrdma_mbx_alloc_pd_range(struct
> > ocrdma_dev *dev)
> > Â dev->pd_mgr->pd_norm_start = rsp->dpp_page_pdid &
> > Â OCRDMA_ALLOC_PD_RNG_RSP_ST
> > ART_PDID_MASK;
> > Â dev->pd_mgr->max_normal_pd = rsp->pd_count;
> > - pd_bitmap_size = BITS_TO_LONGS(rsp->pd_count) *
> > sizeof(long);
> > - dev->pd_mgr->pd_norm_bitmap =
> > kzalloc(pd_bitmap_size,
> > - ÂÂÂÂÂÂGFP_KERNEL);
> > + dev->pd_mgr->pd_norm_bitmap
> > + = kcalloc(BITS_TO_LONGS(rsp->pd_count),
> > + sizeof(long),
> > + GFP_KERNEL);
> > Â }
> > Â kfree(cmd);
> > Â
> > --Â
> > 2.12.0
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-
> > rdma" in
> > the body of a message to majordomo@xxxxxxxxxxxxxxx
> > More majordomo info atÂÂhttp://vger.kernel.org/majordomo-info.html
--
Doug Ledford <dledford@xxxxxxxxxx>
  GPG KeyID: B826A3330E572FDD
 Â
Key fingerprint = AE6B 1BDA 122B 23B4 265B Â1274 B826 A333 0E57 2FDD