Skip to content

Commit

Permalink
gpio: exar: use devm action for freeing the IDA and drop remove()
Browse files Browse the repository at this point in the history
We can simplify the error path in probe() and drop remove() entirely if
we provide a devm action for freeing the device ID.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  • Loading branch information
brgl committed Nov 25, 2020
1 parent 36fb721 commit 5300ebb
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions drivers/gpio/gpio-exar.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ static int exar_direction_input(struct gpio_chip *chip, unsigned int offset)
return 0;
}

static void exar_devm_ida_free(void *data)
{
struct exar_gpio_chip *exar_gpio = data;

ida_free(&ida_index, exar_gpio->index);
}

static const struct regmap_config exar_regmap_config = {
.name = "exar-gpio",
.reg_bits = 16,
Expand Down Expand Up @@ -158,6 +165,10 @@ static int gpio_exar_probe(struct platform_device *pdev)
if (index < 0)
return index;

ret = devm_add_action_or_reset(dev, exar_devm_ida_free, exar_gpio);
if (ret)
return ret;

sprintf(exar_gpio->name, "exar_gpio%d", index);
exar_gpio->gpio_chip.label = exar_gpio->name;
exar_gpio->gpio_chip.parent = dev;
Expand All @@ -173,29 +184,15 @@ static int gpio_exar_probe(struct platform_device *pdev)

ret = devm_gpiochip_add_data(dev, &exar_gpio->gpio_chip, exar_gpio);
if (ret)
goto err_destroy;
return ret;

platform_set_drvdata(pdev, exar_gpio);

return 0;

err_destroy:
ida_free(&ida_index, index);
return ret;
}

static int gpio_exar_remove(struct platform_device *pdev)
{
struct exar_gpio_chip *exar_gpio = platform_get_drvdata(pdev);

ida_free(&ida_index, exar_gpio->index);

return 0;
}

static struct platform_driver gpio_exar_driver = {
.probe = gpio_exar_probe,
.remove = gpio_exar_remove,
.driver = {
.name = DRIVER_NAME,
},
Expand Down

0 comments on commit 5300ebb

Please sign in to comment.