Skip to content

Commit cfcf6a9

Browse files
gonzoleemangregkh
authored andcommitted
base: soc: siplify ida usage
Simplify ida index allocation and removal by using the ida_simple_* helper functions Signed-off-by: Lee Duncan <lduncan@suse.com> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fa40ae3 commit cfcf6a9

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

drivers/base/soc.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <linux/err.h>
1717

1818
static DEFINE_IDA(soc_ida);
19-
static DEFINE_SPINLOCK(soc_lock);
2019

2120
static ssize_t soc_info_get(struct device *dev,
2221
struct device_attribute *attr,
@@ -122,20 +121,10 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
122121
}
123122

124123
/* Fetch a unique (reclaimable) SOC ID. */
125-
do {
126-
if (!ida_pre_get(&soc_ida, GFP_KERNEL)) {
127-
ret = -ENOMEM;
128-
goto out2;
129-
}
130-
131-
spin_lock(&soc_lock);
132-
ret = ida_get_new(&soc_ida, &soc_dev->soc_dev_num);
133-
spin_unlock(&soc_lock);
134-
135-
} while (ret == -EAGAIN);
136-
137-
if (ret)
124+
ret = ida_simple_get(&soc_ida, 0, 0, GFP_KERNEL);
125+
if (ret < 0)
138126
goto out2;
127+
soc_dev->soc_dev_num = ret;
139128

140129
soc_dev->attr = soc_dev_attr;
141130
soc_dev->dev.bus = &soc_bus_type;
@@ -151,7 +140,7 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
151140
return soc_dev;
152141

153142
out3:
154-
ida_remove(&soc_ida, soc_dev->soc_dev_num);
143+
ida_simple_remove(&soc_ida, soc_dev->soc_dev_num);
155144
out2:
156145
kfree(soc_dev);
157146
out1:
@@ -161,7 +150,7 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
161150
/* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
162151
void soc_device_unregister(struct soc_device *soc_dev)
163152
{
164-
ida_remove(&soc_ida, soc_dev->soc_dev_num);
153+
ida_simple_remove(&soc_ida, soc_dev->soc_dev_num);
165154

166155
device_unregister(&soc_dev->dev);
167156
}

0 commit comments

Comments
 (0)