Skip to contentSkip to conversation

scsi: mpi3mr: use ida to manage mrioc's id

PATCH Applied Guixin Liu 4 participants 8 messages Dec 29, 2023 – Jan 30, 2024

Subsystems (2)
lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

PATCH v2 1/1 scsi: mpi3mr: use ida to manage mrioc's 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.

---
Changes from v1 to v2:
- change id from int to u8, and use ida_alloc_range instead of ida_alloc.

 drivers/scsi/mpi3mr/mpi3mr_os.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/scsi/mpi3mr/mpi3mr_os.c +10 -2
index 040031eb0c12..36c4ab679094 100644
@@ -8,11 +8,12 @@
  */
 
 #include "mpi3mr.h"
+#include <linux/idr.h>
 
 /* global driver scop variables */
 LIST_HEAD(mrioc_list);
 DEFINE_SPINLOCK(mrioc_list_lock);
-static int mrioc_ids;
+static DEFINE_IDA(mrioc_ida);
 static int warn_non_secure_ctlr;
 atomic64_t event_counter;
 
@@ -5060,7 +5061,10 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	}
 
 	mrioc = shost_priv(shost);
-	mrioc->id = mrioc_ids++;
+	retval = ida_alloc_range(&mrioc_ida, 1, U8_MAX, GFP_KERNEL);
+	if (retval < 0)
+		goto id_alloc_failed;
+	mrioc->id = (u8)retval;
 	sprintf(mrioc->driver_name, "%s", MPI3MR_DRIVER_NAME);
 	sprintf(mrioc->name, "%s%d", mrioc->driver_name, mrioc->id);
 	INIT_LIST_HEAD(&mrioc->list);
@@ -5207,9 +5211,11 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 resource_alloc_failed:
 	destroy_workqueue(mrioc->fwevt_worker_thread);
 fwevtthread_failed:
+	ida_free(&mrioc_ida, mrioc->id);
 	spin_lock(&mrioc_list_lock);
 	list_del(&mrioc->list);
 	spin_unlock(&mrioc_list_lock);
+id_alloc_failed:
 	scsi_host_put(shost);
 shost_failed:
 	return retval;
@@ -5295,6 +5301,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
 		mrioc->sas_hba.num_phys = 0;
 	}
 
+	ida_free(&mrioc_ida, mrioc->id);
 	spin_lock(&mrioc_list_lock);
 	list_del(&mrioc->list);
 	spin_unlock(&mrioc_list_lock);
@@ -5502,6 +5509,7 @@ static void __exit mpi3mr_exit(void)
 			   &driver_attr_event_counter);
 	pci_unregister_driver(&mpi3mr_pci_driver);
 	sas_release_transport(mpi3mr_transport_template);
+	ida_destroy(&mrioc_ida);
 }
 
 module_init(mpi3mr_init);
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 75 lines · Guixin Liu

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.

---
Changes from v1 to v2:
- change id from int to u8, and use ida_alloc_range instead of ida_alloc.

 drivers/scsi/mpi3mr/mpi3mr_os.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/scsi/mpi3mr/mpi3mr_os.c +10 -3
index 040031eb0c12..36c4ab679094 100644
@@ -8,11 +8,12 @@
  */
 
 #include "mpi3mr.h"
+#include <linux/idr.h>
 
 /* global driver scop variables */
 LIST_HEAD(mrioc_list);
 DEFINE_SPINLOCK(mrioc_list_lock);
-static int mrioc_ids;
+static DEFINE_IDA(mrioc_ida);
 static int warn_non_secure_ctlr;
 atomic64_t event_counter;
 
@@ -5060,7 +5061,10 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        }
 
        mrioc = shost_priv(shost);
-       mrioc->id = mrioc_ids++;
+       retval = ida_alloc_range(&mrioc_ida, 1, U8_MAX, GFP_KERNEL);
+       if (retval < 0)
+               goto id_alloc_failed;
+       mrioc->id = (u8)retval;
        sprintf(mrioc->driver_name, "%s", MPI3MR_DRIVER_NAME);
        sprintf(mrioc->name, "%s%d", mrioc->driver_name, mrioc->id);
        INIT_LIST_HEAD(&mrioc->list);
@@ -5207,9 +5211,11 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 resource_alloc_failed:
        destroy_workqueue(mrioc->fwevt_worker_thread);
 fwevtthread_failed:
+       ida_free(&mrioc_ida, mrioc->id);
        spin_lock(&mrioc_list_lock);
        list_del(&mrioc->list);
        spin_unlock(&mrioc_list_lock);
+id_alloc_failed:
        scsi_host_put(shost);
 shost_failed:
        return retval;
@@ -5295,6 +5301,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
                mrioc->sas_hba.num_phys = 0;
        }
 
+       ida_free(&mrioc_ida, mrioc->id);
        spin_lock(&mrioc_list_lock);
        list_del(&mrioc->list);
        spin_unlock(&mrioc_list_lock);
@@ -5502,6 +5509,7 @@ static void __exit mpi3mr_exit(void)
                           &driver_attr_event_counter);
        pci_unregister_driver(&mpi3mr_pci_driver);
        sas_release_transport(mpi3mr_transport_template);
+       ida_destroy(&mrioc_ida);
 }
 
 module_init(mpi3mr_init);
--

2.43.0

author
#2 lore raw
In reply to Guixin Liu

gentle ping..

best regards,

Guixin Liu

Quoted 70 lines · Guixin Liu

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.

---
Changes from v1 to v2:
- change id from int to u8, and use ida_alloc_range instead of ida_alloc.

  drivers/scsi/mpi3mr/mpi3mr_os.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
drivers/scsi/mpi3mr/mpi3mr_os.c +10 -2
index 040031eb0c12..36c4ab679094 100644
@@ -8,11 +8,12 @@
   */
 
  #include "mpi3mr.h"
+#include <linux/idr.h>
 
  /* global driver scop variables */
  LIST_HEAD(mrioc_list);
  DEFINE_SPINLOCK(mrioc_list_lock);
-static int mrioc_ids;
+static DEFINE_IDA(mrioc_ida);
  static int warn_non_secure_ctlr;
  atomic64_t event_counter;
 
@@ -5060,7 +5061,10 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  	}
 
  	mrioc = shost_priv(shost);
-	mrioc->id = mrioc_ids++;
+	retval = ida_alloc_range(&mrioc_ida, 1, U8_MAX, GFP_KERNEL);
+	if (retval < 0)
+		goto id_alloc_failed;
+	mrioc->id = (u8)retval;
  	sprintf(mrioc->driver_name, "%s", MPI3MR_DRIVER_NAME);
  	sprintf(mrioc->name, "%s%d", mrioc->driver_name, mrioc->id);
  	INIT_LIST_HEAD(&mrioc->list);
@@ -5207,9 +5211,11 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  resource_alloc_failed:
  	destroy_workqueue(mrioc->fwevt_worker_thread);
  fwevtthread_failed:
+	ida_free(&mrioc_ida, mrioc->id);
  	spin_lock(&mrioc_list_lock);
  	list_del(&mrioc->list);
  	spin_unlock(&mrioc_list_lock);
+id_alloc_failed:
  	scsi_host_put(shost);
  shost_failed:
  	return retval;
@@ -5295,6 +5301,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
  		mrioc->sas_hba.num_phys = 0;
  	}
 
+	ida_free(&mrioc_ida, mrioc->id);
  	spin_lock(&mrioc_list_lock);
  	list_del(&mrioc->list);
  	spin_unlock(&mrioc_list_lock);
@@ -5502,6 +5509,7 @@ static void __exit mpi3mr_exit(void)
  			   &driver_attr_event_counter);
  	pci_unregister_driver(&mpi3mr_pci_driver);
  	sas_release_transport(mpi3mr_transport_template);
+	ida_destroy(&mrioc_ida);
  }
 
  module_init(mpi3mr_init);
author
#3 lore raw

friendly ping..

best regards,

Guixin Liu

Quoted 73 lines · Guixin Liu

gentle ping..

best regards,

Guixin Liu

Quoted 66 lines · Guixin Liu

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.

---
Changes from v1 to v2:
- change id from int to u8, and use ida_alloc_range instead of ida_alloc.

  drivers/scsi/mpi3mr/mpi3mr_os.c | 12 ++++++++++--

  1 file changed, 10 insertions(+), 2 deletions(-)
drivers/scsi/mpi3mr/mpi3mr_os.c +6 -2
index 040031eb0c12..36c4ab679094 100644
@@ -8,11 +8,12 @@
    */
     #include "mpi3mr.h"
+#include <linux/idr.h>
     /* global driver scop variables */
   LIST_HEAD(mrioc_list);
   DEFINE_SPINLOCK(mrioc_list_lock);
-static int mrioc_ids;
+static DEFINE_IDA(mrioc_ida);
   static int warn_non_secure_ctlr;
   atomic64_t event_counter;
   @@ -5060,7 +5061,10 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
       }
         mrioc = shost_priv(shost);
-    mrioc->id = mrioc_ids++;
+    retval = ida_alloc_range(&mrioc_ida, 1, U8_MAX, GFP_KERNEL);
+    if (retval < 0)
+        goto id_alloc_failed;
+    mrioc->id = (u8)retval;

      sprintf(mrioc->driver_name, "%s", MPI3MR_DRIVER_NAME); sprintf(mrioc->name, "%s%d", mrioc->driver_name, mrioc->id); INIT_LIST_HEAD(&mrioc->list);

drivers/scsi/mpi3mr/mpi3mr_os.c +0 -0
@@ -5207,9 +5211,11 @@ mpi3mr_probe(struct pci_dev *pdev, const 
 struct pci_device_id *id)

  resource_alloc_failed:
      destroy_workqueue(mrioc->fwevt_worker_thread); fwevtthread_failed:
+    ida_free(&mrioc_ida, mrioc->id); spin_lock(&mrioc_list_lock); list_del(&mrioc->list); spin_unlock(&mrioc_list_lock); +id_alloc_failed:
      scsi_host_put(shost);
  shost_failed:
      return retval;

drivers/scsi/mpi3mr/mpi3mr_os.c +1 -0
@@ -5295,6 +5301,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
           mrioc->sas_hba.num_phys = 0;
       }
   +    ida_free(&mrioc_ida, mrioc->id);
       spin_lock(&mrioc_list_lock);
       list_del(&mrioc->list);
       spin_unlock(&mrioc_list_lock);
@@ -5502,6 +5509,7 @@ static void __exit mpi3mr_exit(void)
                  &driver_attr_event_counter);
       pci_unregister_driver(&mpi3mr_pci_driver);
       sas_release_transport(mpi3mr_transport_template);
+    ida_destroy(&mrioc_ida);
   }
     module_init(mpi3mr_init);
author
#4 lore raw
In reply to Guixin Liu

Hi guys,

Friendly ping...

My patch has been sent to the community for three weeks now,

Could someone please review this patch?

Best regards,

Guixin Liu

Quoted 70 lines · Guixin Liu

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.

---
Changes from v1 to v2:
- change id from int to u8, and use ida_alloc_range instead of ida_alloc.

  drivers/scsi/mpi3mr/mpi3mr_os.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
drivers/scsi/mpi3mr/mpi3mr_os.c +10 -2
index 040031eb0c12..36c4ab679094 100644
@@ -8,11 +8,12 @@
   */
 
  #include "mpi3mr.h"
+#include <linux/idr.h>
 
  /* global driver scop variables */
  LIST_HEAD(mrioc_list);
  DEFINE_SPINLOCK(mrioc_list_lock);
-static int mrioc_ids;
+static DEFINE_IDA(mrioc_ida);
  static int warn_non_secure_ctlr;
  atomic64_t event_counter;
 
@@ -5060,7 +5061,10 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  	}
 
  	mrioc = shost_priv(shost);
-	mrioc->id = mrioc_ids++;
+	retval = ida_alloc_range(&mrioc_ida, 1, U8_MAX, GFP_KERNEL);
+	if (retval < 0)
+		goto id_alloc_failed;
+	mrioc->id = (u8)retval;
  	sprintf(mrioc->driver_name, "%s", MPI3MR_DRIVER_NAME);
  	sprintf(mrioc->name, "%s%d", mrioc->driver_name, mrioc->id);
  	INIT_LIST_HEAD(&mrioc->list);
@@ -5207,9 +5211,11 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  resource_alloc_failed:
  	destroy_workqueue(mrioc->fwevt_worker_thread);
  fwevtthread_failed:
+	ida_free(&mrioc_ida, mrioc->id);
  	spin_lock(&mrioc_list_lock);
  	list_del(&mrioc->list);
  	spin_unlock(&mrioc_list_lock);
+id_alloc_failed:
  	scsi_host_put(shost);
  shost_failed:
  	return retval;
@@ -5295,6 +5301,7 @@ static void mpi3mr_remove(struct pci_dev *pdev)
  		mrioc->sas_hba.num_phys = 0;
  	}
 
+	ida_free(&mrioc_ida, mrioc->id);
  	spin_lock(&mrioc_list_lock);
  	list_del(&mrioc->list);
  	spin_unlock(&mrioc_list_lock);
@@ -5502,6 +5509,7 @@ static void __exit mpi3mr_exit(void)
  			   &driver_attr_event_counter);
  	pci_unregister_driver(&mpi3mr_pci_driver);
  	sas_release_transport(mpi3mr_transport_template);
+	ida_destroy(&mrioc_ida);
  }
 
  module_init(mpi3mr_init);
Reviewed-by on v2 1/1
#5 lore raw
In reply to Guixin Liu
Quoted 4 lines · Guixin Liu

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.

Quoted 9 lines

---
Changes from v1 to v2:
- change id from int to u8, and use ida_alloc_range instead of ida_alloc.

 drivers/scsi/mpi3mr/mpi3mr_os.c | 12 ++++++++++--

 1 file changed, 10 insertions(+), 2 deletions(-)
#6 lore raw
In reply to Guixin Liu

Guixin,

Quoted 2 lines

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.

Applied to 6.9/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering