10 #include <linux/device.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
19 #ifdef CONFIG_DEBUG_DEVRES
38 #ifdef CONFIG_DEBUG_DEVRES
39 static int log_devres = 0;
53 dev_printk(
KERN_ERR, dev,
"DEVRES %3s %p %s (%lu bytes)\n",
54 op, node, node->name, (
unsigned long)node->size);
57 #define set_node_dbginfo(node, n, s) do {} while (0)
58 #define devres_log(dev, node, op) do {} while (0)
65 static void group_open_release(
struct device *dev,
void *
res)
70 static void group_close_release(
struct device *dev,
void *
res)
77 if (node->
release == &group_open_release)
79 if (node->
release == &group_close_release)
87 size_t tot_size =
sizeof(
struct devres) + size;
95 INIT_LIST_HEAD(&dr->
node.entry);
107 #ifdef CONFIG_DEBUG_DEVRES
113 dr = alloc_dr(release, size, gfp);
138 dr = alloc_dr(release, size, gfp);
163 void (*
fn)(
struct device *,
void *,
void *),
180 if (match && !
match(dev, dr->
data, match_data))
220 add_dr(dev, &dr->
node);
235 if (match && !
match(dev, dr->
data, match_data))
264 dr = find_dr(dev, release, match, match_data);
295 dr = find_dr(dev, new_dr->
node.release, match, match_data);
297 add_dr(dev, &new_dr->
node);
330 dr = find_dr(dev, release, match, match_data);
332 list_del_init(&dr->
node.entry);
406 static int remove_nodes(
struct device *dev,
410 int cnt = 0, nr_groups = 0;
424 grp = node_to_group(node);
431 if (&node->
entry == first)
433 list_move_tail(&node->
entry, todo);
455 grp = node_to_group(node);
456 BUG_ON(!grp || list_empty(&grp->
node[0].entry));
459 if (list_empty(&grp->
node[1].entry))
463 if (grp->
color == 2) {
467 list_move_tail(&grp->
node[0].entry, todo);
468 list_del_init(&grp->
node[1].entry);
483 cnt = remove_nodes(dev, first, end, &todo);
536 grp =
kmalloc(
sizeof(*grp), gfp);
540 grp->
node[0].release = &group_open_release;
541 grp->
node[1].release = &group_close_release;
542 INIT_LIST_HEAD(&grp->
node[0].entry);
543 INIT_LIST_HEAD(&grp->
node[1].entry);
551 add_dr(dev, &grp->
node[0]);
565 if (node->
release != &group_open_release)
573 }
else if (list_empty(&grp->
node[1].entry))
595 grp = find_group(dev,
id);
597 add_dr(dev, &grp->
node[1]);
621 grp = find_group(dev,
id);
623 list_del_init(&grp->
node[0].entry);
624 list_del_init(&grp->
node[1].entry);
655 grp = find_group(dev,
id);
660 if (!list_empty(&grp->
node[1].entry))
661 end = grp->
node[1].entry.next;
663 cnt = release_nodes(dev, first, end, flags);
676 static void devm_kzalloc_release(
struct device *dev,
void *
res)
681 static int devm_kzalloc_match(
struct device *dev,
void *
res,
void *
data)
704 dr = alloc_dr(devm_kzalloc_release, size, gfp);
725 rc =
devres_destroy(dev, devm_kzalloc_release, devm_kzalloc_match, p);