Re: [PATCH 07/17] nvme: use ida_simple_{get,remove} for the controller instance

2017-10-19 Thread Christoph Hellwig
On Thu, Oct 19, 2017 at 09:14:27AM -0600, Keith Busch wrote:
> This is a good cleanup, and I'd support this patch going in ahead of
> this series on its own if you want to apply to 4.15 immediately.

Ok, will do.


Re: [PATCH 07/17] nvme: use ida_simple_{get,remove} for the controller instance

2017-10-19 Thread Keith Busch
This is a good cleanup, and I'd support this patch going in ahead of
this series on its own if you want to apply to 4.15 immediately.

Reviewed-by: Keith Busch 


Re: [PATCH 07/17] nvme: use ida_simple_{get,remove} for the controller instance

2017-10-19 Thread Johannes Thumshirn
Looks good,
Reviewed-by: Johannes Thumshirn 
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850


[PATCH 07/17] nvme: use ida_simple_{get,remove} for the controller instance

2017-10-18 Thread Christoph Hellwig
Switch to the ida_simple_* helpers instead of opencoding them.

Signed-off-by: Christoph Hellwig 
---
 drivers/nvme/host/core.c | 40 +++-
 1 file changed, 7 insertions(+), 33 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 573cc3b59bfa..bdae1e4fcd0b 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -74,6 +74,8 @@ EXPORT_SYMBOL_GPL(nvme_wq);
 static LIST_HEAD(nvme_ctrl_list);
 static DEFINE_SPINLOCK(dev_list_lock);
 
+static DEFINE_IDA(nvme_instance_ida);
+
 static struct class *nvme_class;
 
 static __le32 nvme_get_log_dw10(u8 lid, size_t size)
@@ -2696,35 +2698,6 @@ void nvme_queue_async_events(struct nvme_ctrl *ctrl)
 }
 EXPORT_SYMBOL_GPL(nvme_queue_async_events);
 
-static DEFINE_IDA(nvme_instance_ida);
-
-static int nvme_set_instance(struct nvme_ctrl *ctrl)
-{
-   int instance, error;
-
-   do {
-   if (!ida_pre_get(_instance_ida, GFP_KERNEL))
-   return -ENODEV;
-
-   spin_lock(_list_lock);
-   error = ida_get_new(_instance_ida, );
-   spin_unlock(_list_lock);
-   } while (error == -EAGAIN);
-
-   if (error)
-   return -ENODEV;
-
-   ctrl->instance = instance;
-   return 0;
-}
-
-static void nvme_release_instance(struct nvme_ctrl *ctrl)
-{
-   spin_lock(_list_lock);
-   ida_remove(_instance_ida, ctrl->instance);
-   spin_unlock(_list_lock);
-}
-
 void nvme_stop_ctrl(struct nvme_ctrl *ctrl)
 {
nvme_stop_keep_alive(ctrl);
@@ -2762,7 +2735,7 @@ static void nvme_free_ctrl(struct kref *kref)
struct nvme_ctrl *ctrl = container_of(kref, struct nvme_ctrl, kref);
 
put_device(ctrl->device);
-   nvme_release_instance(ctrl);
+   ida_simple_remove(_instance_ida, ctrl->instance);
ida_destroy(>ns_ida);
 
ctrl->ops->free_ctrl(ctrl);
@@ -2796,9 +2769,10 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device 
*dev,
INIT_WORK(>async_event_work, nvme_async_event_work);
INIT_WORK(>fw_act_work, nvme_fw_act_work);
 
-   ret = nvme_set_instance(ctrl);
-   if (ret)
+   ret = ida_simple_get(_instance_ida, 0, 0, GFP_KERNEL);
+   if (ret < 0)
goto out;
+   ctrl->instance = ret;
 
ctrl->device = device_create_with_groups(nvme_class, ctrl->dev,
MKDEV(nvme_char_major, ctrl->instance),
@@ -2825,7 +2799,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device 
*dev,
 
return 0;
 out_release_instance:
-   nvme_release_instance(ctrl);
+   ida_simple_remove(_instance_ida, ctrl->instance);
 out:
return ret;
 }
-- 
2.14.1