]> www.infradead.org Git - users/willy/xarray.git/commitdiff
powercap: Convert IDRs to IDAs
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 21:23:11 +0000 (16:23 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:18 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/powercap/powercap_sys.c
include/linux/powercap.h

index f808c5fa9838ce3b7cd8272b27c1aa38841c9f90..4fff639aa87d0e70e16c4dd58d7a416a3dcdeb52 100644 (file)
@@ -392,10 +392,10 @@ static void powercap_release(struct device *dev)
 
                /* Store flag as the release() may free memory */
                allocated = power_zone->allocated;
-               /* Remove id from parent idr struct */
-               idr_remove(power_zone->parent_idr, power_zone->id);
-               /* Destroy idrs allocated for this zone */
-               idr_destroy(&power_zone->idr);
+               /* Free id in parent's allocator */
+               ida_free(power_zone->parent_ids, power_zone->id);
+               /* Destroy ids allocated for this zone */
+               ida_destroy(&power_zone->ids);
                kfree(power_zone->name);
                kfree(power_zone->zone_dev_attrs);
                kfree(power_zone->constraints);
@@ -409,7 +409,7 @@ static void powercap_release(struct device *dev)
 
                /* Store flag as the release() may free memory */
                allocated = control_type->allocated;
-               idr_destroy(&control_type->idr);
+               ida_destroy(&control_type->ids);
                mutex_destroy(&control_type->lock);
                if (control_type->ops && control_type->ops->release)
                        control_type->ops->release(control_type);
@@ -511,21 +511,20 @@ struct powercap_zone *powercap_register_zone(
        power_zone->control_type_inst = control_type;
        if (!parent) {
                power_zone->dev.parent = &control_type->dev;
-               power_zone->parent_idr = &control_type->idr;
+               power_zone->parent_ids = &control_type->ids;
        } else {
                power_zone->dev.parent = &parent->dev;
-               power_zone->parent_idr = &parent->idr;
+               power_zone->parent_ids = &parent->ids;
        }
        power_zone->dev.class = &powercap_class;
 
        mutex_lock(&control_type->lock);
-       /* Using idr to get the unique id */
-       result = idr_alloc(power_zone->parent_idr, NULL, 0, 0, GFP_KERNEL);
+       result = ida_alloc(power_zone->parent_ids, GFP_KERNEL);
        if (result < 0)
-               goto err_idr_alloc;
+               goto err_id_alloc;
 
        power_zone->id = result;
-       idr_init(&power_zone->idr);
+       ida_init(&power_zone->ids);
        result = -ENOMEM;
        power_zone->name = kstrdup(name, GFP_KERNEL);
        if (!power_zone->name)
@@ -571,8 +570,8 @@ err_attr_alloc:
 err_const_alloc:
        kfree(power_zone->name);
 err_name_alloc:
-       idr_remove(power_zone->parent_idr, power_zone->id);
-err_idr_alloc:
+       ida_free(power_zone->parent_ids, power_zone->id);
+err_id_alloc:
        if (power_zone->allocated)
                kfree(power_zone);
        mutex_unlock(&control_type->lock);
@@ -627,7 +626,7 @@ struct powercap_control_type *powercap_register_control_type(
                        kfree(control_type);
                return ERR_PTR(result);
        }
-       idr_init(&control_type->idr);
+       ida_init(&control_type->ids);
 
        mutex_lock(&powercap_cntrl_list_lock);
        list_add_tail(&control_type->node, &powercap_cntrl_list);
index 4537f57f9e42f7a1441b54f96f79128d274234cc..5ae49af17d8662b9557e4a92a87cf001a59b25a7 100644 (file)
@@ -47,7 +47,7 @@ struct powercap_control_type_ops {
  * struct powercap_control_type- Defines a powercap control_type
  * @name:              name of control_type
  * @dev:               device for this control_type
- * @idr:               idr to have unique id for its child
+ * @ids:               ID allocator for children
  * @root_node:         Root holding power zones for this control_type
  * @ops:               Pointer to callback struct
  * @node_lock:         mutex for control type
@@ -64,7 +64,7 @@ struct powercap_control_type_ops {
  */
 struct powercap_control_type {
        struct device dev;
-       struct idr idr;
+       struct ida ids;
        int nr_zones;
        const struct powercap_control_type_ops *ops;
        struct mutex lock;
@@ -111,14 +111,14 @@ struct powercap_zone_ops {
 #define MAX_CONSTRAINTS_PER_ZONE       10
 /**
  * struct powercap_zone- Defines instance of a power cap zone
- * @id:                        Unique id
+ * @id:                        Unique id within parent's zone.
  * @name:              Power zone name.
  * @control_type_inst: Control type instance for this zone.
  * @ops:               Pointer to the zone operation structure.
  * @dev:               Instance of a device.
  * @const_id_cnt:      Number of constraint defined.
- * @idr:               Instance to an idr entry for children zones.
- * @parent_idr:                To remove reference from the parent idr.
+ * @ids:               ID allocation for child zones
+ * @parent_ids:                Parent's ID allocator
  * @private_data:      Private data pointer if any for this zone.
  * @zone_dev_attrs:    Attributes associated with this device.
  * @zone_attr_count:   Attribute count.
@@ -141,8 +141,8 @@ struct powercap_zone {
        const struct powercap_zone_ops *ops;
        struct device dev;
        int const_id_cnt;
-       struct idr idr;
-       struct idr *parent_idr;
+       struct ida ids;
+       struct ida *parent_ids;
        void *private_data;
        struct attribute **zone_dev_attrs;
        int zone_attr_count;