diff mbox

[3/5] block: nvme-core: simplify ida usage

Message ID cb1a4e9a77ed39c98072c70a0bebc9b98067852a.1443723136.git.lduncan@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lee Duncan Oct. 1, 2015, 6:59 p.m. UTC
Simplify ida index allocation and removal by
using the ida_simple_* helper functions.

Signed-off-by: Lee Duncan <lduncan@suse.com>
---
 drivers/block/nvme-core.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

Comments

Johannes Thumshirn Oct. 2, 2015, 10:15 a.m. UTC | #1
Lee Duncan <lduncan@suse.com> writes:

> Simplify ida index allocation and removal by
> using the ida_simple_* helper functions.
>
> Signed-off-by: Lee Duncan <lduncan@suse.com>
> ---
>  drivers/block/nvme-core.c | 16 ++++------------
>  1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
> index d1d6141920d3..d354a3391e4a 100644
> --- a/drivers/block/nvme-core.c
> +++ b/drivers/block/nvme-core.c
> @@ -2713,18 +2713,10 @@ static DEFINE_IDA(nvme_instance_ida);
>  
>  static int nvme_set_instance(struct nvme_dev *dev)
>  {
> -	int instance, error;
> +	int instance;
>  
> -	do {
> -		if (!ida_pre_get(&nvme_instance_ida, GFP_KERNEL))
> -			return -ENODEV;
> -
> -		spin_lock(&dev_list_lock);
> -		error = ida_get_new(&nvme_instance_ida, &instance);
> -		spin_unlock(&dev_list_lock);
> -	} while (error == -EAGAIN);
> -
> -	if (error)
> +	instance = ida_simple_get(&nvme_instance_ida, 0, 0, GFP_KERNEL);
> +	if (instance < 0)
>  		return -ENODEV;
>  
>  	dev->instance = instance;
> @@ -2734,7 +2726,7 @@ static int nvme_set_instance(struct nvme_dev *dev)
>  static void nvme_release_instance(struct nvme_dev *dev)
>  {
>  	spin_lock(&dev_list_lock);
> -	ida_remove(&nvme_instance_ida, dev->instance);
> +	ida_simple_remove(&nvme_instance_ida, dev->instance);
>  	spin_unlock(&dev_list_lock);
>  }

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Keith Busch Oct. 8, 2015, 2:29 p.m. UTC | #2
On Fri, 2 Oct 2015, Johannes Thumshirn wrote:
> Lee Duncan <lduncan@suse.com> writes:
>> Simplify ida index allocation and removal by
>> using the ida_simple_* helper functions.

Looks good to me. Just one comment:

>>  static void nvme_release_instance(struct nvme_dev *dev)
>>  {
>>  	spin_lock(&dev_list_lock);
>> -	ida_remove(&nvme_instance_ida, dev->instance);
>> +	ida_simple_remove(&nvme_instance_ida, dev->instance);
>>  	spin_unlock(&dev_list_lock);

No harm from taking the nvme spin lock here, but it's not necessary with
the simple interface.

> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index d1d6141920d3..d354a3391e4a 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -2713,18 +2713,10 @@  static DEFINE_IDA(nvme_instance_ida);
 
 static int nvme_set_instance(struct nvme_dev *dev)
 {
-	int instance, error;
+	int instance;
 
-	do {
-		if (!ida_pre_get(&nvme_instance_ida, GFP_KERNEL))
-			return -ENODEV;
-
-		spin_lock(&dev_list_lock);
-		error = ida_get_new(&nvme_instance_ida, &instance);
-		spin_unlock(&dev_list_lock);
-	} while (error == -EAGAIN);
-
-	if (error)
+	instance = ida_simple_get(&nvme_instance_ida, 0, 0, GFP_KERNEL);
+	if (instance < 0)
 		return -ENODEV;
 
 	dev->instance = instance;
@@ -2734,7 +2726,7 @@  static int nvme_set_instance(struct nvme_dev *dev)
 static void nvme_release_instance(struct nvme_dev *dev)
 {
 	spin_lock(&dev_list_lock);
-	ida_remove(&nvme_instance_ida, dev->instance);
+	ida_simple_remove(&nvme_instance_ida, dev->instance);
 	spin_unlock(&dev_list_lock);
 }