error = lpfc_alloc_sysfs_attr(phba);
        if (error)
-               goto out_kthread_stop;
+               goto out_remove_host;
 
        error = request_irq(phba->pcidev->irq, lpfc_intr_handler, SA_SHIRQ,
                                                        LPFC_DRIVER_NAME, phba);
        phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
 
        error = lpfc_sli_hba_setup(phba);
-       if (error)
+       if (error) {
+               error = -ENODEV;
                goto out_free_irq;
+       }
 
        if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
                spin_lock_irq(phba->host->host_lock);
        free_irq(phba->pcidev->irq, phba);
 out_free_sysfs_attr:
        lpfc_free_sysfs_attr(phba);
+out_remove_host:
+       fc_remove_host(phba->host);
+       scsi_remove_host(phba->host);
 out_kthread_stop:
        kthread_stop(phba->worker_thread);
 out_free_iocbq:
 out_idr_remove:
        idr_remove(&lpfc_hba_index, phba->brd_no);
 out_put_host:
+       phba->host = NULL;
        scsi_host_put(host);
 out_release_regions:
        pci_release_regions(pdev);
 out_disable_device:
        pci_disable_device(pdev);
 out:
+       pci_set_drvdata(pdev, NULL);
        return error;
 }