Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: acpi: Add managed variant of acpi_dev_add_driver_gpios()

Introduce device managed variant of acpi_dev_add_driver_gpios() and its
counterpart acpi_dev_remove_driver_gpios().

The functions in most cases are used in driver's ->probe() and
->remove() callbacks, that's why it's useful to have managed variant of
them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Rafael J. Wysocki <rjw@rjwysocki.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Andy Shevchenko and committed by
Linus Walleij
85c73d50 ff21378a

+42
+31
drivers/gpio/gpiolib-acpi.c
··· 362 362 } 363 363 EXPORT_SYMBOL_GPL(acpi_dev_add_driver_gpios); 364 364 365 + static void devm_acpi_dev_release_driver_gpios(struct device *dev, void *res) 366 + { 367 + acpi_dev_remove_driver_gpios(ACPI_COMPANION(dev)); 368 + } 369 + 370 + int devm_acpi_dev_add_driver_gpios(struct device *dev, 371 + const struct acpi_gpio_mapping *gpios) 372 + { 373 + void *res; 374 + int ret; 375 + 376 + res = devres_alloc(devm_acpi_dev_release_driver_gpios, 0, GFP_KERNEL); 377 + if (!res) 378 + return -ENOMEM; 379 + 380 + ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), gpios); 381 + if (ret) { 382 + devres_free(res); 383 + return ret; 384 + } 385 + devres_add(dev, res); 386 + return 0; 387 + } 388 + EXPORT_SYMBOL_GPL(devm_acpi_dev_add_driver_gpios); 389 + 390 + void devm_acpi_dev_remove_driver_gpios(struct device *dev) 391 + { 392 + WARN_ON(devres_release(dev, devm_acpi_dev_release_driver_gpios, NULL, NULL)); 393 + } 394 + EXPORT_SYMBOL_GPL(devm_acpi_dev_remove_driver_gpios); 395 + 365 396 static bool acpi_get_driver_gpio_data(struct acpi_device *adev, 366 397 const char *name, int index, 367 398 struct acpi_reference_args *args)
+11
include/linux/acpi.h
··· 952 952 adev->driver_gpios = NULL; 953 953 } 954 954 955 + int devm_acpi_dev_add_driver_gpios(struct device *dev, 956 + const struct acpi_gpio_mapping *gpios); 957 + void devm_acpi_dev_remove_driver_gpios(struct device *dev); 958 + 955 959 int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index); 956 960 #else 957 961 static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev, ··· 964 960 return -ENXIO; 965 961 } 966 962 static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {} 963 + 964 + static inline int devm_acpi_dev_add_driver_gpios(struct device *dev, 965 + const struct acpi_gpio_mapping *gpios) 966 + { 967 + return -ENXIO; 968 + } 969 + static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {} 967 970 968 971 static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) 969 972 {