hlist_del_init(&c->list);
 }
 
+static void enqueue_cmd_and_start_io(ctlr_info_t *h,
+       CommandList_struct *c)
+{
+       unsigned long flags;
+       spin_lock_irqsave(&h->lock, flags);
+       addQ(&h->reqQ, c);
+       h->Qdepth++;
+       start_io(h);
+       spin_unlock_irqrestore(&h->lock, flags);
+}
+
 static void cciss_free_sg_chain_blocks(SGDescriptor_struct **cmd_sg_list,
        int nr_cmds)
 {
                        CommandList_struct *c;
                        char *buff = NULL;
                        u64bit temp64;
-                       unsigned long flags;
                        DECLARE_COMPLETION_ONSTACK(wait);
 
                        if (!arg)
                        }
                        c->waiting = &wait;
 
-                       /* Put the request on the tail of the request queue */
-                       spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
-                       addQ(&host->reqQ, c);
-                       host->Qdepth++;
-                       start_io(host);
-                       spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
-
+                       enqueue_cmd_and_start_io(host, c);
                        wait_for_completion(&wait);
 
                        /* unlock the buffers from DMA */
                        unsigned char **buff = NULL;
                        int *buff_size = NULL;
                        u64bit temp64;
-                       unsigned long flags;
                        BYTE sg_used = 0;
                        int status = 0;
                        int i;
                                }
                        }
                        c->waiting = &wait;
-                       /* Put the request on the tail of the request queue */
-                       spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
-                       addQ(&host->reqQ, c);
-                       host->Qdepth++;
-                       start_io(host);
-                       spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
+                       enqueue_cmd_and_start_io(host, c);
                        wait_for_completion(&wait);
                        /* unlock the buffers from DMA */
                        for (i = 0; i < sg_used; i++) {
        CommandList_struct *cmd = rq->completion_data;
        ctlr_info_t *h = hba[cmd->ctlr];
        SGDescriptor_struct *curr_sg = cmd->SG;
-       unsigned long flags;
        u64bit temp64;
+       unsigned long flags;
        int i, ddir;
        int sg_index = 0;
 
 {
        DECLARE_COMPLETION_ONSTACK(wait);
        u64bit buff_dma_handle;
-       unsigned long flags;
        int return_status = IO_OK;
 
 resend_cmd2:
        c->waiting = &wait;
-       /* Put the request on the tail of the queue and send it */
-       spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
-       addQ(&h->reqQ, c);
-       h->Qdepth++;
-       start_io(h);
-       spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
+       enqueue_cmd_and_start_io(h, c);
 
        wait_for_completion(&wait);