struct ata_port *ap = dev->sata_dev.ap;
        struct sas_ha_struct *ha = dev->port->ha;
 
+       /* hold a reference over eh since we may be racing with final
+        * remove once all commands are completed
+        */
+       kref_get(&dev->kref);
        ata_port_printk(ap, KERN_DEBUG, "sas eh calling libata port error handler");
        ata_scsi_port_error_handler(ha->core.shost, ap);
+       sas_put_device(dev);
 }
 
 void sas_ata_strategy_handler(struct Scsi_Host *shost)
 
        if (dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV)
                kfree(dev->ex_dev.ex_phy);
 
+       if (dev_is_sata(dev) && dev->sata_dev.ap) {
+               ata_sas_port_destroy(dev->sata_dev.ap);
+               dev->sata_dev.ap = NULL;
+       }
+
        kfree(dev);
 }
 
 
        if (!found_dev)
                return;
 
-       if (dev_is_sata(found_dev))
-               ata_sas_port_destroy(found_dev->sata_dev.ap);
-
        starget->hostdata = NULL;
        sas_put_device(found_dev);
 }