mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-29 15:14:18 +08:00
nvmem: Introduce devm_nvmem_(un)register()
Introduce devm_nvmem_register()/devm_nvmem_unregister() to make .remove() unnecessary in trivial drivers. Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Cc: Heiko Stuebner <heiko@sntech.de> Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Carlo Caione <carlo@caione.org> Cc: Kevin Hilman <khilman@baylibre.com> Cc: Matthias Brugger <matthias.bgg@gmail.com> Cc: cphealy@gmail.com Cc: linux-kernel@vger.kernel.org Cc: linux-mediatek@lists.infradead.org Cc: linux-rockchip@lists.infradead.org Cc: linux-amlogic@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
fd0f4906a3
commit
f1f50eca5f
@ -549,6 +549,65 @@ int nvmem_unregister(struct nvmem_device *nvmem)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(nvmem_unregister);
|
||||
|
||||
static void devm_nvmem_release(struct device *dev, void *res)
|
||||
{
|
||||
WARN_ON(nvmem_unregister(*(struct nvmem_device **)res));
|
||||
}
|
||||
|
||||
/**
|
||||
* devm_nvmem_register() - Register a managed nvmem device for given
|
||||
* nvmem_config.
|
||||
* Also creates an binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
|
||||
*
|
||||
* @config: nvmem device configuration with which nvmem device is created.
|
||||
*
|
||||
* Return: Will be an ERR_PTR() on error or a valid pointer to nvmem_device
|
||||
* on success.
|
||||
*/
|
||||
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);
|
||||
|
||||
nvmem = nvmem_register(config);
|
||||
|
||||
if (!IS_ERR(nvmem)) {
|
||||
*ptr = nvmem;
|
||||
devres_add(dev, ptr);
|
||||
} else {
|
||||
devres_free(ptr);
|
||||
}
|
||||
|
||||
return nvmem;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(devm_nvmem_register);
|
||||
|
||||
static int devm_nvmem_match(struct device *dev, void *res, void *data)
|
||||
{
|
||||
struct nvmem_device **r = res;
|
||||
|
||||
return *r == data;
|
||||
}
|
||||
|
||||
/**
|
||||
* devm_nvmem_unregister() - Unregister previously registered managed nvmem
|
||||
* device.
|
||||
*
|
||||
* @nvmem: Pointer to previously registered nvmem device.
|
||||
*
|
||||
* Return: Will be an negative on error or a zero on success.
|
||||
*/
|
||||
int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
|
||||
{
|
||||
return devres_release(dev, devm_nvmem_release, devm_nvmem_match, nvmem);
|
||||
}
|
||||
EXPORT_SYMBOL(devm_nvmem_unregister);
|
||||
|
||||
|
||||
static struct nvmem_device *__nvmem_device_get(struct device_node *np,
|
||||
struct nvmem_cell **cellp,
|
||||
const char *cell_id)
|
||||
|
@ -72,6 +72,11 @@ struct nvmem_config {
|
||||
struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
|
||||
int nvmem_unregister(struct nvmem_device *nvmem);
|
||||
|
||||
struct nvmem_device *devm_nvmem_register(struct device *dev,
|
||||
const struct nvmem_config *cfg);
|
||||
|
||||
int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem);
|
||||
|
||||
#else
|
||||
|
||||
static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
|
||||
@ -84,5 +89,17 @@ static inline int nvmem_unregister(struct nvmem_device *nvmem)
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
static inline struct nvmem_device *
|
||||
devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
|
||||
{
|
||||
return nvmem_register(c);
|
||||
}
|
||||
|
||||
static inline int
|
||||
devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem)
|
||||
{
|
||||
return nvmem_unregister(nvmem);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NVMEM */
|
||||
#endif /* ifndef _LINUX_NVMEM_PROVIDER_H */
|
||||
|
Loading…
Reference in New Issue
Block a user