From patchwork Sat Apr 22 14:36:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9694401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E0E3F600CA for ; Sat, 22 Apr 2017 14:36:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2B14277D9 for ; Sat, 22 Apr 2017 14:36:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4414285F0; Sat, 22 Apr 2017 14:36:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E680277D9 for ; Sat, 22 Apr 2017 14:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1424524AbdDVOgs (ORCPT ); Sat, 22 Apr 2017 10:36:48 -0400 Received: from mout.web.de ([212.227.15.4]:60056 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424351AbdDVOgq (ORCPT ); Sat, 22 Apr 2017 10:36:46 -0400 Received: from [192.168.1.2] ([77.181.100.232]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MfqSa-1cgzUG41cy-00N7lW; Sat, 22 Apr 2017 16:36:29 +0200 Subject: [PATCH v2 03/12] IB/ocrdma: Improve size determinations in ten functions From: SF Markus Elfring To: Devesh Sharma , Doug Ledford , Hal Rosenstock , Sean Hefty , Selvin Xavier , Yuval Shaia , linux-rdma@vger.kernel.org Cc: LKML , kernel-janitors@vger.kernel.org References: <1492720999.3041.18.camel@redhat.com> <86425035-7da8-d2b1-8544-d4f7540d50c6@users.sourceforge.net> Message-ID: <755f6c2c-03a2-7248-a5e3-9190d119cdaf@users.sourceforge.net> Date: Sat, 22 Apr 2017 16:36:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0.1 MIME-Version: 1.0 In-Reply-To: <86425035-7da8-d2b1-8544-d4f7540d50c6@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:HG560LCWGCW+/Wwh+oBLWArSDJtc6Rz3IpGFzegyIQVcD1oZ/kF o87ELruxsw7goif/hdq/kxXsg9YG3WJTx0tjFJ9+G0rHPopgZGcrawUx+rKxSJxcPDw3RbA 2iYsdp0ioGWdZuio0q6HLMJYqtC1FkzCyZk974v73D+lBVjW8u0yajmvjyb0heSbfpvULsV 4VZ2Fb30/0l9XTKx5TCeg== X-UI-Out-Filterresults: notjunk:1; V01:K0:O7JAssJjmRA=:Xg7wgZepk5RMl5Tl5NVEKJ nKQODqvuJKwJHi+bXsWMSgcB8SMzo2jiMKm2jYMKIbXHxm5Pz4mL5/kqc/xsmuvFXxDk/4UnQ aUyJrE4qD+UG7i3/Dz/dTo1kbZN+VVWhuaaNSQq4hs4mIl2K1DtenKtdmMx56kJOZ9IqVJ/Lf 3PIrIGIn3vgTsxImAg7y4s4SGYNcFatTZBrUrY/g8G1Nnn2afZx4Deg4HMrGjWF/wcWE11lZ6 PRF1zAfa5D9bhI1Z/wExctMRszv0y8pRhZhVnR6iVkwXzL7FK+6NyynPeeGHx6vTFLGDQ4csj c7rzAl5a1BXhklsbqTyhAWTV9GpP9ekbjaiNQ18JaegdIHF1KYpjcro/8w8xvyY7F2sg2kT0Z cqAVY1E/cRmBRaQmQdQremA08JYty4w/HVrfjfOeNlUqu+Lu/yw3CSjN2KESmQDdKVK6kvNN9 8zE0dzeRCMhO1EW/eag9LbC2AdNgJVNz6OO+9vFimDWC1jmecFEadCPehme1WWMtysFIHorwE fMS5LoNLFIcrqsaJF1T6lUtI22p83el/P2/Bw88YVJyDFnKmedG662JWyYAcEb/is7fKC4TlQ w6Cx3fhzpT+WY5ZOR3ARJHhLVOQfqK59fYto1cPHhiPPuPjS24xGYmkioB3CHZh7itS7I+vrc eZfGx04qlFegrV4p5jg5P1QVKm6oQLZYBZtup976xEdRBidr86NJ6zN4hVE1CWV3TYP0irRYd N9gwsOZw5LPmz0YPEX6KjGGSpfjhMrB1YSlUMpikx6dsGKRZyfoRzD2c/GL2QgbZf7c4cS4iJ AP5o9Wu Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 22 Apr 2017 13:26:49 +0200 Replace the specification of data types by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determinations a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring --- v2: Changes were rebased on source files from Linux next-20170421. These were recombined as requested by Doug Ledford. drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 28 ++++++++++++---------------- drivers/infiniband/hw/ocrdma/ocrdma_main.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 4 ++-- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c index d5a3127b6df8..7e58a74102f6 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c @@ -352,7 +352,7 @@ static void *ocrdma_init_emb_mqe(u8 opcode, u32 cmd_len) { struct ocrdma_mqe *mqe; - mqe = kzalloc(sizeof(struct ocrdma_mqe), GFP_KERNEL); + mqe = kzalloc(sizeof(*mqe), GFP_KERNEL); if (!mqe) return NULL; mqe->hdr.spcl_sge_cnt_emb |= @@ -890,7 +890,7 @@ static int ocrdma_mq_cq_handler(struct ocrdma_dev *dev, u16 cq_id) ocrdma_process_acqe(dev, cqe); else if (cqe->valid_ae_cmpl_cons & OCRDMA_MCQE_CMPL_MASK) ocrdma_process_mcqe(dev, cqe); - memset(cqe, 0, sizeof(struct ocrdma_mcqe)); + memset(cqe, 0, sizeof(*cqe)); ocrdma_mcq_inc_tail(dev); } ocrdma_ring_cq_db(dev, dev->mq.cq.id, true, false, cqe_popped); @@ -1302,7 +1302,7 @@ int ocrdma_mbx_rdma_stats(struct ocrdma_dev *dev, bool reset) mqe->u.nonemb_req.sge[0].len = dev->stats_mem.size; /* Cache the old stats */ - memcpy(old_stats, req, sizeof(struct ocrdma_rdma_stats_resp)); + memcpy(old_stats, req, sizeof(*old_stats)); memset(req, 0, dev->stats_mem.size); ocrdma_init_mch((struct ocrdma_mbx_hdr *)req, @@ -1315,7 +1315,7 @@ int ocrdma_mbx_rdma_stats(struct ocrdma_dev *dev, bool reset) status = ocrdma_nonemb_mbx_cmd(dev, mqe, dev->stats_mem.va); if (status) /* Copy from cache, if mbox fails */ - memcpy(req, old_stats, sizeof(struct ocrdma_rdma_stats_resp)); + memcpy(req, old_stats, sizeof(*old_stats)); else ocrdma_le32_to_cpu(req, dev->stats_mem.size); @@ -1331,7 +1331,7 @@ static int ocrdma_mbx_get_ctrl_attribs(struct ocrdma_dev *dev) struct ocrdma_get_ctrl_attribs_rsp *ctrl_attr_rsp; struct mgmt_hba_attribs *hba_attribs; - mqe = kzalloc(sizeof(struct ocrdma_mqe), GFP_KERNEL); + mqe = kzalloc(sizeof(*mqe), GFP_KERNEL); if (!mqe) return status; @@ -1595,8 +1595,7 @@ void ocrdma_alloc_pd_pool(struct ocrdma_dev *dev) { int status; - dev->pd_mgr = kzalloc(sizeof(struct ocrdma_pd_resource_mgr), - GFP_KERNEL); + dev->pd_mgr = kzalloc(sizeof(*dev->pd_mgr), GFP_KERNEL); if (!dev->pd_mgr) return; @@ -2487,7 +2486,7 @@ int ocrdma_mbx_query_qp(struct ocrdma_dev *dev, struct ocrdma_qp *qp, if (status) goto mbx_err; rsp = (struct ocrdma_query_qp_rsp *)cmd; - memcpy(param, &rsp->params, sizeof(struct ocrdma_qp_params)); + memcpy(param, &rsp->params, sizeof(*param)); mbx_err: kfree(cmd); return status; @@ -2901,9 +2900,8 @@ static int ocrdma_mbx_get_dcbx_config(struct ocrdma_dev *dev, u32 ptype, struct pci_dev *pdev = dev->nic_info.pdev; struct ocrdma_mqe_sge *mqe_sge = cmd.u.nonemb_req.sge; - memset(&cmd, 0, sizeof(struct ocrdma_mqe)); - cmd.hdr.pyld_len = max_t (u32, sizeof(struct ocrdma_get_dcbx_cfg_rsp), - sizeof(struct ocrdma_get_dcbx_cfg_req)); + memset(&cmd, 0, sizeof(cmd)); + cmd.hdr.pyld_len = max_t(u32, sizeof(*rsp), sizeof(*req)); req = dma_alloc_coherent(&pdev->dev, cmd.hdr.pyld_len, &pa, GFP_KERNEL); if (!req) { status = -ENOMEM; @@ -2915,8 +2913,7 @@ static int ocrdma_mbx_get_dcbx_config(struct ocrdma_dev *dev, u32 ptype, mqe_sge->pa_lo = (u32) (pa & 0xFFFFFFFFUL); mqe_sge->pa_hi = (u32) upper_32_bits(pa); mqe_sge->len = cmd.hdr.pyld_len; - - memset(req, 0, sizeof(struct ocrdma_get_dcbx_cfg_req)); + memset(req, 0, sizeof(*req)); ocrdma_init_mch(&req->hdr, OCRDMA_CMD_GET_DCBX_CONFIG, OCRDMA_SUBSYS_DCBX, cmd.hdr.pyld_len); req->param_type = ptype; @@ -2926,9 +2923,8 @@ static int ocrdma_mbx_get_dcbx_config(struct ocrdma_dev *dev, u32 ptype, goto mbx_err; rsp = (struct ocrdma_get_dcbx_cfg_rsp *)req; - ocrdma_le32_to_cpu(rsp, sizeof(struct ocrdma_get_dcbx_cfg_rsp)); - memcpy(dcbxcfg, &rsp->cfg, sizeof(struct ocrdma_dcbx_cfg)); - + ocrdma_le32_to_cpu(rsp, sizeof(*rsp)); + memcpy(dcbxcfg, &rsp->cfg, sizeof(*dcbxcfg)); mbx_err: dma_free_coherent(&pdev->dev, cmd.hdr.pyld_len, req, pa); mem_err: diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c index 91705b10f269..e2aa67d6cbb8 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c @@ -303,7 +303,7 @@ static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info) u8 lstate = 0; struct ocrdma_dev *dev; - dev = (struct ocrdma_dev *)ib_alloc_device(sizeof(struct ocrdma_dev)); + dev = (struct ocrdma_dev *)ib_alloc_device(sizeof(*dev)); if (!dev) { pr_err("Unable to allocate ib device\n"); return NULL; diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c index 146601c97158..f12d1d458f28 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c @@ -1914,7 +1914,7 @@ struct ib_srq *ocrdma_create_srq(struct ib_pd *ibpd, if (srq->idx_bit_fields == NULL) goto arm_err; memset(srq->idx_bit_fields, 0xff, - srq->bit_fields_len * sizeof(u32)); + srq->bit_fields_len * sizeof(*srq->idx_bit_fields)); } if (init_attr->attr.srq_limit) { @@ -3029,7 +3029,7 @@ struct ib_mr *ocrdma_alloc_mr(struct ib_pd *ibpd, if (!mr) return ERR_PTR(-ENOMEM); - mr->pages = kcalloc(max_num_sg, sizeof(u64), GFP_KERNEL); + mr->pages = kcalloc(max_num_sg, sizeof(*mr->pages), GFP_KERNEL); if (!mr->pages) { status = -ENOMEM; goto pl_err;