nvmem: core: Use devm_add_action_or_reset()

Slightly simplify the devm_nvmem_register() by using the
devm_add_action_or_reset().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20220220151527.17216-3-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Andy Shevchenko 2022-02-20 15:15:16 +00:00 committed by Greg Kroah-Hartman
parent 190fae4685
commit 5825b2c676
1 changed files with 9 additions and 13 deletions

View File

@ -907,9 +907,9 @@ void nvmem_unregister(struct nvmem_device *nvmem)
}
EXPORT_SYMBOL_GPL(nvmem_unregister);
static void devm_nvmem_release(struct device *dev, void *res)
static void devm_nvmem_unregister(void *nvmem)
{
nvmem_unregister(*(struct nvmem_device **)res);
nvmem_unregister(nvmem);
}
/**
@ -926,20 +926,16 @@ static void devm_nvmem_release(struct device *dev, void *res)
struct nvmem_device *devm_nvmem_register(struct device *dev,
const struct nvmem_config *config)
{
struct nvmem_device **ptr, *nvmem;
ptr = devres_alloc(devm_nvmem_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return ERR_PTR(-ENOMEM);
struct nvmem_device *nvmem;
int ret;
nvmem = nvmem_register(config);
if (IS_ERR(nvmem))
return nvmem;
if (!IS_ERR(nvmem)) {
*ptr = nvmem;
devres_add(dev, ptr);
} else {
devres_free(ptr);
}
ret = devm_add_action_or_reset(dev, devm_nvmem_unregister, nvmem);
if (ret)
return ERR_PTR(ret);
return nvmem;
}