summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Davis <afd@ti.com>2024-12-03 00:15:15 +0300
committerSebastian Reichel <sebastian.reichel@collabora.com>2024-12-05 00:31:31 +0300
commitbea4395a04d2602e72f550e795c15e98e557b779 (patch)
tree8ca8e8b27d80ca151e0f972eef1e003e248118cf
parentdc509d8be38ffe4ff6d752bdb7913718318e83cd (diff)
downloadlinux-bea4395a04d2602e72f550e795c15e98e557b779.tar.xz
power: supply: ds2782: Switch to simpler IDA interface
We don't need to specify any ranges when allocating IDs so we can switch to ida_alloc() and ida_free() instead of idr_*. Signed-off-by: Andrew Davis <afd@ti.com> Link: https://lore.kernel.org/r/20241202211519.199635-1-afd@ti.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-rw-r--r--drivers/power/supply/ds2782_battery.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/drivers/power/supply/ds2782_battery.c b/drivers/power/supply/ds2782_battery.c
index 85aa9c465aa4..10428d781c18 100644
--- a/drivers/power/supply/ds2782_battery.c
+++ b/drivers/power/supply/ds2782_battery.c
@@ -63,8 +63,7 @@ struct ds278x_info {
int status; /* State Of Charge */
};
-static DEFINE_IDR(battery_id);
-static DEFINE_MUTEX(battery_lock);
+static DEFINE_IDA(battery_id);
static inline int ds278x_read_reg(struct ds278x_info *info, int reg, u8 *val)
{
@@ -322,9 +321,7 @@ static void ds278x_battery_remove(struct i2c_client *client)
kfree(info->battery_desc.name);
kfree(info);
- mutex_lock(&battery_lock);
- idr_remove(&battery_id, id);
- mutex_unlock(&battery_lock);
+ ida_free(&battery_id, id);
}
#ifdef CONFIG_PM_SLEEP
@@ -387,12 +384,9 @@ static int ds278x_battery_probe(struct i2c_client *client)
}
/* Get an ID for this battery */
- mutex_lock(&battery_lock);
- ret = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL);
- mutex_unlock(&battery_lock);
- if (ret < 0)
- goto fail_id;
- num = ret;
+ num = ida_alloc(&battery_id, GFP_KERNEL);
+ if (num < 0)
+ return num;
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info) {
@@ -439,10 +433,7 @@ fail_register:
fail_name:
kfree(info);
fail_info:
- mutex_lock(&battery_lock);
- idr_remove(&battery_id, num);
- mutex_unlock(&battery_lock);
-fail_id:
+ ida_free(&battery_id, num);
return ret;
}