diff mbox

[03/26] IB/ocrdma: Improve size determinations in ocrdma_mbx_get_dcbx_config()

Message ID 907034da-34ae-9e5b-6e56-3a2feb4924da@users.sourceforge.net (mailing list archive)
State Changes Requested
Headers show

Commit Message

SF Markus Elfring March 8, 2017, 12:45 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Yuval Shaia March 8, 2017, 1:54 p.m. UTC | #1
On Wed, Mar 08, 2017 at 01:45:43PM +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
> ---
>  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:

Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>

> -- 
> 2.12.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Devesh Sharma March 8, 2017, 2:46 p.m. UTC | #2
Acked-By: Devesh Sharma <devesh.sharma@broadcom.com>

On Wed, Mar 8, 2017 at 7:24 PM, Yuval Shaia <yuval.shaia@oracle.com> wrote:
> On Wed, Mar 08, 2017 at 01:45:43PM +0100, SF Markus Elfring wrote:
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> 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 <elfring@users.sourceforge.net>
>> ---
>>  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:
>
> Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com>
>
>> --
>> 2.12.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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: