return 0;
 }
 
-/**
- *     ata_poll_qc_complete - turn irq back on and finish qc
- *     @qc: Command to complete
- *     @err_mask: ATA status register content
- *
- *     LOCKING:
- *     None.  (grabs host lock)
- */
-void ata_poll_qc_complete(struct ata_queued_cmd *qc)
-{
-       struct ata_port *ap = qc->ap;
-       unsigned long flags;
-
-       spin_lock_irqsave(&ap->host_set->lock, flags);
-
-       if (ap->ops->error_handler) {
-               /* EH might have kicked in while host_set lock is released */
-               qc = ata_qc_from_tag(ap, qc->tag);
-               if (qc) {
-                       if (!(qc->err_mask & AC_ERR_HSM)) {
-                               ata_irq_on(ap);
-                               ata_qc_complete(qc);
-                       } else
-                               ata_port_freeze(ap);
-               }
-       } else {
-               /* old EH */
-               ata_irq_on(ap);
-               ata_qc_complete(qc);
-       }
-
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
-}
-
 /**
  *     swap_buf_le16 - swap halves of 16-bit words in place
  *     @buf:  Buffer to swap
        return 0;
 }
 
+/**
+ *     ata_hsm_qc_complete - finish a qc running on standard HSM
+ *     @qc: Command to complete
+ *     @in_wq: 1 if called from workqueue, 0 otherwise
+ *
+ *     Finish @qc which is running on standard HSM.
+ *
+ *     LOCKING:
+ *     If @in_wq is zero, spin_lock_irqsave(host_set lock).
+ *     Otherwise, none on entry and grabs host lock.
+ */
+static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
+{
+       struct ata_port *ap = qc->ap;
+       unsigned long flags;
+
+       if (ap->ops->error_handler) {
+               if (in_wq) {
+                       spin_lock_irqsave(&ap->host_set->lock, flags);
+
+                       /* EH might have kicked in while host_set lock
+                        * is released.
+                        */
+                       qc = ata_qc_from_tag(ap, qc->tag);
+                       if (qc) {
+                               if (likely(!(qc->err_mask & AC_ERR_HSM))) {
+                                       ata_irq_on(ap);
+                                       ata_qc_complete(qc);
+                               } else
+                                       ata_port_freeze(ap);
+                       }
+
+                       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+               } else {
+                       if (likely(!(qc->err_mask & AC_ERR_HSM)))
+                               ata_qc_complete(qc);
+                       else
+                               ata_port_freeze(ap);
+               }
+       } else {
+               if (in_wq) {
+                       spin_lock_irqsave(&ap->host_set->lock, flags);
+                       ata_irq_on(ap);
+                       ata_qc_complete(qc);
+                       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+               } else
+                       ata_qc_complete(qc);
+       }
+}
+
 /**
  *     ata_hsm_move - move the HSM to the next state.
  *     @ap: the target ata_port
                ap->hsm_task_state = HSM_ST_IDLE;
 
                /* complete taskfile transaction */
-               if (in_wq)
-                       ata_poll_qc_complete(qc);
-               else
-                       ata_qc_complete(qc);
+               ata_hsm_qc_complete(qc, in_wq);
 
                poll_next = 0;
                break;
 
        case HSM_ST_ERR:
-               if (qc->tf.command != ATA_CMD_PACKET)
-                       printk(KERN_ERR "ata%u: dev %u command error, drv_stat 0x%x\n",
-                              ap->id, qc->dev->devno, status);
-
                /* make sure qc->err_mask is available to
                 * know what's wrong and recover
                 */
                ap->hsm_task_state = HSM_ST_IDLE;
 
                /* complete taskfile transaction */
-               if (in_wq)
-                       ata_poll_qc_complete(qc);
-               else
-                       ata_qc_complete(qc);
+               ata_hsm_qc_complete(qc, in_wq);
 
                poll_next = 0;
                break;