[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201104193051.32236-9-brgl@bgdev.pl>
Date: Wed, 4 Nov 2020 20:30:51 +0100
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Linus Walleij <linus.walleij@...aro.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Jan Kiszka <jan.kiszka@...mens.com>,
David Laight <David.Laight@...lab.com>,
Mark Brown <broonie@...nel.org>
Cc: linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org,
Bartosz Golaszewski <bgolaszewski@...libre.com>
Subject: [PATCH v2 8/8] gpio: exar: use devm action for freeing the IDA and drop remove()
From: Bartosz Golaszewski <bgolaszewski@...libre.com>
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@...libre.com>
---
drivers/gpio/gpio-exar.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c
index 94ef500567ef..b3372279188d 100644
--- a/drivers/gpio/gpio-exar.c
+++ b/drivers/gpio/gpio-exar.c
@@ -108,6 +108,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 = 8,
@@ -155,6 +162,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;
@@ -171,29 +182,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,
},
--
2.29.1
Powered by blists - more mailing lists