diff options
author | Dan Williams <dan.j.williams@intel.com> | 2011-03-03 17:59:32 -0800 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2011-07-03 03:55:29 -0700 |
commit | d9c37390c4f02153188a64a7a89fa6798dc3ffc2 (patch) | |
tree | 508f28b5b88348b2d989f479442cbd6813bd2b42 /drivers/scsi/isci/init.c | |
parent | 6ad31fec306d532031b2f778f8656385df1b9d8f (diff) |
isci: preallocate remote devices
Until we synchronize against device removal this limits the damage of
use after free bugs to the driver's own objects. Unless we implement
reference counting we need to ensure at least a subset of a remote
device is valid at all times. We follow the lead of other libsas
drivers that also preallocate devices.
This also enforces maximum remote device accounting at the lldd layer,
but the core may still run out of RNC's before we hit this limit.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/scsi/isci/init.c')
-rw-r--r-- | drivers/scsi/isci/init.c | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c index f1b8a51dd49..2838beff43b 100644 --- a/drivers/scsi/isci/init.c +++ b/drivers/scsi/isci/init.c @@ -64,7 +64,6 @@ #include "sci_environment.h" static struct scsi_transport_template *isci_transport_template; -struct kmem_cache *isci_kmem_cache; static DEFINE_PCI_DEVICE_TABLE(isci_id_table) = { { PCI_VDEVICE(INTEL, 0x1D61),}, @@ -443,7 +442,10 @@ static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id) struct Scsi_Host *shost; int err; - isci_host = devm_kzalloc(&pdev->dev, sizeof(*isci_host), GFP_KERNEL); + isci_host = devm_kzalloc(&pdev->dev, sizeof(*isci_host) + + SCI_MAX_REMOTE_DEVICES * + (sizeof(struct isci_remote_device) + + scic_remote_device_get_object_size()), GFP_KERNEL); if (!isci_host) return NULL; @@ -656,31 +658,17 @@ static void __devexit isci_pci_remove(struct pci_dev *pdev) static __init int isci_init(void) { - int err = -ENOMEM; + int err; pr_info("%s: Intel(R) C600 SAS Controller Driver\n", DRV_NAME); - isci_kmem_cache = kmem_cache_create(DRV_NAME, - sizeof(struct isci_remote_device) + - scic_remote_device_get_object_size(), - 0, 0, NULL); - if (!isci_kmem_cache) - return err; - isci_transport_template = sas_domain_attach_transport(&isci_transport_ops); if (!isci_transport_template) - goto err_kmem; + return -ENOMEM; err = pci_register_driver(&isci_pci_driver); if (err) - goto err_sas; - - return 0; - - err_sas: - sas_release_transport(isci_transport_template); - err_kmem: - kmem_cache_destroy(isci_kmem_cache); + sas_release_transport(isci_transport_template); return err; } @@ -689,7 +677,6 @@ static __exit void isci_exit(void) { pci_unregister_driver(&isci_pci_driver); sas_release_transport(isci_transport_template); - kmem_cache_destroy(isci_kmem_cache); } MODULE_LICENSE("Dual BSD/GPL"); |