Suggested-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Scott Benesh <scott.benesh@microsemi.com>
Reviewed-by: Scott Teel <scott.teel@microsemi.com>
Reviewed-by: Kevin Barnett <kevin.barnett@microsemi.com>
Signed-off-by: Don Brace <don.brace@microsemi.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
        if (!h->scsi_host)
                return;
 
+       /*
+        * Allow for commands to drain
+        */
+       device->removed = 1;
+       hpsa_wait_for_outstanding_commands_for_dev(h, device);
+
        if (is_logical_device(device)) { /* RAID */
                sdev = scsi_device_lookup(h->scsi_host, device->bus,
                                                device->target, device->lun);
                }
        } else { /* HBA */
 
-               device->removed = 1;
-               hpsa_wait_for_outstanding_commands_for_dev(h, device);
-
                hpsa_remove_sas_device(device);
        }
 }