aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/devres.c
diff options
context:
space:
mode:
authorMing Lei <ming.lei@canonical.com>2012-08-04 00:01:26 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-16 16:30:29 -0400
commitbddb1b9078505bb0e430c87c5015c0963f7a594f (patch)
treeef3d3a201dd23633d5c2dad8fb00be82a35f3023 /drivers/base/devres.c
parentf531f05ae9437df5ba1ebd90017e4dd5526048e9 (diff)
driver core: devres: introduce devres_for_each_res
This patch introduces one devres API of devres_for_each_res so that the device's driver can iterate each resource it has interest in. The firmware loader will use the API to get each firmware name from the device instance. Signed-off-by: Ming Lei <ming.lei@canonical.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/devres.c')
-rw-r--r--drivers/base/devres.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 2360adb7a58f..8731979d668a 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -144,6 +144,48 @@ EXPORT_SYMBOL_GPL(devres_alloc);
144#endif 144#endif
145 145
146/** 146/**
147 * devres_for_each_res - Resource iterator
148 * @dev: Device to iterate resource from
149 * @release: Look for resources associated with this release function
150 * @match: Match function (optional)
151 * @match_data: Data for the match function
152 * @fn: Function to be called for each matched resource.
153 * @data: Data for @fn, the 3rd parameter of @fn
154 *
155 * Call @fn for each devres of @dev which is associated with @release
156 * and for which @match returns 1.
157 *
158 * RETURNS:
159 * void
160 */
161void devres_for_each_res(struct device *dev, dr_release_t release,
162 dr_match_t match, void *match_data,
163 void (*fn)(struct device *, void *, void *),
164 void *data)
165{
166 struct devres_node *node;
167 struct devres_node *tmp;
168 unsigned long flags;
169
170 if (!fn)
171 return;
172
173 spin_lock_irqsave(&dev->devres_lock, flags);
174 list_for_each_entry_safe_reverse(node, tmp,
175 &dev->devres_head, entry) {
176 struct devres *dr = container_of(node, struct devres, node);
177
178 if (node->release != release)
179 continue;
180 if (match && !match(dev, dr->data, match_data))
181 continue;
182 fn(dev, dr->data, data);
183 }
184 spin_unlock_irqrestore(&dev->devres_lock, flags);
185}
186EXPORT_SYMBOL_GPL(devres_for_each_res);
187
188/**
147 * devres_free - Free device resource data 189 * devres_free - Free device resource data
148 * @res: Pointer to devres data to free 190 * @res: Pointer to devres data to free
149 * 191 *