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>
This commit is contained in:
parent
37174f3341
commit
3c6e73e47a
drivers/gpio
|
@ -477,9 +477,9 @@ void devm_gpio_free(struct device *dev, unsigned int gpio)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_gpio_free);
|
EXPORT_SYMBOL_GPL(devm_gpio_free);
|
||||||
|
|
||||||
static void devm_gpio_chip_release(struct device *dev, void *res)
|
static void devm_gpio_chip_release(void *data)
|
||||||
{
|
{
|
||||||
struct gpio_chip *gc = *(struct gpio_chip **)res;
|
struct gpio_chip *gc = data;
|
||||||
|
|
||||||
gpiochip_remove(gc);
|
gpiochip_remove(gc);
|
||||||
}
|
}
|
||||||
|
@ -505,23 +505,12 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, vo
|
||||||
struct lock_class_key *lock_key,
|
struct lock_class_key *lock_key,
|
||||||
struct lock_class_key *request_key)
|
struct lock_class_key *request_key)
|
||||||
{
|
{
|
||||||
struct gpio_chip **ptr;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ptr = devres_alloc(devm_gpio_chip_release, sizeof(*ptr),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!ptr)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
ret = gpiochip_add_data_with_key(gc, data, lock_key, request_key);
|
ret = gpiochip_add_data_with_key(gc, data, lock_key, request_key);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
devres_free(ptr);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
*ptr = gc;
|
return devm_add_action_or_reset(dev, devm_gpio_chip_release, gc);
|
||||||
devres_add(dev, ptr);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_gpiochip_add_data_with_key);
|
EXPORT_SYMBOL_GPL(devm_gpiochip_add_data_with_key);
|
||||||
|
|
Loading…
Reference in New Issue