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>
This commit is contained in:
parent
19a4505a7a
commit
b6376dbed8
|
|
@ -3079,9 +3079,9 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(__spi_alloc_controller);
|
||||
|
||||
static void devm_spi_release_controller(struct device *dev, void *ctlr)
|
||||
static void devm_spi_release_controller(void *ctlr)
|
||||
{
|
||||
spi_controller_put(*(struct spi_controller **)ctlr);
|
||||
spi_controller_put(ctlr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3103,21 +3103,18 @@ struct spi_controller *__devm_spi_alloc_controller(struct device *dev,
|
|||
unsigned int size,
|
||||
bool target)
|
||||
{
|
||||
struct spi_controller **ptr, *ctlr;
|
||||
|
||||
ptr = devres_alloc(devm_spi_release_controller, sizeof(*ptr),
|
||||
GFP_KERNEL);
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
struct spi_controller *ctlr;
|
||||
int ret;
|
||||
|
||||
ctlr = __spi_alloc_controller(dev, size, target);
|
||||
if (ctlr) {
|
||||
ctlr->devm_allocated = true;
|
||||
*ptr = ctlr;
|
||||
devres_add(dev, ptr);
|
||||
} else {
|
||||
devres_free(ptr);
|
||||
}
|
||||
if (!ctlr)
|
||||
return NULL;
|
||||
|
||||
ret = devm_add_action_or_reset(dev, devm_spi_release_controller, ctlr);
|
||||
if (ret)
|
||||
return NULL;
|
||||
|
||||
ctlr->devm_allocated = true;
|
||||
|
||||
return ctlr;
|
||||
}
|
||||
|
|
@ -3378,9 +3375,9 @@ free_bus_id:
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(spi_register_controller);
|
||||
|
||||
static void devm_spi_unregister(struct device *dev, void *res)
|
||||
static void devm_spi_unregister_controller(void *ctlr)
|
||||
{
|
||||
spi_unregister_controller(*(struct spi_controller **)res);
|
||||
spi_unregister_controller(ctlr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3398,22 +3395,14 @@ static void devm_spi_unregister(struct device *dev, void *res)
|
|||
int devm_spi_register_controller(struct device *dev,
|
||||
struct spi_controller *ctlr)
|
||||
{
|
||||
struct spi_controller **ptr;
|
||||
int ret;
|
||||
|
||||
ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL);
|
||||
if (!ptr)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = spi_register_controller(ctlr);
|
||||
if (!ret) {
|
||||
*ptr = ctlr;
|
||||
devres_add(dev, ptr);
|
||||
} else {
|
||||
devres_free(ptr);
|
||||
}
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return devm_add_action_or_reset(dev, devm_spi_unregister_controller, ctlr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(devm_spi_register_controller);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue