|
8 | 8 | */
|
9 | 9 |
|
10 | 10 | #include "mpi3mr.h"
|
| 11 | +#include <linux/idr.h> |
11 | 12 |
|
12 | 13 | /* global driver scop variables */
|
13 | 14 | LIST_HEAD(mrioc_list);
|
14 | 15 | DEFINE_SPINLOCK(mrioc_list_lock);
|
15 |
| -static int mrioc_ids; |
| 16 | +static DEFINE_IDA(mrioc_ida); |
16 | 17 | static int warn_non_secure_ctlr;
|
17 | 18 | atomic64_t event_counter;
|
18 | 19 |
|
@@ -5072,7 +5073,10 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
5072 | 5073 | }
|
5073 | 5074 |
|
5074 | 5075 | mrioc = shost_priv(shost);
|
5075 |
| - mrioc->id = mrioc_ids++; |
| 5076 | + retval = ida_alloc_range(&mrioc_ida, 1, U8_MAX, GFP_KERNEL); |
| 5077 | + if (retval < 0) |
| 5078 | + goto id_alloc_failed; |
| 5079 | + mrioc->id = (u8)retval; |
5076 | 5080 | sprintf(mrioc->driver_name, "%s", MPI3MR_DRIVER_NAME);
|
5077 | 5081 | sprintf(mrioc->name, "%s%d", mrioc->driver_name, mrioc->id);
|
5078 | 5082 | INIT_LIST_HEAD(&mrioc->list);
|
@@ -5222,9 +5226,11 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
5222 | 5226 | resource_alloc_failed:
|
5223 | 5227 | destroy_workqueue(mrioc->fwevt_worker_thread);
|
5224 | 5228 | fwevtthread_failed:
|
| 5229 | + ida_free(&mrioc_ida, mrioc->id); |
5225 | 5230 | spin_lock(&mrioc_list_lock);
|
5226 | 5231 | list_del(&mrioc->list);
|
5227 | 5232 | spin_unlock(&mrioc_list_lock);
|
| 5233 | +id_alloc_failed: |
5228 | 5234 | scsi_host_put(shost);
|
5229 | 5235 | shost_failed:
|
5230 | 5236 | return retval;
|
@@ -5310,6 +5316,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
|
5310 | 5316 | mrioc->sas_hba.num_phys = 0;
|
5311 | 5317 | }
|
5312 | 5318 |
|
| 5319 | + ida_free(&mrioc_ida, mrioc->id); |
5313 | 5320 | spin_lock(&mrioc_list_lock);
|
5314 | 5321 | list_del(&mrioc->list);
|
5315 | 5322 | spin_unlock(&mrioc_list_lock);
|
@@ -5525,6 +5532,7 @@ static void __exit mpi3mr_exit(void)
|
5525 | 5532 | &driver_attr_event_counter);
|
5526 | 5533 | pci_unregister_driver(&mpi3mr_pci_driver);
|
5527 | 5534 | sas_release_transport(mpi3mr_transport_template);
|
| 5535 | + ida_destroy(&mrioc_ida); |
5528 | 5536 | }
|
5529 | 5537 |
|
5530 | 5538 | module_init(mpi3mr_init);
|
|
0 commit comments