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

Configure Feed

Select the types of activity you want to include in your feed.

spi: Simplify devm_spi_*_controller()

Use devm_add_action_or_reset() instead of devres_alloc() and
devres_add(), which works the same. This will simplify the
code. There is no functional changes.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20260108175145.3535441-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Andy Shevchenko and committed by
Mark Brown
b6376dbe 19a4505a

+18 -29
+18 -29
drivers/spi/spi.c
··· 3079 3079 } 3080 3080 EXPORT_SYMBOL_GPL(__spi_alloc_controller); 3081 3081 3082 - static void devm_spi_release_controller(struct device *dev, void *ctlr) 3082 + static void devm_spi_release_controller(void *ctlr) 3083 3083 { 3084 - spi_controller_put(*(struct spi_controller **)ctlr); 3084 + spi_controller_put(ctlr); 3085 3085 } 3086 3086 3087 3087 /** ··· 3103 3103 unsigned int size, 3104 3104 bool target) 3105 3105 { 3106 - struct spi_controller **ptr, *ctlr; 3107 - 3108 - ptr = devres_alloc(devm_spi_release_controller, sizeof(*ptr), 3109 - GFP_KERNEL); 3110 - if (!ptr) 3111 - return NULL; 3106 + struct spi_controller *ctlr; 3107 + int ret; 3112 3108 3113 3109 ctlr = __spi_alloc_controller(dev, size, target); 3114 - if (ctlr) { 3115 - ctlr->devm_allocated = true; 3116 - *ptr = ctlr; 3117 - devres_add(dev, ptr); 3118 - } else { 3119 - devres_free(ptr); 3120 - } 3110 + if (!ctlr) 3111 + return NULL; 3112 + 3113 + ret = devm_add_action_or_reset(dev, devm_spi_release_controller, ctlr); 3114 + if (ret) 3115 + return NULL; 3116 + 3117 + ctlr->devm_allocated = true; 3121 3118 3122 3119 return ctlr; 3123 3120 } ··· 3375 3378 } 3376 3379 EXPORT_SYMBOL_GPL(spi_register_controller); 3377 3380 3378 - static void devm_spi_unregister(struct device *dev, void *res) 3381 + static void devm_spi_unregister_controller(void *ctlr) 3379 3382 { 3380 - spi_unregister_controller(*(struct spi_controller **)res); 3383 + spi_unregister_controller(ctlr); 3381 3384 } 3382 3385 3383 3386 /** ··· 3395 3398 int devm_spi_register_controller(struct device *dev, 3396 3399 struct spi_controller *ctlr) 3397 3400 { 3398 - struct spi_controller **ptr; 3399 3401 int ret; 3400 3402 3401 - ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL); 3402 - if (!ptr) 3403 - return -ENOMEM; 3404 - 3405 3403 ret = spi_register_controller(ctlr); 3406 - if (!ret) { 3407 - *ptr = ctlr; 3408 - devres_add(dev, ptr); 3409 - } else { 3410 - devres_free(ptr); 3411 - } 3404 + if (ret) 3405 + return ret; 3412 3406 3413 - return ret; 3407 + return devm_add_action_or_reset(dev, devm_spi_unregister_controller, ctlr); 3408 + 3414 3409 } 3415 3410 EXPORT_SYMBOL_GPL(devm_spi_register_controller); 3416 3411