From patchwork Wed Mar 8 12:45:43 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: 9610989 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 041796046A for ; Wed, 8 Mar 2017 12:48:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA849284F3 for ; Wed, 8 Mar 2017 12:48:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD27C2850D; Wed, 8 Mar 2017 12:48:37 +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 920D0284F3 for ; Wed, 8 Mar 2017 12:48:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753066AbdCHMse (ORCPT ); Wed, 8 Mar 2017 07:48:34 -0500 Received: from mout.web.de ([212.227.17.12]:52513 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752758AbdCHMsc (ORCPT ); Wed, 8 Mar 2017 07:48:32 -0500 Received: from [192.168.1.2] ([92.228.144.238]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0Lk8ko-1c9VGW11Mw-00cDi0; Wed, 08 Mar 2017 13:45:50 +0100 Subject: [PATCH 03/26] IB/ocrdma: Improve size determinations in ocrdma_mbx_get_dcbx_config() To: linux-rdma@vger.kernel.org, Devesh Sharma , Doug Ledford , Hal Rosenstock , Sean Hefty , Selvin Xavier References: Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: <907034da-34ae-9e5b-6e56-3a2feb4924da@users.sourceforge.net> Date: Wed, 8 Mar 2017 13:45:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: X-Provags-ID: V03:K0:r3lMRyCcAuIoHqB4QPnUpcUgXZ/Zpop7a74z7Xuog9+6GGPrnCI Vodq2RBtkK/55mBjmoNs/rZVyG0DYWTo6mvYVuv2Z5e8OP2L8Tu/cJsWTWjKsF/drMAuW+M xGsb49w+8OgZ2GwJ47h9ruUqKN219fH6YHNezUKRu5RItxcRUBwPvrFBuyUOy4CVHPY7tpQ 3d/AVtwsrU/uhEIfy7elQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:WHU8uHlmCUY=:n2A1LKrBnAREOR5Gt4zCpR u0dH9vwCaEJcufAseu8Hqah6yORcXyNddpmOb5mF0RFw2q6ZEewDDILehgZeN3u0DpWZNcRVo /QNnqH+xCZDi1UdHhVKxzXgZqFZ2DFMf/xx/EiKtMmdVJgqUmRoXRLGo/8ViAEVcw7UQP6GV1 YqZeMfgoY718LyNJx73exGV8MflkZYOW3E8SitecpbwUr5SuG0nUmYi/HKvnDkRSwUb41ZsFF HHIOPs0zkOri7cnhM4lK+b2w1dwAQlQF3sEj/AvK/rUPPrsnhmy5NjyloNKd+Osx0wzdRw7iN hh0mEisD7fnUoeasbt2lmyFwBWPuK3knGdfQOCN9amLAayE+jd4j/H169M8sdZdd9+5V+dOfS rqSap+Owu9pRYBcgdGwN4OBA+stYsUIJ7hBRGjqMuTUiY0SF/Y+jwF2mQAh1z/00GY38r9EXO SQ+SeLCMwB3X73tid/r2b1je/5Q+PhEXpUE3bY3Pk7BrWmRwei15N8mS9C+eB9IioQGxvra0E c3lmBPOsx5+J3aIPq15XlSYWngW7UpiU/0BYNm8OrgagUxC2TOE9REohW7BZLVWeS2qR04v23 G2iekKJQBB2Ps3iYViXiWY9StbDvSyajt6M4WkdNNMw0Ta7NtVLgAd6nvFvLhg6ruGo6JZeg+ ReKExbkOAl25TxNYdO+cNq2sEZQdlXUyF7cPMyrBLDnXVZS9sI6TOzPJGRepXCaEes6Oa86ZR qGtz/T+kQI4vX7tehU1WGzXHk5qZVYgMV5eYV4ekECGqvWjvV4wYpdeOwQMOV9/u9prk5anm4 qBPcvC7 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: Tue, 7 Mar 2017 19:09:20 +0100 Replace the specification of data structures by references for variables 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 Reviewed-by: Yuval Shaia Acked-By: Devesh Sharma --- drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c index d5a3127b6df8..85bebb887c5c 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c @@ -2901,9 +2901,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 +2914,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 +2924,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: