aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/core.c
diff options
context:
space:
mode:
authorCornelia Huck <cornelia.huck@de.ibm.com>2006-11-16 09:42:07 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-12-01 17:52:01 -0500
commit5ab699810d46011ad2195c5916f3cbc684bfe3ee (patch)
tree991f6d4f502fd7871766b51a94a0e3ab33aadd62 /drivers/base/core.c
parent035ed7a49447bc8e15d4d9316fc6a359b2d94333 (diff)
driver core: Introduce device_find_child().
Introduce device_find_child() to match device_for_each_child(). Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/core.c')
-rw-r--r--drivers/base/core.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 5d11bbdfbd2..a29e6854546 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -750,12 +750,45 @@ int device_for_each_child(struct device * parent, void * data,
750 return error; 750 return error;
751} 751}
752 752
753/**
754 * device_find_child - device iterator for locating a particular device.
755 * @parent: parent struct device
756 * @data: Data to pass to match function
757 * @match: Callback function to check device
758 *
759 * This is similar to the device_for_each_child() function above, but it
760 * returns a reference to a device that is 'found' for later use, as
761 * determined by the @match callback.
762 *
763 * The callback should return 0 if the device doesn't match and non-zero
764 * if it does. If the callback returns non-zero and a reference to the
765 * current device can be obtained, this function will return to the caller
766 * and not iterate over any more devices.
767 */
768struct device * device_find_child(struct device *parent, void *data,
769 int (*match)(struct device *, void *))
770{
771 struct klist_iter i;
772 struct device *child;
773
774 if (!parent)
775 return NULL;
776
777 klist_iter_init(&parent->klist_children, &i);
778 while ((child = next_device(&i)))
779 if (match(child, data) && get_device(child))
780 break;
781 klist_iter_exit(&i);
782 return child;
783}
784
753int __init devices_init(void) 785int __init devices_init(void)
754{ 786{
755 return subsystem_register(&devices_subsys); 787 return subsystem_register(&devices_subsys);
756} 788}
757 789
758EXPORT_SYMBOL_GPL(device_for_each_child); 790EXPORT_SYMBOL_GPL(device_for_each_child);
791EXPORT_SYMBOL_GPL(device_find_child);
759 792
760EXPORT_SYMBOL_GPL(device_initialize); 793EXPORT_SYMBOL_GPL(device_initialize);
761EXPORT_SYMBOL_GPL(device_add); 794EXPORT_SYMBOL_GPL(device_add);