@@ -495,7 +495,7 @@ static void gpiodevice_release(struct device *dev)
list_del(&gdev->list);
spin_unlock_irqrestore(&gpio_lock, flags);
- ida_free(&gpio_ida, gdev->id);
+ ida_simple_remove(&gpio_ida, gdev->id);
kfree_const(gdev->label);
kfree(gdev->descs);
kfree(gdev);
@@ -594,6 +594,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
unsigned long flags;
int base = gc->base;
unsigned int i;
+ int alias_id, first_dynamic;
int ret = 0;
u32 ngpios;
@@ -623,11 +624,20 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
*/
gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode;
- gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL);
- if (gdev->id < 0) {
- ret = gdev->id;
- goto err_free_gdev;
+ alias_id = of_alias_get_id(gdev->dev.of_node, "gpio");
+ if (alias_id < 0) {
+ first_dynamic = of_alias_get_highest_id("gpio");
+ if (first_dynamic < 0)
+ first_dynamic = 0;
+ else
+ first_dynamic++;
+ alias_id = ida_simple_get(&gpio_ida, first_dynamic, 0, GFP_KERNEL);
+ if (alias_id < 0) {
+ ret = alias_id;
+ goto err_free_gdev;
+ }
}
+ gdev->id = alias_id;
ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id);
if (ret)
@@ -821,7 +831,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
err_free_dev_name:
kfree(dev_name(&gdev->dev));
err_free_ida:
- ida_free(&gpio_ida, gdev->id);
+ ida_simple_remove(&gpio_ida, gdev->id);
err_free_gdev:
/* failures here can mean systems won't boot... */
if (ret != -EPROBE_DEFER) {