Re: drivers/base/core.c: about device_find_child() function

From: Federico Vaga
Date: Mon Apr 15 2013 - 04:51:33 EST


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/