NULL check before some freeing functions is not needed.
Found by coccinelle spatch "free/ifnullfree.cocci"
Run against version v4.20-rc4
P.S. If you find this email unwanted, set up a procmail rule junking on
the header:
X-Patch: Cocci
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/csiostor/csio_init.c b/drivers/scsi/csiostor/csio_init.c
--- a/drivers/scsi/csiostor/csio_init.c
+++ b/drivers/scsi/csiostor/csio_init.c
@@ -157,8 +157,7 @@ csio_dfs_create(struct csio_hw *hw)
static int
csio_dfs_destroy(struct csio_hw *hw)
{
- if (hw->debugfs_root)
- debugfs_remove_recursive(hw->debugfs_root);
+ debugfs_remove_recursive(hw->debugfs_root);
return 0;
}
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3s_hv_nested.c
--- a/arch/powerpc/kvm/book3s_hv_nested.c
+++ b/arch/powerpc/kvm/book3s_hv_nested.c
@@ -1252,8 +1252,7 @@ static long int __kvmhv_nested_page_faul
rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn];
ret = kvmppc_create_pte(kvm, gp->shadow_pgtable, pte, n_gpa, level,
mmu_seq, gp->shadow_lpid, rmapp, &n_rmap);
- if (n_rmap)
- kfree(n_rmap);
+ kfree(n_rmap);
if (ret == -EAGAIN)
ret = RESUME_GUEST; /* Let the guest try again */
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -584,8 +584,7 @@ static void asd_destroy_ha_caches(struct
if (asd_ha->hw_prof.scb_ext)
asd_free_coherent(asd_ha, asd_ha->hw_prof.scb_ext);
- if (asd_ha->hw_prof.ddb_bitmap)
- kfree(asd_ha->hw_prof.ddb_bitmap);
+ kfree(asd_ha->hw_prof.ddb_bitmap);
asd_ha->hw_prof.ddb_bitmap = NULL;
for (i = 0; i < ASD_MAX_PHYS; i++) {
@@ -660,12 +659,10 @@ Err:
static void asd_destroy_global_caches(void)
{
- if (asd_dma_token_cache)
- kmem_cache_destroy(asd_dma_token_cache);
+ kmem_cache_destroy(asd_dma_token_cache);
asd_dma_token_cache = NULL;
- if (asd_ascb_cache)
- kmem_cache_destroy(asd_ascb_cache);
+ kmem_cache_destroy(asd_ascb_cache);
asd_ascb_cache = NULL;
}
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -4191,12 +4191,10 @@ fail_free_nvram:
kfree(ha->nvram);
ha->nvram = NULL;
fail_free_ctx_mempool:
- if (ha->ctx_mempool)
- mempool_destroy(ha->ctx_mempool);
+ mempool_destroy(ha->ctx_mempool);
ha->ctx_mempool = NULL;
fail_free_srb_mempool:
- if (ha->srb_mempool)
- mempool_destroy(ha->srb_mempool);
+ mempool_destroy(ha->srb_mempool);
ha->srb_mempool = NULL;
fail_free_gid_list:
dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
@@ -4498,8 +4496,7 @@ qla2x00_mem_free(struct qla_hw_data *ha)
dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
ha->mctp_dump_dma);
- if (ha->srb_mempool)
- mempool_destroy(ha->srb_mempool);
+ mempool_destroy(ha->srb_mempool);
if (ha->dcbx_tlv)
dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
@@ -4531,8 +4528,7 @@ qla2x00_mem_free(struct qla_hw_data *ha)
if (ha->async_pd)
dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
- if (ha->s_dma_pool)
- dma_pool_destroy(ha->s_dma_pool);
+ dma_pool_destroy(ha->s_dma_pool);
if (ha->gid_list)
dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
@@ -4553,14 +4549,11 @@ qla2x00_mem_free(struct qla_hw_data *ha)
}
}
- if (ha->dl_dma_pool)
- dma_pool_destroy(ha->dl_dma_pool);
+ dma_pool_destroy(ha->dl_dma_pool);
- if (ha->fcp_cmnd_dma_pool)
- dma_pool_destroy(ha->fcp_cmnd_dma_pool);
+ dma_pool_destroy(ha->fcp_cmnd_dma_pool);
- if (ha->ctx_mempool)
- mempool_destroy(ha->ctx_mempool);
+ mempool_destroy(ha->ctx_mempool);
qlt_mem_free(ha);
@@ -7106,8 +7099,7 @@ qla2x00_module_exit(void)
qla2x00_release_firmware();
kmem_cache_destroy(srb_cachep);
qlt_exit();
- if (ctx_cachep)
- kmem_cache_destroy(ctx_cachep);
+ kmem_cache_destroy(ctx_cachep);
fc_release_transport(qla2xxx_transport_template);
fc_release_transport(qla2xxx_transport_vport_template);
}
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -9537,8 +9537,7 @@ static void ipr_free_cmd_blks(struct ipr
}
}
- if (ioa_cfg->ipr_cmd_pool)
- dma_pool_destroy(ioa_cfg->ipr_cmd_pool);
+ dma_pool_destroy(ioa_cfg->ipr_cmd_pool);
kfree(ioa_cfg->ipr_cmnd_list);
kfree(ioa_cfg->ipr_cmnd_list_dma);
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -4160,20 +4160,17 @@ static void qla4xxx_mem_free(struct scsi
ha->fw_dump_size = 0;
/* Free srb pool. */
- if (ha->srb_mempool)
- mempool_destroy(ha->srb_mempool);
+ mempool_destroy(ha->srb_mempool);
ha->srb_mempool = NULL;
- if (ha->chap_dma_pool)
- dma_pool_destroy(ha->chap_dma_pool);
+ dma_pool_destroy(ha->chap_dma_pool);
if (ha->chap_list)
vfree(ha->chap_list);
ha->chap_list = NULL;
- if (ha->fw_ddb_dma_pool)
- dma_pool_destroy(ha->fw_ddb_dma_pool);
+ dma_pool_destroy(ha->fw_ddb_dma_pool);
/* release io space registers */
if (is_qla8022(ha)) {
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/power/avs/smartreflex.c b/drivers/power/avs/smartreflex.c
--- a/drivers/power/avs/smartreflex.c
+++ b/drivers/power/avs/smartreflex.c
@@ -1010,8 +1010,7 @@ static int omap_sr_remove(struct platfor
if (sr_info->autocomp_active)
sr_stop_vddautocomp(sr_info);
- if (sr_info->dbg_dir)
- debugfs_remove_recursive(sr_info->dbg_dir);
+ debugfs_remove_recursive(sr_info->dbg_dir);
pm_runtime_disable(&pdev->dev);
list_del(&sr_info->node);
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -248,20 +248,13 @@ static int zfcp_allocate_low_mem_buffers
static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
{
- if (adapter->pool.erp_req)
- mempool_destroy(adapter->pool.erp_req);
- if (adapter->pool.scsi_req)
- mempool_destroy(adapter->pool.scsi_req);
- if (adapter->pool.scsi_abort)
- mempool_destroy(adapter->pool.scsi_abort);
- if (adapter->pool.qtcb_pool)
- mempool_destroy(adapter->pool.qtcb_pool);
- if (adapter->pool.status_read_req)
- mempool_destroy(adapter->pool.status_read_req);
- if (adapter->pool.sr_data)
- mempool_destroy(adapter->pool.sr_data);
- if (adapter->pool.gid_pn)
- mempool_destroy(adapter->pool.gid_pn);
+ mempool_destroy(adapter->pool.erp_req);
+ mempool_destroy(adapter->pool.scsi_req);
+ mempool_destroy(adapter->pool.scsi_abort);
+ mempool_destroy(adapter->pool.qtcb_pool);
+ mempool_destroy(adapter->pool.status_read_req);
+ mempool_destroy(adapter->pool.sr_data);
+ mempool_destroy(adapter->pool.gid_pn);
}
/**
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
--- a/drivers/scsi/qedf/qedf_main.c
+++ b/drivers/scsi/qedf/qedf_main.c
@@ -2935,8 +2935,7 @@ static void qedf_free_fcoe_pf_param(stru
qedf_free_global_queues(qedf);
- if (qedf->global_queues)
- kfree(qedf->global_queues);
+ kfree(qedf->global_queues);
}
/*
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -4213,8 +4213,7 @@ _base_release_memory_pools(struct MPT3SA
ioc->pcie_sg_lookup[i].pcie_sgl,
ioc->pcie_sg_lookup[i].pcie_sgl_dma);
}
- if (ioc->pcie_sgl_dma_pool)
- dma_pool_destroy(ioc->pcie_sgl_dma_pool);
+ dma_pool_destroy(ioc->pcie_sgl_dma_pool);
}
if (ioc->config_page) {
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -3673,8 +3673,7 @@ ahd_free_tstate(struct ahd_softc *ahd, u
return;
tstate = ahd->enabled_targets[scsi_id];
- if (tstate != NULL)
- kfree(tstate);
+ kfree(tstate);
ahd->enabled_targets[scsi_id] = NULL;
}
#endif
@@ -6136,8 +6135,7 @@ ahd_set_unit(struct ahd_softc *ahd, int
void
ahd_set_name(struct ahd_softc *ahd, char *name)
{
- if (ahd->name != NULL)
- kfree(ahd->name);
+ kfree(ahd->name);
ahd->name = name;
}
@@ -6198,12 +6196,9 @@ ahd_free(struct ahd_softc *ahd)
kfree(ahd->black_hole);
}
#endif
- if (ahd->name != NULL)
- kfree(ahd->name);
- if (ahd->seep_config != NULL)
- kfree(ahd->seep_config);
- if (ahd->saved_stack != NULL)
- kfree(ahd->saved_stack);
+ kfree(ahd->name);
+ kfree(ahd->seep_config);
+ kfree(ahd->saved_stack);
#ifndef __FreeBSD__
kfree(ahd);
#endif
diff -u -p a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -2193,8 +2193,7 @@ ahc_free_tstate(struct ahc_softc *ahc, u
if (channel == 'B')
scsi_id += 8;
tstate = ahc->enabled_targets[scsi_id];
- if (tstate != NULL)
- kfree(tstate);
+ kfree(tstate);
ahc->enabled_targets[scsi_id] = NULL;
}
#endif
@@ -4474,8 +4473,7 @@ ahc_set_unit(struct ahc_softc *ahc, int
void
ahc_set_name(struct ahc_softc *ahc, char *name)
{
- if (ahc->name != NULL)
- kfree(ahc->name);
+ kfree(ahc->name);
ahc->name = name;
}
@@ -4536,10 +4534,8 @@ ahc_free(struct ahc_softc *ahc)
kfree(ahc->black_hole);
}
#endif
- if (ahc->name != NULL)
- kfree(ahc->name);
- if (ahc->seep_config != NULL)
- kfree(ahc->seep_config);
+ kfree(ahc->name);
+ kfree(ahc->seep_config);
#ifndef __FreeBSD__
kfree(ahc);
#endif
@@ -4944,8 +4940,7 @@ ahc_fini_scbdata(struct ahc_softc *ahc)
case 0:
break;
}
- if (scb_data->scbarray != NULL)
- kfree(scb_data->scbarray);
+ kfree(scb_data->scbarray);
}
static void
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -1276,8 +1276,7 @@ lpfc_bsg_hba_set_event(struct bsg_job *j
return 0; /* call job done later */
job_error:
- if (dd_data != NULL)
- kfree(dd_data);
+ kfree(dd_data);
job->dd_data = NULL;
return rc;
diff -u -p a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -12450,8 +12450,7 @@ lpfc_sli4_oas_verify(struct lpfc_hba *ph
phba->cfg_fof = 1;
} else {
phba->cfg_fof = 0;
- if (phba->device_data_mem_pool)
- mempool_destroy(phba->device_data_mem_pool);
+ mempool_destroy(phba->device_data_mem_pool);
phba->device_data_mem_pool = NULL;
}
diff -u -p a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -248,25 +248,19 @@ lpfc_mem_free(struct lpfc_hba *phba)
/* Free HBQ pools */
lpfc_sli_hbqbuf_free_all(phba);
- if (phba->lpfc_nvmet_drb_pool)
- dma_pool_destroy(phba->lpfc_nvmet_drb_pool);
+ dma_pool_destroy(phba->lpfc_nvmet_drb_pool);
phba->lpfc_nvmet_drb_pool = NULL;
- if (phba->lpfc_drb_pool)
- dma_pool_destroy(phba->lpfc_drb_pool);
+ dma_pool_destroy(phba->lpfc_drb_pool);
phba->lpfc_drb_pool = NULL;
- if (phba->lpfc_hrb_pool)
- dma_pool_destroy(phba->lpfc_hrb_pool);
+ dma_pool_destroy(phba->lpfc_hrb_pool);
phba->lpfc_hrb_pool = NULL;
- if (phba->txrdy_payload_pool)
- dma_pool_destroy(phba->txrdy_payload_pool);
+ dma_pool_destroy(phba->txrdy_payload_pool);
phba->txrdy_payload_pool = NULL;
- if (phba->lpfc_hbq_pool)
- dma_pool_destroy(phba->lpfc_hbq_pool);
+ dma_pool_destroy(phba->lpfc_hbq_pool);
phba->lpfc_hbq_pool = NULL;
- if (phba->rrq_pool)
- mempool_destroy(phba->rrq_pool);
+ mempool_destroy(phba->rrq_pool);
phba->rrq_pool = NULL;
/* Free NLP memory pool */
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
@@ -816,6 +816,5 @@ out:
void amdgpu_acpi_fini(struct amdgpu_device *adev)
{
unregister_acpi_notifier(&adev->acpi_nb);
- if (adev->atif)
- kfree(adev->atif);
+ kfree(adev->atif);
}
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -1243,8 +1243,7 @@ megaraid_mbox_teardown_dma_pools(adapter
dma_pool_free(raid_dev->sg_pool_handle, sg_pci_blk[i].vaddr,
sg_pci_blk[i].dma_addr);
}
- if (raid_dev->sg_pool_handle)
- dma_pool_destroy(raid_dev->sg_pool_handle);
+ dma_pool_destroy(raid_dev->sg_pool_handle);
epthru_pci_blk = raid_dev->epthru_pool;
@@ -1252,8 +1251,7 @@ megaraid_mbox_teardown_dma_pools(adapter
dma_pool_free(raid_dev->epthru_pool_handle,
epthru_pci_blk[i].vaddr, epthru_pci_blk[i].dma_addr);
}
- if (raid_dev->epthru_pool_handle)
- dma_pool_destroy(raid_dev->epthru_pool_handle);
+ dma_pool_destroy(raid_dev->epthru_pool_handle);
mbox_pci_blk = raid_dev->mbox_pool;
@@ -1261,8 +1259,7 @@ megaraid_mbox_teardown_dma_pools(adapter
dma_pool_free(raid_dev->mbox_pool_handle,
mbox_pci_blk[i].vaddr, mbox_pci_blk[i].dma_addr);
}
- if (raid_dev->mbox_pool_handle)
- dma_pool_destroy(raid_dev->mbox_pool_handle);
+ dma_pool_destroy(raid_dev->mbox_pool_handle);
return;
}
diff -u -p a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -1017,8 +1017,7 @@ memalloc_error:
kfree(adapter->kioc_list);
kfree(adapter->mbox_list);
- if (adapter->pthru_dma_pool)
- dma_pool_destroy(adapter->pthru_dma_pool);
+ dma_pool_destroy(adapter->pthru_dma_pool);
kfree(adapter);
diff -u -p a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
--- 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_
}
- 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
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
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);
}
/**
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -681,8 +681,7 @@ static int new_lockspace(const char *nam
out_lkbidr:
idr_destroy(&ls->ls_lkbidr);
for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) {
- if (ls->ls_remove_names[i])
- kfree(ls->ls_remove_names[i]);
+ kfree(ls->ls_remove_names[i]);
}
out_rsbtbl:
vfree(ls->ls_rsbtbl);
NULL check before some freeing functions is not needed.
Signed-off-by: Thomas Meyer <[email protected]>
---
diff -u -p a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c
--- a/drivers/platform/x86/intel_ips.c
+++ b/drivers/platform/x86/intel_ips.c
@@ -1300,8 +1300,7 @@ static const struct file_operations ips_
static void ips_debugfs_cleanup(struct ips_driver *ips)
{
- if (ips->debug_root)
- debugfs_remove_recursive(ips->debug_root);
+ debugfs_remove_recursive(ips->debug_root);
return;
}
On Sun, 2018-12-02 at 21:52 +0100, Thomas Meyer wrote:
> NULL check before some freeing functions is not needed.
Technically true, however I think a comment should be added then to
make it clearer to someone reading the code why this is ok.
See below.
Suraj.
>
> Signed-off-by: Thomas Meyer <[email protected]>
> ---
>
> diff -u -p a/arch/powerpc/kvm/book3s_hv_nested.c
> b/arch/powerpc/kvm/book3s_hv_nested.c
> --- a/arch/powerpc/kvm/book3s_hv_nested.c
> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
> @@ -1252,8 +1252,7 @@ static long int __kvmhv_nested_page_faul
> rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn];
> ret = kvmppc_create_pte(kvm, gp->shadow_pgtable, pte, n_gpa,
> level,
> mmu_seq, gp->shadow_lpid, rmapp,
> &n_rmap);
> - if (n_rmap)
> - kfree(n_rmap);
> + kfree(n_rmap);
e.g.
/* n_rmap set to NULL in kvmppc_create_pte if reference preserved */
> if (ret == -EAGAIN)
> ret = RESUME_GUEST; /* Let the guest try
> again */
>
> -----Original Message-----
> From: Thomas Meyer <[email protected]>
> Sent: Monday, December 3, 2018 2:22 AM
> To: Dept-Eng QLogic Storage Upstream <QLogic-Storage-
> [email protected]>; [email protected];
> [email protected]; [email protected]; linux-
> [email protected]
> Subject: [PATCH] scsi: qla4xxx: NULL check before some freeing functions is not
> needed.
>
> External Email
>
> NULL check before some freeing functions is not needed.
>
> Signed-off-by: Thomas Meyer <[email protected]>
> ---
>
> diff -u -p a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
> --- a/drivers/scsi/qla4xxx/ql4_os.c
> +++ b/drivers/scsi/qla4xxx/ql4_os.c
> @@ -4160,20 +4160,17 @@ static void qla4xxx_mem_free(struct scsi
> ha->fw_dump_size = 0;
>
> /* Free srb pool. */
> - if (ha->srb_mempool)
> - mempool_destroy(ha->srb_mempool);
> + mempool_destroy(ha->srb_mempool);
>
> ha->srb_mempool = NULL;
>
> - if (ha->chap_dma_pool)
> - dma_pool_destroy(ha->chap_dma_pool);
> + dma_pool_destroy(ha->chap_dma_pool);
>
> if (ha->chap_list)
> vfree(ha->chap_list);
> ha->chap_list = NULL;
>
> - if (ha->fw_ddb_dma_pool)
> - dma_pool_destroy(ha->fw_ddb_dma_pool);
> + dma_pool_destroy(ha->fw_ddb_dma_pool);
>
> /* release io space registers */
> if (is_qla8022(ha)) {
Thanks
Acked-by: Manish Rangankar <[email protected]>
> -----Original Message-----
> From: Thomas Meyer <[email protected]>
> Sent: Monday, December 3, 2018 2:22 AM
> To: Dept-Eng QLogic Storage Upstream <QLogic-Storage-
> [email protected]>; [email protected];
> [email protected]; [email protected]; linux-
> [email protected]
> Subject: [PATCH] scsi: qedf: NULL check before some freeing functions is not
> needed.
>
> External Email
>
> NULL check before some freeing functions is not needed.
>
> Signed-off-by: Thomas Meyer <[email protected]>
> ---
>
> diff -u -p a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c
> --- a/drivers/scsi/qedf/qedf_main.c
> +++ b/drivers/scsi/qedf/qedf_main.c
> @@ -2935,8 +2935,7 @@ static void qedf_free_fcoe_pf_param(stru
>
> qedf_free_global_queues(qedf);
>
> - if (qedf->global_queues)
> - kfree(qedf->global_queues);
> + kfree(qedf->global_queues);
> }
>
> /*
Thanks
Acked-by: Manish Rangankar <[email protected]>
On Mon, Dec 3, 2018 at 2:25 AM Thomas Meyer <[email protected]> wrote:
>
> NULL check before some freeing functions is not needed.
>
> Signed-off-by: Thomas Meyer <[email protected]>
Acked-by: Sumit Saxena <[email protected]>
> ---
>
> diff -u -p a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
> --- a/drivers/scsi/megaraid/megaraid_mbox.c
> +++ b/drivers/scsi/megaraid/megaraid_mbox.c
> @@ -1243,8 +1243,7 @@ megaraid_mbox_teardown_dma_pools(adapter
> dma_pool_free(raid_dev->sg_pool_handle, sg_pci_blk[i].vaddr,
> sg_pci_blk[i].dma_addr);
> }
> - if (raid_dev->sg_pool_handle)
> - dma_pool_destroy(raid_dev->sg_pool_handle);
> + dma_pool_destroy(raid_dev->sg_pool_handle);
>
>
> epthru_pci_blk = raid_dev->epthru_pool;
> @@ -1252,8 +1251,7 @@ megaraid_mbox_teardown_dma_pools(adapter
> dma_pool_free(raid_dev->epthru_pool_handle,
> epthru_pci_blk[i].vaddr, epthru_pci_blk[i].dma_addr);
> }
> - if (raid_dev->epthru_pool_handle)
> - dma_pool_destroy(raid_dev->epthru_pool_handle);
> + dma_pool_destroy(raid_dev->epthru_pool_handle);
>
>
> mbox_pci_blk = raid_dev->mbox_pool;
> @@ -1261,8 +1259,7 @@ megaraid_mbox_teardown_dma_pools(adapter
> dma_pool_free(raid_dev->mbox_pool_handle,
> mbox_pci_blk[i].vaddr, mbox_pci_blk[i].dma_addr);
> }
> - if (raid_dev->mbox_pool_handle)
> - dma_pool_destroy(raid_dev->mbox_pool_handle);
> + dma_pool_destroy(raid_dev->mbox_pool_handle);
>
> return;
> }
> diff -u -p a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
> --- a/drivers/scsi/megaraid/megaraid_mm.c
> +++ b/drivers/scsi/megaraid/megaraid_mm.c
> @@ -1017,8 +1017,7 @@ memalloc_error:
> kfree(adapter->kioc_list);
> kfree(adapter->mbox_list);
>
> - if (adapter->pthru_dma_pool)
> - dma_pool_destroy(adapter->pthru_dma_pool);
> + dma_pool_destroy(adapter->pthru_dma_pool);
>
> kfree(adapter);
>
> diff -u -p a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
> --- 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_
>
> }
>
> - 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
> 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
> 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);
> }
>
> /**
>
>
Thanks, this was already submitted for v4.12 with
https://www.spinics.net/lists/linux-scsi/msg125190.html
based on
https://www.spinics.net/lists/linux-s390/msg21307.html
Also, previously seen in
https://www.spinics.net/lists/linux-s390/msg22035.html
On 12/02/2018 09:52 PM, Thomas Meyer wrote:
> NULL check before some freeing functions is not needed.
>
> Signed-off-by: Thomas Meyer <[email protected]>
> ---
>
> diff -u -p a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
> --- a/drivers/s390/scsi/zfcp_aux.c
> +++ b/drivers/s390/scsi/zfcp_aux.c
> @@ -248,20 +248,13 @@ static int zfcp_allocate_low_mem_buffers
>
> static void zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
> {
> - if (adapter->pool.erp_req)
> - mempool_destroy(adapter->pool.erp_req);
> - if (adapter->pool.scsi_req)
> - mempool_destroy(adapter->pool.scsi_req);
> - if (adapter->pool.scsi_abort)
> - mempool_destroy(adapter->pool.scsi_abort);
> - if (adapter->pool.qtcb_pool)
> - mempool_destroy(adapter->pool.qtcb_pool);
> - if (adapter->pool.status_read_req)
> - mempool_destroy(adapter->pool.status_read_req);
> - if (adapter->pool.sr_data)
> - mempool_destroy(adapter->pool.sr_data);
> - if (adapter->pool.gid_pn)
> - mempool_destroy(adapter->pool.gid_pn);
> + mempool_destroy(adapter->pool.erp_req);
> + mempool_destroy(adapter->pool.scsi_req);
> + mempool_destroy(adapter->pool.scsi_abort);
> + mempool_destroy(adapter->pool.qtcb_pool);
> + mempool_destroy(adapter->pool.status_read_req);
> + mempool_destroy(adapter->pool.sr_data);
> + mempool_destroy(adapter->pool.gid_pn);
> }
>
> /**
>
--
Mit freundlichen Gruessen / Kind regards
Steffen Maier
Linux on IBM Z Development
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
Am 02.12.18 um 21:52 schrieb Thomas Meyer:
> NULL check before some freeing functions is not needed.
>
> Signed-off-by: Thomas Meyer <[email protected]>
Reviewed-by: Christian König <[email protected]>
> ---
>
> diff -u -p a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
> @@ -816,6 +816,5 @@ out:
> void amdgpu_acpi_fini(struct amdgpu_device *adev)
> {
> unregister_acpi_notifier(&adev->acpi_nb);
> - if (adev->atif)
> - kfree(adev->atif);
> + kfree(adev->atif);
> }
> On Dec 2, 2018, at 12:52 PM, Thomas Meyer <[email protected]> wrote:
>
> External Email
>
> ----------------------------------------------------------------------
> External Email
>
> NULL check before some freeing functions is not needed.
>
> Signed-off-by: Thomas Meyer <[email protected]>
> ---
>
> diff -u -p a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
> --- a/drivers/scsi/qla2xxx/qla_os.c
> +++ b/drivers/scsi/qla2xxx/qla_os.c
> @@ -4191,12 +4191,10 @@ fail_free_nvram:
> kfree(ha->nvram);
> ha->nvram = NULL;
> fail_free_ctx_mempool:
> - if (ha->ctx_mempool)
> - mempool_destroy(ha->ctx_mempool);
> + mempool_destroy(ha->ctx_mempool);
> ha->ctx_mempool = NULL;
> fail_free_srb_mempool:
> - if (ha->srb_mempool)
> - mempool_destroy(ha->srb_mempool);
> + mempool_destroy(ha->srb_mempool);
> ha->srb_mempool = NULL;
> fail_free_gid_list:
> dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
> @@ -4498,8 +4496,7 @@ qla2x00_mem_free(struct qla_hw_data *ha)
> dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
> ha->mctp_dump_dma);
>
> - if (ha->srb_mempool)
> - mempool_destroy(ha->srb_mempool);
> + mempool_destroy(ha->srb_mempool);
>
> if (ha->dcbx_tlv)
> dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
> @@ -4531,8 +4528,7 @@ qla2x00_mem_free(struct qla_hw_data *ha)
> if (ha->async_pd)
> dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
>
> - if (ha->s_dma_pool)
> - dma_pool_destroy(ha->s_dma_pool);
> + dma_pool_destroy(ha->s_dma_pool);
>
> if (ha->gid_list)
> dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
> @@ -4553,14 +4549,11 @@ qla2x00_mem_free(struct qla_hw_data *ha)
> }
> }
>
> - if (ha->dl_dma_pool)
> - dma_pool_destroy(ha->dl_dma_pool);
> + dma_pool_destroy(ha->dl_dma_pool);
>
> - if (ha->fcp_cmnd_dma_pool)
> - dma_pool_destroy(ha->fcp_cmnd_dma_pool);
> + dma_pool_destroy(ha->fcp_cmnd_dma_pool);
>
> - if (ha->ctx_mempool)
> - mempool_destroy(ha->ctx_mempool);
> + mempool_destroy(ha->ctx_mempool);
>
> qlt_mem_free(ha);
>
> @@ -7106,8 +7099,7 @@ qla2x00_module_exit(void)
> qla2x00_release_firmware();
> kmem_cache_destroy(srb_cachep);
> qlt_exit();
> - if (ctx_cachep)
> - kmem_cache_destroy(ctx_cachep);
> + kmem_cache_destroy(ctx_cachep);
> fc_release_transport(qla2xxx_transport_template);
> fc_release_transport(qla2xxx_transport_vport_template);
> }
Looks good.
Acked-by: Himanshu Madhani <[email protected]>
Thanks,
- Himanshu
On Sun, Dec 2, 2018 at 10:55 PM Thomas Meyer <[email protected]> wrote:
>
> NULL check before some freeing functions is not needed.
Pushed to my review and testing queue, thanks!
>
> Signed-off-by: Thomas Meyer <[email protected]>
> ---
>
> diff -u -p a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c
> --- a/drivers/platform/x86/intel_ips.c
> +++ b/drivers/platform/x86/intel_ips.c
> @@ -1300,8 +1300,7 @@ static const struct file_operations ips_
>
> static void ips_debugfs_cleanup(struct ips_driver *ips)
> {
> - if (ips->debug_root)
> - debugfs_remove_recursive(ips->debug_root);
> + debugfs_remove_recursive(ips->debug_root);
> return;
> }
>
--
With Best Regards,
Andy Shevchenko
Thomas,
> NULL check before some freeing functions is not needed.
Applied to 4.21/scsi-queue.
--
Martin K. Petersen Oracle Linux Engineering
Thomas,
> NULL check before some freeing functions is not needed.
Applied to 4.21/scsi-queue, thanks.
--
Martin K. Petersen Oracle Linux Engineering
Thomas,
> NULL check before some freeing functions is not needed.
Applied to 4.21/scsi-queue.
--
Martin K. Petersen Oracle Linux Engineering
Thomas Meyer <[email protected]> writes:
> NULL check before some freeing functions is not needed.
>
> Signed-off-by: Thomas Meyer <[email protected]>
Reviewed-by: Kevin Hilman <[email protected]>
> ---
>
> diff -u -p a/drivers/power/avs/smartreflex.c b/drivers/power/avs/smartreflex.c
> --- a/drivers/power/avs/smartreflex.c
> +++ b/drivers/power/avs/smartreflex.c
> @@ -1010,8 +1010,7 @@ static int omap_sr_remove(struct platfor
>
> if (sr_info->autocomp_active)
> sr_stop_vddautocomp(sr_info);
> - if (sr_info->dbg_dir)
> - debugfs_remove_recursive(sr_info->dbg_dir);
> + debugfs_remove_recursive(sr_info->dbg_dir);
>
> pm_runtime_disable(&pdev->dev);
> list_del(&sr_info->node);
On Tuesday, December 11, 2018 7:53:05 PM CET Kevin Hilman wrote:
> Thomas Meyer <[email protected]> writes:
>
> > NULL check before some freeing functions is not needed.
> >
> > Signed-off-by: Thomas Meyer <[email protected]>
>
> Reviewed-by: Kevin Hilman <[email protected]>
>
> > ---
> >
> > diff -u -p a/drivers/power/avs/smartreflex.c b/drivers/power/avs/smartreflex.c
> > --- a/drivers/power/avs/smartreflex.c
> > +++ b/drivers/power/avs/smartreflex.c
> > @@ -1010,8 +1010,7 @@ static int omap_sr_remove(struct platfor
> >
> > if (sr_info->autocomp_active)
> > sr_stop_vddautocomp(sr_info);
> > - if (sr_info->dbg_dir)
> > - debugfs_remove_recursive(sr_info->dbg_dir);
> > + debugfs_remove_recursive(sr_info->dbg_dir);
> >
> > pm_runtime_disable(&pdev->dev);
> > list_del(&sr_info->node);
>
Patch applied, thanks!