From 36ba69d80d0c4b30cdd9dec197a30d72451ece4d Mon Sep 17 00:00:00 2001 From: Himanshu Madhani Date: Thu, 1 Aug 2019 15:55:46 -0400 Subject: [PATCH 086/124] [scsi] scsi: qla2xxx: Make qla2x00_mem_free() easier to verify Message-id: <20190801155618.12650-87-hmadhani@redhat.com> Patchwork-id: 267861 O-Subject: [RHEL 7.8 e-stor PATCH 086/118] scsi: qla2xxx: Make qla2x00_mem_free() easier to verify Bugzilla: 1729270 RH-Acked-by: Jarod Wilson RH-Acked-by: Tony Camuso From: Bart Van Assche Bugzilla 1729270 Instead of clearing all freed pointers at the end of qla2x00_mem_free(), clear freed pointers immediately after having freed the memory these pointers point at. Cc: Himanshu Madhani Cc: Giridhar Malavali Signed-off-by: Bart Van Assche Acked-by: Himanshu Madhani Signed-off-by: Martin K. Petersen (cherry picked from commit 5365bf99e360bf3c31f2d5ba8f20f60dd47f6a86) Signed-off-by: Himanshu Madhani Signed-off-by: Jan Stancek --- drivers/scsi/qla2xxx/qla_os.c | 61 +++++++++++++++++---------------------- drivers/scsi/qla2xxx/qla_target.c | 3 ++ 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c index 326c0e6588de..43a109f3676c 100644 --- a/drivers/scsi/qla2xxx/qla_os.c +++ b/drivers/scsi/qla2xxx/qla_os.c @@ -4803,28 +4803,37 @@ qla2x00_mem_free(struct qla_hw_data *ha) if (ha->mctp_dump) dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump, ha->mctp_dump_dma); + ha->mctp_dump = NULL; mempool_destroy(ha->srb_mempool); + ha->srb_mempool = NULL; if (ha->dcbx_tlv) dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE, ha->dcbx_tlv, ha->dcbx_tlv_dma); + ha->dcbx_tlv = NULL; if (ha->xgmac_data) dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE, ha->xgmac_data, ha->xgmac_data_dma); + ha->xgmac_data = NULL; if (ha->sns_cmd) dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), ha->sns_cmd, ha->sns_cmd_dma); + ha->sns_cmd = NULL; + ha->sns_cmd_dma = 0; if (ha->ct_sns) dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), ha->ct_sns, ha->ct_sns_dma); + ha->ct_sns = NULL; + ha->ct_sns_dma = 0; if (ha->sfp_data) dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data, ha->sfp_data_dma); + ha->sfp_data = NULL; if (ha->flt) dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, @@ -4832,19 +4841,28 @@ qla2x00_mem_free(struct qla_hw_data *ha) if (ha->ms_iocb) dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); + ha->ms_iocb = NULL; + ha->ms_iocb_dma = 0; if (ha->ex_init_cb) dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma); + ha->ex_init_cb = NULL; + ha->ex_init_cb_dma = 0; if (ha->async_pd) dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma); + ha->async_pd = NULL; + ha->async_pd_dma = 0; dma_pool_destroy(ha->s_dma_pool); + ha->s_dma_pool = NULL; if (ha->gid_list) dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha), ha->gid_list, ha->gid_list_dma); + ha->gid_list = NULL; + ha->gid_list_dma = 0; if (IS_QLA82XX(ha)) { if (!list_empty(&ha->gbl_dsd_list)) { @@ -4862,10 +4880,13 @@ qla2x00_mem_free(struct qla_hw_data *ha) } dma_pool_destroy(ha->dl_dma_pool); + ha->dl_dma_pool = NULL; dma_pool_destroy(ha->fcp_cmnd_dma_pool); + ha->fcp_cmnd_dma_pool = NULL; mempool_destroy(ha->ctx_mempool); + ha->ctx_mempool = NULL; if (ql2xenabledif) { struct dsd_dma *dsd, *nxt; @@ -4898,47 +4919,19 @@ qla2x00_mem_free(struct qla_hw_data *ha) if (ha->init_cb) dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb, ha->init_cb_dma); + ha->init_cb = NULL; + ha->init_cb_dma = 0; vfree(ha->optrom_buffer); + ha->optrom_buffer = NULL; kfree(ha->nvram); + ha->nvram = NULL; kfree(ha->npiv_info); + ha->npiv_info = NULL; kfree(ha->swl); + ha->swl = NULL; kfree(ha->loop_id_map); - - ha->srb_mempool = NULL; - ha->ctx_mempool = NULL; - ha->sns_cmd = NULL; - ha->sns_cmd_dma = 0; - ha->ct_sns = NULL; - ha->ct_sns_dma = 0; - ha->ms_iocb = NULL; - ha->ms_iocb_dma = 0; - ha->init_cb = NULL; - ha->init_cb_dma = 0; - ha->ex_init_cb = NULL; - ha->ex_init_cb_dma = 0; - ha->async_pd = NULL; - ha->async_pd_dma = 0; ha->loop_id_map = NULL; - ha->npiv_info = NULL; - ha->optrom_buffer = NULL; - ha->swl = NULL; - ha->nvram = NULL; - ha->mctp_dump = NULL; - ha->dcbx_tlv = NULL; - ha->xgmac_data = NULL; - ha->sfp_data = NULL; - - ha->s_dma_pool = NULL; - ha->dl_dma_pool = NULL; - ha->fcp_cmnd_dma_pool = NULL; - - ha->gid_list = NULL; - ha->gid_list_dma = 0; - - ha->tgt.atio_ring = NULL; - ha->tgt.atio_dma = 0; - ha->tgt.tgt_vp_map = NULL; } struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht, diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c index eaa32f5e7d19..204004431c3f 100644 --- a/drivers/scsi/qla2xxx/qla_target.c +++ b/drivers/scsi/qla2xxx/qla_target.c @@ -7320,7 +7320,10 @@ qlt_mem_free(struct qla_hw_data *ha) sizeof(struct atio_from_isp), ha->tgt.atio_ring, ha->tgt.atio_dma); } + ha->tgt.atio_ring = NULL; + ha->tgt.atio_dma = 0; kfree(ha->tgt.tgt_vp_map); + ha->tgt.tgt_vp_map = NULL; } /* vport_slock to be held by the caller */ -- 2.13.6