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

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>

+4 -15
+4 -15
drivers/gpio/gpiolib-devres.c
··· 477 477 } 478 478 EXPORT_SYMBOL_GPL(devm_gpio_free); 479 479 480 - static void devm_gpio_chip_release(struct device *dev, void *res) 480 + static void devm_gpio_chip_release(void *data) 481 481 { 482 - struct gpio_chip *gc = *(struct gpio_chip **)res; 482 + struct gpio_chip *gc = data; 483 483 484 484 gpiochip_remove(gc); 485 485 } ··· 505 505 struct lock_class_key *lock_key, 506 506 struct lock_class_key *request_key) 507 507 { 508 - struct gpio_chip **ptr; 509 508 int ret; 510 509 511 - ptr = devres_alloc(devm_gpio_chip_release, sizeof(*ptr), 512 - GFP_KERNEL); 513 - if (!ptr) 514 - return -ENOMEM; 515 - 516 510 ret = gpiochip_add_data_with_key(gc, data, lock_key, request_key); 517 - if (ret < 0) { 518 - devres_free(ptr); 511 + if (ret < 0) 519 512 return ret; 520 - } 521 513 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); 526 515 } 527 516 EXPORT_SYMBOL_GPL(devm_gpiochip_add_data_with_key);