Skip to content

Commit 29b7518

Browse files
guixinliu1995martinkpetersen
authored andcommitted
scsi: mpi3mr: Use ida to manage mrioc ID
To ensure that the same ID is not obtained during concurrent execution of the probe, an ida is used to manage the mrioc's ID. Signed-off-by: Guixin Liu <kanie@linux.alibaba.com> Link: https://lore.kernel.org/r/20231229040331.52518-1-kanie@linux.alibaba.com Reviewed-by: Lee Duncan <lduncan@suse.com> Reviewed-by: Martin Wilck <mwilck@suse.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 165470f commit 29b7518

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/scsi/mpi3mr/mpi3mr_os.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
*/
99

1010
#include "mpi3mr.h"
11+
#include <linux/idr.h>
1112

1213
/* global driver scop variables */
1314
LIST_HEAD(mrioc_list);
1415
DEFINE_SPINLOCK(mrioc_list_lock);
15-
static int mrioc_ids;
16+
static DEFINE_IDA(mrioc_ida);
1617
static int warn_non_secure_ctlr;
1718
atomic64_t event_counter;
1819

@@ -5072,7 +5073,10 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
50725073
}
50735074

50745075
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;
50765080
sprintf(mrioc->driver_name, "%s", MPI3MR_DRIVER_NAME);
50775081
sprintf(mrioc->name, "%s%d", mrioc->driver_name, mrioc->id);
50785082
INIT_LIST_HEAD(&mrioc->list);
@@ -5222,9 +5226,11 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
52225226
resource_alloc_failed:
52235227
destroy_workqueue(mrioc->fwevt_worker_thread);
52245228
fwevtthread_failed:
5229+
ida_free(&mrioc_ida, mrioc->id);
52255230
spin_lock(&mrioc_list_lock);
52265231
list_del(&mrioc->list);
52275232
spin_unlock(&mrioc_list_lock);
5233+
id_alloc_failed:
52285234
scsi_host_put(shost);
52295235
shost_failed:
52305236
return retval;
@@ -5310,6 +5316,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
53105316
mrioc->sas_hba.num_phys = 0;
53115317
}
53125318

5319+
ida_free(&mrioc_ida, mrioc->id);
53135320
spin_lock(&mrioc_list_lock);
53145321
list_del(&mrioc->list);
53155322
spin_unlock(&mrioc_list_lock);
@@ -5525,6 +5532,7 @@ static void __exit mpi3mr_exit(void)
55255532
&driver_attr_event_counter);
55265533
pci_unregister_driver(&mpi3mr_pci_driver);
55275534
sas_release_transport(mpi3mr_transport_template);
5535+
ida_destroy(&mrioc_ida);
55285536
}
55295537

55305538
module_init(mpi3mr_init);

0 commit comments

Comments
 (0)