|
15 | 15 |
|
16 | 16 | #include "common.h"
|
17 | 17 |
|
| 18 | +static DEFINE_IDA(ffa_bus_id); |
| 19 | + |
18 | 20 | static int ffa_device_match(struct device *dev, struct device_driver *drv)
|
19 | 21 | {
|
20 | 22 | const struct ffa_device_id *id_table;
|
@@ -131,6 +133,7 @@ static void ffa_release_device(struct device *dev)
|
131 | 133 | {
|
132 | 134 | struct ffa_device *ffa_dev = to_ffa_dev(dev);
|
133 | 135 |
|
| 136 | + ida_free(&ffa_bus_id, ffa_dev->id); |
134 | 137 | kfree(ffa_dev);
|
135 | 138 | }
|
136 | 139 |
|
@@ -171,18 +174,24 @@ bool ffa_device_is_valid(struct ffa_device *ffa_dev)
|
171 | 174 | struct ffa_device *ffa_device_register(const uuid_t *uuid, int vm_id,
|
172 | 175 | const struct ffa_ops *ops)
|
173 | 176 | {
|
174 |
| - int ret; |
| 177 | + int id, ret; |
175 | 178 | struct device *dev;
|
176 | 179 | struct ffa_device *ffa_dev;
|
177 | 180 |
|
| 181 | + id = ida_alloc_min(&ffa_bus_id, 1, GFP_KERNEL); |
| 182 | + if (id < 0) |
| 183 | + return NULL; |
| 184 | + |
178 | 185 | ffa_dev = kzalloc(sizeof(*ffa_dev), GFP_KERNEL);
|
179 |
| - if (!ffa_dev) |
| 186 | + if (!ffa_dev) { |
| 187 | + ida_free(&ffa_bus_id, id); |
180 | 188 | return NULL;
|
| 189 | + } |
181 | 190 |
|
182 | 191 | dev = &ffa_dev->dev;
|
183 | 192 | dev->bus = &ffa_bus_type;
|
184 | 193 | dev->release = ffa_release_device;
|
185 |
| - dev_set_name(&ffa_dev->dev, "arm-ffa-%04x", vm_id); |
| 194 | + dev_set_name(&ffa_dev->dev, "arm-ffa-%d", id); |
186 | 195 |
|
187 | 196 | ffa_dev->vm_id = vm_id;
|
188 | 197 | ffa_dev->ops = ops;
|
@@ -218,4 +227,5 @@ void arm_ffa_bus_exit(void)
|
218 | 227 | {
|
219 | 228 | ffa_devices_unregister();
|
220 | 229 | bus_unregister(&ffa_bus_type);
|
| 230 | + ida_destroy(&ffa_bus_id); |
221 | 231 | }
|
0 commit comments