From: Bjorn Andersson Date: Thu, 4 Aug 2016 05:04:05 +0000 (-0700) Subject: power: reset: reboot-mode: Add managed resource API X-Git-Tag: v4.9-rc1~100^2~38 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c1a9634f1aaf5e10c23f8890ea2e64c61d48cb44;p=platform%2Fkernel%2Flinux-exynos.git power: reset: reboot-mode: Add managed resource API Provide managed resource version of reboot_mode_register() and reboot_mode_unregister() to simplify implementations. Signed-off-by: Bjorn Andersson Tested-by: John Stultz Signed-off-by: Sebastian Reichel --- diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index b0d775d..b1ff0b7 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -342,6 +342,10 @@ PINCTRL devm_pinctrl_register() devm_pinctrl_unregister() +POWER + devm_reboot_mode_register() + devm_reboot_mode_unregister() + PWM devm_pwm_get() devm_pwm_put() diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c index 2dfbbce..fb51218 100644 --- a/drivers/power/reset/reboot-mode.c +++ b/drivers/power/reset/reboot-mode.c @@ -135,6 +135,65 @@ int reboot_mode_unregister(struct reboot_mode_driver *reboot) } EXPORT_SYMBOL_GPL(reboot_mode_unregister); +static void devm_reboot_mode_release(struct device *dev, void *res) +{ + reboot_mode_unregister(*(struct reboot_mode_driver **)res); +} + +/** + * devm_reboot_mode_register() - resource managed reboot_mode_register() + * @dev: device to associate this resource with + * @reboot: reboot mode driver + * + * Returns: 0 on success or a negative error code on failure. + */ +int devm_reboot_mode_register(struct device *dev, + struct reboot_mode_driver *reboot) +{ + struct reboot_mode_driver **dr; + int rc; + + dr = devres_alloc(devm_reboot_mode_release, sizeof(*dr), GFP_KERNEL); + if (!dr) + return -ENOMEM; + + rc = reboot_mode_register(reboot); + if (rc) { + devres_free(dr); + return rc; + } + + *dr = reboot; + devres_add(dev, dr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_reboot_mode_register); + +static int devm_reboot_mode_match(struct device *dev, void *res, void *data) +{ + struct reboot_mode_driver **p = res; + + if (WARN_ON(!p || !*p)) + return 0; + + return *p == data; +} + +/** + * devm_reboot_mode_unregister() - resource managed reboot_mode_unregister() + * @dev: device to associate this resource with + * @reboot: reboot mode driver + */ +void devm_reboot_mode_unregister(struct device *dev, + struct reboot_mode_driver *reboot) +{ + WARN_ON(devres_release(dev, + devm_reboot_mode_release, + devm_reboot_mode_match, reboot)); +} +EXPORT_SYMBOL_GPL(devm_reboot_mode_unregister); + MODULE_AUTHOR("Andy Yan