Skip to content

Commit 3c6e73e

Browse files
committed
gpiolib: devres: shrink devm_gpiochip_add_data_with_key()
If all we want to manage is a single pointer, there's no need to manually allocate and add a new devres. We can simply use devm_add_action_or_reset() and shrink the code by a good bit. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 37174f3 commit 3c6e73e

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

drivers/gpio/gpiolib-devres.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ void devm_gpio_free(struct device *dev, unsigned int gpio)
477477
}
478478
EXPORT_SYMBOL_GPL(devm_gpio_free);
479479

480-
static void devm_gpio_chip_release(struct device *dev, void *res)
480+
static void devm_gpio_chip_release(void *data)
481481
{
482-
struct gpio_chip *gc = *(struct gpio_chip **)res;
482+
struct gpio_chip *gc = data;
483483

484484
gpiochip_remove(gc);
485485
}
@@ -505,23 +505,12 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, vo
505505
struct lock_class_key *lock_key,
506506
struct lock_class_key *request_key)
507507
{
508-
struct gpio_chip **ptr;
509508
int ret;
510509

511-
ptr = devres_alloc(devm_gpio_chip_release, sizeof(*ptr),
512-
GFP_KERNEL);
513-
if (!ptr)
514-
return -ENOMEM;
515-
516510
ret = gpiochip_add_data_with_key(gc, data, lock_key, request_key);
517-
if (ret < 0) {
518-
devres_free(ptr);
511+
if (ret < 0)
519512
return ret;
520-
}
521513

522-
*ptr = gc;
523-
devres_add(dev, ptr);
524-
525-
return 0;
514+
return devm_add_action_or_reset(dev, devm_gpio_chip_release, gc);
526515
}
527516
EXPORT_SYMBOL_GPL(devm_gpiochip_add_data_with_key);

0 commit comments

Comments
 (0)