diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index d664c4650b2dd3c7a9d312d7d94ff4b4e09f26a8..0553ad4571dfd952758aba0c92552b4d88442906 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -477,6 +477,9 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) if (sht->virt_boundary_mask) shost->virt_boundary_mask = sht->virt_boundary_mask; + if (!sht->module) + shost->is_builtin = true; + device_initialize(&shost->shost_gendev); dev_set_name(&shost->shost_gendev, "host%d", shost->host_no); shost->shost_gendev.bus = &scsi_bus_type; diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index f561caabc7715c4139bf540a74fbef689932450f..9e21ef4e09717da80bc98669fd5e7ee1e0194ecf 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -522,11 +522,15 @@ EXPORT_SYMBOL(scsi_report_opcode); */ int scsi_device_get(struct scsi_device *sdev) { + struct module *module; + if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL) goto fail; if (!get_device(&sdev->sdev_gendev)) goto fail; - if (!try_module_get(sdev->host->hostt->module)) + + module = sdev->host->hostt->module; + if ((!module && !sdev->host->is_builtin) || !try_module_get(module)) goto fail_put_device; return 0; diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 19f595b6a5ca06ceea30a2aceeb64bd439d365cb..161d3d078ec9098ecd9e50bdeddb96984404bf89 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -698,7 +698,7 @@ struct Scsi_Host { */ struct device *dma_dev; - KABI_RESERVE(1) + KABI_USE(1, bool is_builtin) KABI_RESERVE(2) KABI_RESERVE(3) KABI_RESERVE(4)