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

gpiolib: legacy: Consolidate devm_gpio_*() with other legacy APIs

There is no reason to keep deprecated legacy API implementations
in the gpiolib-devres.c. Consolidate devm_gpio_*() with other legacy
APIs. While at it, clean up header inclusion block in gpiolib-devres.c.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240828151357.2677340-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

Andy Shevchenko and committed by
Bartosz Golaszewski
d25f9ab1 94bd9ce1

+94 -74
+8 -74
drivers/gpio/gpiolib-devres.c
··· 6 6 * Copyright (c) 2011 John Crispin <john@phrozen.org> 7 7 */ 8 8 9 - #include <linux/module.h> 10 - #include <linux/err.h> 11 - #include <linux/gpio.h> 12 - #include <linux/gpio/consumer.h> 13 9 #include <linux/device.h> 10 + #include <linux/err.h> 11 + #include <linux/export.h> 14 12 #include <linux/gfp.h> 13 + #include <linux/types.h> 14 + 15 + #include <linux/gpio/consumer.h> 15 16 16 17 #include "gpiolib.h" 18 + 19 + struct fwnode_handle; 20 + struct lock_class_key; 17 21 18 22 static void devm_gpiod_release(struct device *dev, void *res) 19 23 { ··· 357 353 devm_gpiod_match_array, &descs)); 358 354 } 359 355 EXPORT_SYMBOL_GPL(devm_gpiod_put_array); 360 - 361 - static void devm_gpio_release(struct device *dev, void *res) 362 - { 363 - unsigned *gpio = res; 364 - 365 - gpio_free(*gpio); 366 - } 367 - 368 - /** 369 - * devm_gpio_request - request a GPIO for a managed device 370 - * @dev: device to request the GPIO for 371 - * @gpio: GPIO to allocate 372 - * @label: the name of the requested GPIO 373 - * 374 - * Except for the extra @dev argument, this function takes the 375 - * same arguments and performs the same function as 376 - * gpio_request(). GPIOs requested with this function will be 377 - * automatically freed on driver detach. 378 - */ 379 - int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) 380 - { 381 - unsigned *dr; 382 - int rc; 383 - 384 - dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 385 - if (!dr) 386 - return -ENOMEM; 387 - 388 - rc = gpio_request(gpio, label); 389 - if (rc) { 390 - devres_free(dr); 391 - return rc; 392 - } 393 - 394 - *dr = gpio; 395 - devres_add(dev, dr); 396 - 397 - return 0; 398 - } 399 - EXPORT_SYMBOL_GPL(devm_gpio_request); 400 - 401 - /** 402 - * devm_gpio_request_one - request a single GPIO with initial setup 403 - * @dev: device to request for 404 - * @gpio: the GPIO number 405 - * @flags: GPIO configuration as specified by GPIOF_* 406 - * @label: a literal description string of this GPIO 407 - */ 408 - int devm_gpio_request_one(struct device *dev, unsigned gpio, 409 - unsigned long flags, const char *label) 410 - { 411 - unsigned *dr; 412 - int rc; 413 - 414 - dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 415 - if (!dr) 416 - return -ENOMEM; 417 - 418 - rc = gpio_request_one(gpio, flags, label); 419 - if (rc) { 420 - devres_free(dr); 421 - return rc; 422 - } 423 - 424 - *dr = gpio; 425 - devres_add(dev, dr); 426 - 427 - return 0; 428 - } 429 - EXPORT_SYMBOL_GPL(devm_gpio_request_one); 430 356 431 357 static void devm_gpio_chip_release(void *data) 432 358 {
+86
drivers/gpio/gpiolib-legacy.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/bitops.h> 3 + #include <linux/device.h> 4 + #include <linux/errno.h> 5 + #include <linux/export.h> 6 + #include <linux/gfp.h> 7 + 2 8 #include <linux/gpio/consumer.h> 3 9 #include <linux/gpio/driver.h> 4 10 ··· 80 74 return gpiod_request(desc, label); 81 75 } 82 76 EXPORT_SYMBOL_GPL(gpio_request); 77 + 78 + static void devm_gpio_release(struct device *dev, void *res) 79 + { 80 + unsigned *gpio = res; 81 + 82 + gpio_free(*gpio); 83 + } 84 + 85 + /** 86 + * devm_gpio_request - request a GPIO for a managed device 87 + * @dev: device to request the GPIO for 88 + * @gpio: GPIO to allocate 89 + * @label: the name of the requested GPIO 90 + * 91 + * Except for the extra @dev argument, this function takes the 92 + * same arguments and performs the same function as gpio_request(). 93 + * GPIOs requested with this function will be automatically freed 94 + * on driver detach. 95 + * 96 + * **DEPRECATED** This function is deprecated and must not be used in new code. 97 + * 98 + * Returns: 99 + * 0 on success, or negative errno on failure. 100 + */ 101 + int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) 102 + { 103 + unsigned *dr; 104 + int rc; 105 + 106 + dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 107 + if (!dr) 108 + return -ENOMEM; 109 + 110 + rc = gpio_request(gpio, label); 111 + if (rc) { 112 + devres_free(dr); 113 + return rc; 114 + } 115 + 116 + *dr = gpio; 117 + devres_add(dev, dr); 118 + 119 + return 0; 120 + } 121 + EXPORT_SYMBOL_GPL(devm_gpio_request); 122 + 123 + /** 124 + * devm_gpio_request_one - request a single GPIO with initial setup 125 + * @dev: device to request for 126 + * @gpio: the GPIO number 127 + * @flags: GPIO configuration as specified by GPIOF_* 128 + * @label: a literal description string of this GPIO 129 + * 130 + * **DEPRECATED** This function is deprecated and must not be used in new code. 131 + * 132 + * Returns: 133 + * 0 on success, or negative errno on failure. 134 + */ 135 + int devm_gpio_request_one(struct device *dev, unsigned gpio, 136 + unsigned long flags, const char *label) 137 + { 138 + unsigned *dr; 139 + int rc; 140 + 141 + dr = devres_alloc(devm_gpio_release, sizeof(unsigned), GFP_KERNEL); 142 + if (!dr) 143 + return -ENOMEM; 144 + 145 + rc = gpio_request_one(gpio, flags, label); 146 + if (rc) { 147 + devres_free(dr); 148 + return rc; 149 + } 150 + 151 + *dr = gpio; 152 + devres_add(dev, dr); 153 + 154 + return 0; 155 + } 156 + EXPORT_SYMBOL_GPL(devm_gpio_request_one);