diff options
author | Luis R. Rodriguez <mcgrof@do-not-panic.com> | 2013-04-10 04:35:17 -0700 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2013-04-10 15:48:57 +0200 |
commit | 01cf5be5adde73c9370f8eaa8df313722a753ef0 (patch) | |
tree | 5eadee2b52e5a5519f3dd0536752f0df10f75639 /backport/compat/compat-3.5.c | |
parent | 8ed370d2b8834945a3487ccc9c9004e22ae4a79c (diff) |
compat: backport devres_release()
commit d926d0e4c74cfcb42a05e91d1cdf698b41e1e118
Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
Date: Thu May 3 18:15:13 2012 +0100
devres: Add devres_release()
APIs using devres frequently want to implement a "remove and free the
resource" operation so it seems sensible that they should be able to
just have devres do the freeing for them since that's a big part of what
devres is all about.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'backport/compat/compat-3.5.c')
-rw-r--r-- | backport/compat/compat-3.5.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/backport/compat/compat-3.5.c b/backport/compat/compat-3.5.c index d7f1c275..9cc8456c 100644 --- a/backport/compat/compat-3.5.c +++ b/backport/compat/compat-3.5.c @@ -12,6 +12,40 @@ #include <linux/highuid.h> #include <linux/ktime.h> +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0)) +#include <linux/device.h> + +/** + * devres_release - Find a device resource and destroy it, calling release + * @dev: Device to find resource from + * @release: Look for resources associated with this release function + * @match: Match function (optional) + * @match_data: Data for the match function + * + * Find the latest devres of @dev associated with @release and for + * which @match returns 1. If @match is NULL, it's considered to + * match all. If found, the resource is removed atomically, the + * release function called and the resource freed. + * + * RETURNS: + * 0 if devres is found and freed, -ENOENT if not found. + */ +int devres_release(struct device *dev, dr_release_t release, + dr_match_t match, void *match_data) +{ + void *res; + + res = devres_remove(dev, release, match, match_data); + if (unlikely(!res)) + return -ENOENT; + + (*release)(dev, res); + devres_free(res); + return 0; +} +EXPORT_SYMBOL_GPL(devres_release); +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0)) */ + /* * Commit 7a4e7408c5cadb240e068a662251754a562355e3 * exported overflowuid and overflowgid for all |