Messages in this thread | | | From | Federico Vaga <> | Subject | Re: drivers/base/core.c: about device_find_child() function | Date | Mon, 15 Apr 2013 10:51:29 +0200 |
| |
Hi Lars,
> Considering that there seems to be a common pattern here where the caller > only wants to know if the device exists, but is not really interested in the > device itself, how about adding a helper function for this?
It was my first thought when I opened this thread. But now I'm convinced that device_for_each_child() is the best choice (maybe I'm wrong).
device_for_each_child() allow you to perform an operation of each child of a device: look for a specific child, do something on every children, retrieve a specific group of children, etc.
I think that an helper for this case will be a perfect duplication of device_for_each_child() with a different name and comment (borrowed from device_find_child()). Maybe, a macro to assign a different name to this function:
/* * [...] * The callback should return 0 if the device doesn't match and non-zero * if it does * [...] */ #define device_has_child(parent, data, match) device_for_each_child(parent, data, match)
But, is it useful? It can be a suggestion to developers to prefer device_for_each_child() instead of device_find_child() when (s)he is interested only about the child existence. So, (s)he does not need to put_device(). But I think that is not a strong argumentation, and later in time someone will propose his own special use of device_for_each_child().
I think that device_for_each_child() is generic enough to cover this problem.
-- Federico Vaga
| |