/* 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);
/* 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);
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)
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);
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);
* 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
*/
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;
#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.
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;