spi: simplify devm_spi_register_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: Tian Tao <tiantao6@hisilicon.com> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/1617843307-53853-1-git-send-email-tiantao6@hisilicon.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
9b844b0871
commit
59ebbe40fb
1 changed files with 5 additions and 14 deletions
|
@ -2793,9 +2793,9 @@ free_bus_id:
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(spi_register_controller);
|
EXPORT_SYMBOL_GPL(spi_register_controller);
|
||||||
|
|
||||||
static void devm_spi_unregister(struct device *dev, void *res)
|
static void devm_spi_unregister(void *ctlr)
|
||||||
{
|
{
|
||||||
spi_unregister_controller(*(struct spi_controller **)res);
|
spi_unregister_controller(ctlr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2814,22 +2814,13 @@ static void devm_spi_unregister(struct device *dev, void *res)
|
||||||
int devm_spi_register_controller(struct device *dev,
|
int devm_spi_register_controller(struct device *dev,
|
||||||
struct spi_controller *ctlr)
|
struct spi_controller *ctlr)
|
||||||
{
|
{
|
||||||
struct spi_controller **ptr;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL);
|
|
||||||
if (!ptr)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
ret = spi_register_controller(ctlr);
|
ret = spi_register_controller(ctlr);
|
||||||
if (!ret) {
|
if (ret)
|
||||||
*ptr = ctlr;
|
return ret;
|
||||||
devres_add(dev, ptr);
|
|
||||||
} else {
|
|
||||||
devres_free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return devm_add_action_or_reset(dev, devm_spi_unregister, ctlr);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_spi_register_controller);
|
EXPORT_SYMBOL_GPL(devm_spi_register_controller);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue