]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
scsi: qla2xxx: Let the compiler check the type of the SCSI command context pointer
authorBart Van Assche <bvanassche@acm.org>
Fri, 9 Aug 2019 03:02:12 +0000 (20:02 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 13 Aug 2019 01:34:09 +0000 (21:34 -0400)
Split srb_cmd.ctx into two pointers such that the compiler can check the
type of that pointer.

Cc: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Tested-by: Himanshu Madhani <hmadhani@marvell.com>
Reviewed-by: Himanshu Madhani <hmadhani@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_iocb.c
drivers/scsi/qla2xxx/qla_nx.c
drivers/scsi/qla2xxx/qla_os.c

index 3ffe7661a25b38d582ba265d0d08758e1ca2021f..527b2a2708a10f878d4186b7b5e32a6d4d7c3864 100644 (file)
@@ -317,7 +317,8 @@ struct srb_cmd {
        uint32_t request_sense_length;
        uint32_t fw_sense_length;
        uint8_t *request_sense_ptr;
-       void *ctx;
+       struct ct6_dsd *ct6_ctx;
+       struct crc_context *crc_ctx;
 };
 
 /*
@@ -630,7 +631,6 @@ typedef struct srb {
 } srb_t;
 
 #define GET_CMD_SP(sp) (sp->u.scmd.cmd)
-#define GET_CMD_CTX_SP(sp) (sp->u.scmd.ctx)
 
 #define GET_CMD_SENSE_LEN(sp) \
        (sp->u.scmd.request_sense_length)
index 22d8752223210234367de66f156e3c9180f6a5d0..6acf92d1995120a5e61c56a6f136c90281d8d385 100644 (file)
@@ -621,7 +621,7 @@ qla24xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt,
        }
 
        cur_seg = scsi_sglist(cmd);
-       ctx = GET_CMD_CTX_SP(sp);
+       ctx = sp->u.scmd.ct6_ctx;
 
        while (tot_dsds) {
                avail_dsds = (tot_dsds > QLA_DSDS_PER_IOCB) ?
@@ -954,8 +954,7 @@ qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp,
 
                        if (sp) {
                                list_add_tail(&dsd_ptr->list,
-                                   &((struct crc_context *)
-                                           sp->u.scmd.ctx)->dsd_list);
+                                             &sp->u.scmd.crc_ctx->dsd_list);
 
                                sp->flags |= SRB_CRC_CTX_DSD_VALID;
                        } else {
@@ -1052,8 +1051,7 @@ qla24xx_walk_and_build_sglist(struct qla_hw_data *ha, srb_t *sp,
 
                        if (sp) {
                                list_add_tail(&dsd_ptr->list,
-                                   &((struct crc_context *)
-                                           sp->u.scmd.ctx)->dsd_list);
+                                             &sp->u.scmd.crc_ctx->dsd_list);
 
                                sp->flags |= SRB_CRC_CTX_DSD_VALID;
                        } else {
@@ -1099,7 +1097,7 @@ qla24xx_walk_and_build_prot_sglist(struct qla_hw_data *ha, srb_t *sp,
 
                sgl = scsi_prot_sglist(cmd);
                vha = sp->vha;
-               difctx = sp->u.scmd.ctx;
+               difctx = sp->u.scmd.crc_ctx;
                direction_to_device = cmd->sc_data_direction == DMA_TO_DEVICE;
                ql_dbg(ql_dbg_tgt + ql_dbg_verbose, vha, 0xe021,
                  "%s: scsi_cmnd: %p, crc_ctx: %p, sp: %p\n",
@@ -1439,7 +1437,7 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
                bundling = 0;
 
        /* Allocate CRC context from global pool */
-       crc_ctx_pkt = sp->u.scmd.ctx =
+       crc_ctx_pkt = sp->u.scmd.crc_ctx =
            dma_pool_zalloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma);
 
        if (!crc_ctx_pkt)
@@ -3188,7 +3186,7 @@ qla82xx_start_scsi(srb_t *sp)
                                goto queuing_error;
                }
 
-               ctx = sp->u.scmd.ctx =
+               ctx = sp->u.scmd.ct6_ctx =
                    mempool_alloc(ha->ctx_mempool, GFP_ATOMIC);
                if (!ctx) {
                        ql_log(ql_log_fatal, vha, 0x3010,
@@ -3384,9 +3382,9 @@ qla82xx_start_scsi(srb_t *sp)
        if (tot_dsds)
                scsi_dma_unmap(cmd);
 
-       if (sp->u.scmd.ctx) {
-               mempool_free(sp->u.scmd.ctx, ha->ctx_mempool);
-               sp->u.scmd.ctx = NULL;
+       if (sp->u.scmd.crc_ctx) {
+               mempool_free(sp->u.scmd.crc_ctx, ha->ctx_mempool);
+               sp->u.scmd.crc_ctx = NULL;
        }
        spin_unlock_irqrestore(&ha->hardware_lock, flags);
 
index a91d426add75a60a4807a6fb2376b9adf39d1a49..372355bfcbb65ca2db95ae8583f9553a1cc762cc 100644 (file)
@@ -3686,7 +3686,7 @@ qla82xx_chip_reset_cleanup(scsi_qla_host_t *vha)
                        for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
                                sp = req->outstanding_cmds[cnt];
                                if (sp) {
-                                       if ((!sp->u.scmd.ctx ||
+                                       if ((!sp->u.scmd.crc_ctx ||
                                            (sp->flags &
                                                SRB_FCP_CMND_DMA_VALID)) &&
                                                !ha->flags.isp82xx_fw_hung) {
index 5ca7f7913258a45ab584b08ceacf07bedcfac27b..5cb0bb65ace38556d23a09ca14e2809a3f99e1bb 100644 (file)
@@ -656,7 +656,6 @@ void qla2x00_sp_free_dma(srb_t *sp)
 {
        struct qla_hw_data *ha = sp->vha->hw;
        struct scsi_cmnd *cmd = GET_CMD_SP(sp);
-       void *ctx = GET_CMD_CTX_SP(sp);
 
        if (sp->flags & SRB_DMA_VALID) {
                scsi_dma_unmap(cmd);
@@ -669,24 +668,21 @@ void qla2x00_sp_free_dma(srb_t *sp)
                sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
        }
 
-       if (!ctx)
-               return;
-
        if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
                /* List assured to be having elements */
-               qla2x00_clean_dsd_pool(ha, ctx);
+               qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
                sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
        }
 
        if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
-               struct crc_context *ctx0 = ctx;
+               struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
 
                dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
                sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
        }
 
        if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
-               struct ct6_dsd *ctx1 = ctx;
+               struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
 
                dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
                    ctx1->fcp_cmnd_dma);
@@ -719,7 +715,6 @@ void qla2xxx_qpair_sp_free_dma(srb_t *sp)
 {
        struct scsi_cmnd *cmd = GET_CMD_SP(sp);
        struct qla_hw_data *ha = sp->fcport->vha->hw;
-       void *ctx = GET_CMD_CTX_SP(sp);
 
        if (sp->flags & SRB_DMA_VALID) {
                scsi_dma_unmap(cmd);
@@ -732,17 +727,14 @@ void qla2xxx_qpair_sp_free_dma(srb_t *sp)
                sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
        }
 
-       if (!ctx)
-               return;
-
        if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
                /* List assured to be having elements */
-               qla2x00_clean_dsd_pool(ha, ctx);
+               qla2x00_clean_dsd_pool(ha, sp->u.scmd.crc_ctx);
                sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
        }
 
        if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
-               struct crc_context *difctx = ctx;
+               struct crc_context *difctx = sp->u.scmd.crc_ctx;
                struct dsd_dma *dif_dsd, *nxt_dsd;
 
                list_for_each_entry_safe(dif_dsd, nxt_dsd,
@@ -778,7 +770,7 @@ void qla2xxx_qpair_sp_free_dma(srb_t *sp)
        }
 
        if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
-               struct ct6_dsd *ctx1 = ctx;
+               struct ct6_dsd *ctx1 = sp->u.scmd.ct6_ctx;
 
                dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
                    ctx1->fcp_cmnd_dma);
@@ -790,9 +782,9 @@ void qla2xxx_qpair_sp_free_dma(srb_t *sp)
        }
 
        if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
-               struct crc_context *ctx0 = ctx;
+               struct crc_context *ctx0 = sp->u.scmd.crc_ctx;
 
-               dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
+               dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
                sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
        }
 }