2018-11-28 08:07:23

by Wen Yang

[permalink] [raw]
Subject: [PATCH] scsi: megaraid_sas: NULL check before some freeing functions is not needed

dma_pool_destroy(NULL) is safe, so removes NULL check before freeing
the mem. This patch also fix the ifnullfree.cocci warnings.

Signed-off-by: Wen Yang <[email protected]>
CC: Julia Lawall <[email protected]>
CC: Kashyap Desai <[email protected]>
CC: Sumit Saxena <[email protected]>
CC: Shivasharan S <[email protected]>
CC: [email protected]
---
drivers/scsi/megaraid/megaraid_sas_fusion.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index f74b5ea24f0f..aa477f09a7a5 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -807,10 +807,8 @@ megasas_free_rdpq_fusion(struct megasas_instance *instance) {

}

- if (fusion->reply_frames_desc_pool)
- dma_pool_destroy(fusion->reply_frames_desc_pool);
- if (fusion->reply_frames_desc_pool_align)
- dma_pool_destroy(fusion->reply_frames_desc_pool_align);
+ dma_pool_destroy(fusion->reply_frames_desc_pool);
+ dma_pool_destroy(fusion->reply_frames_desc_pool_align);

if (fusion->rdpq_virt)
dma_free_coherent(&instance->pdev->dev,
@@ -830,8 +828,7 @@ megasas_free_reply_fusion(struct megasas_instance *instance) {
fusion->reply_frames_desc[0],
fusion->reply_frames_desc_phys[0]);

- if (fusion->reply_frames_desc_pool)
- dma_pool_destroy(fusion->reply_frames_desc_pool);
+ dma_pool_destroy(fusion->reply_frames_desc_pool);

}

@@ -1627,8 +1624,7 @@ static inline void megasas_free_ioc_init_cmd(struct megasas_instance *instance)
fusion->ioc_init_cmd->frame,
fusion->ioc_init_cmd->frame_phys_addr);

- if (fusion->ioc_init_cmd)
- kfree(fusion->ioc_init_cmd);
+ kfree(fusion->ioc_init_cmd);
}

/**
--
2.19.1



2018-12-03 06:44:23

by Sumit Saxena

[permalink] [raw]
Subject: Re: [PATCH] scsi: megaraid_sas: NULL check before some freeing functions is not needed

On Wed, Nov 28, 2018 at 1:36 PM Wen Yang <[email protected]> wrote:
>
> dma_pool_destroy(NULL) is safe, so removes NULL check before freeing
> the mem. This patch also fix the ifnullfree.cocci warnings.
>
> Signed-off-by: Wen Yang <[email protected]>

Acked-by: Sumit Saxena <[email protected]>

> CC: Julia Lawall <[email protected]>
> CC: Kashyap Desai <[email protected]>
> CC: Sumit Saxena <[email protected]>
> CC: Shivasharan S <[email protected]>
> CC: [email protected]
> ---
> drivers/scsi/megaraid/megaraid_sas_fusion.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> index f74b5ea24f0f..aa477f09a7a5 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> @@ -807,10 +807,8 @@ megasas_free_rdpq_fusion(struct megasas_instance *instance) {
>
> }
>
> - if (fusion->reply_frames_desc_pool)
> - dma_pool_destroy(fusion->reply_frames_desc_pool);
> - if (fusion->reply_frames_desc_pool_align)
> - dma_pool_destroy(fusion->reply_frames_desc_pool_align);
> + dma_pool_destroy(fusion->reply_frames_desc_pool);
> + dma_pool_destroy(fusion->reply_frames_desc_pool_align);
>
> if (fusion->rdpq_virt)
> dma_free_coherent(&instance->pdev->dev,
> @@ -830,8 +828,7 @@ megasas_free_reply_fusion(struct megasas_instance *instance) {
> fusion->reply_frames_desc[0],
> fusion->reply_frames_desc_phys[0]);
>
> - if (fusion->reply_frames_desc_pool)
> - dma_pool_destroy(fusion->reply_frames_desc_pool);
> + dma_pool_destroy(fusion->reply_frames_desc_pool);
>
> }
>
> @@ -1627,8 +1624,7 @@ static inline void megasas_free_ioc_init_cmd(struct megasas_instance *instance)
> fusion->ioc_init_cmd->frame,
> fusion->ioc_init_cmd->frame_phys_addr);
>
> - if (fusion->ioc_init_cmd)
> - kfree(fusion->ioc_init_cmd);
> + kfree(fusion->ioc_init_cmd);
> }
>
> /**
> --
> 2.19.1
>