aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ibmaem.c
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@cam.ac.uk>2011-10-31 20:10:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-31 20:30:51 -0400
commit65807044760e03ebf766973c5e94a2ea1d57937b (patch)
tree51795f5484b08b90d523655ecd214866ee8958ee /drivers/hwmon/ibmaem.c
parent4ca5f468cc2a0be1cba585f335dcbe56b40944f2 (diff)
drivers/hwmon/hwmon.c: convert idr to ida and use ida_simple_get()
A straightforward looking use of idr for a device id. Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Tejun Heo <tj@kernel.org> Cc: Guenter Roeck <guenter.roeck@ericsson.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Acked-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/hwmon/ibmaem.c')
-rw-r--r--drivers/hwmon/ibmaem.c47
1 files changed, 8 insertions, 39 deletions
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index c316294c48b4..783d0c17b762 100644
--- a/drivers/hwmon/ibmaem.c
+++ b/drivers/hwmon/ibmaem.c
@@ -88,8 +88,7 @@
88#define AEM_MIN_POWER_INTERVAL 200 88#define AEM_MIN_POWER_INTERVAL 200
89#define UJ_PER_MJ 1000L 89#define UJ_PER_MJ 1000L
90 90
91static DEFINE_IDR(aem_idr); 91static DEFINE_IDA(aem_ida);
92static DEFINE_SPINLOCK(aem_idr_lock);
93 92
94static struct platform_driver aem_driver = { 93static struct platform_driver aem_driver = {
95 .driver = { 94 .driver = {
@@ -356,38 +355,6 @@ static void aem_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
356 complete(&data->read_complete); 355 complete(&data->read_complete);
357} 356}
358 357
359/* ID functions */
360
361/* Obtain an id */
362static int aem_idr_get(int *id)
363{
364 int i, err;
365
366again:
367 if (unlikely(!idr_pre_get(&aem_idr, GFP_KERNEL)))
368 return -ENOMEM;
369
370 spin_lock(&aem_idr_lock);
371 err = idr_get_new(&aem_idr, NULL, &i);
372 spin_unlock(&aem_idr_lock);
373
374 if (unlikely(err == -EAGAIN))
375 goto again;
376 else if (unlikely(err))
377 return err;
378
379 *id = i & MAX_ID_MASK;
380 return 0;
381}
382
383/* Release an object ID */
384static void aem_idr_put(int id)
385{
386 spin_lock(&aem_idr_lock);
387 idr_remove(&aem_idr, id);
388 spin_unlock(&aem_idr_lock);
389}
390
391/* Sensor support functions */ 358/* Sensor support functions */
392 359
393/* Read a sensor value */ 360/* Read a sensor value */
@@ -530,7 +497,7 @@ static void aem_delete(struct aem_data *data)
530 ipmi_destroy_user(data->ipmi.user); 497 ipmi_destroy_user(data->ipmi.user);
531 platform_set_drvdata(data->pdev, NULL); 498 platform_set_drvdata(data->pdev, NULL);
532 platform_device_unregister(data->pdev); 499 platform_device_unregister(data->pdev);
533 aem_idr_put(data->id); 500 ida_simple_remove(&aem_ida, data->id);
534 kfree(data); 501 kfree(data);
535} 502}
536 503
@@ -587,7 +554,8 @@ static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle)
587 data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; 554 data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL;
588 555
589 /* Create sub-device for this fw instance */ 556 /* Create sub-device for this fw instance */
590 if (aem_idr_get(&data->id)) 557 data->id = ida_simple_get(&aem_ida, 0, 0, GFP_KERNEL);
558 if (data->id < 0)
591 goto id_err; 559 goto id_err;
592 560
593 data->pdev = platform_device_alloc(DRVNAME, data->id); 561 data->pdev = platform_device_alloc(DRVNAME, data->id);
@@ -638,7 +606,7 @@ ipmi_err:
638 platform_set_drvdata(data->pdev, NULL); 606 platform_set_drvdata(data->pdev, NULL);
639 platform_device_unregister(data->pdev); 607 platform_device_unregister(data->pdev);
640dev_err: 608dev_err:
641 aem_idr_put(data->id); 609 ida_simple_remove(&aem_ida, data->id);
642id_err: 610id_err:
643 kfree(data); 611 kfree(data);
644 612
@@ -720,7 +688,8 @@ static int aem_init_aem2_inst(struct aem_ipmi_data *probe,
720 data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; 688 data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL;
721 689
722 /* Create sub-device for this fw instance */ 690 /* Create sub-device for this fw instance */
723 if (aem_idr_get(&data->id)) 691 data->id = ida_simple_get(&aem_ida, 0, 0, GFP_KERNEL);
692 if (data->id < 0)
724 goto id_err; 693 goto id_err;
725 694
726 data->pdev = platform_device_alloc(DRVNAME, data->id); 695 data->pdev = platform_device_alloc(DRVNAME, data->id);
@@ -771,7 +740,7 @@ ipmi_err:
771 platform_set_drvdata(data->pdev, NULL); 740 platform_set_drvdata(data->pdev, NULL);
772 platform_device_unregister(data->pdev); 741 platform_device_unregister(data->pdev);
773dev_err: 742dev_err:
774 aem_idr_put(data->id); 743 ida_simple_remove(&aem_ida, data->id);
775id_err: 744id_err:
776 kfree(data); 745 kfree(data);
777 746