forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Tested-by: John Stultz <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]"); | ||
MODULE_DESCRIPTION("System reboot mode core library"); | ||
MODULE_LICENSE("GPL v2"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters