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

From: Lars-Peter Clausen
Date: Sat Apr 13 2013 - 04:00:20 EST


On 04/12/2013 02:09 PM, Federico Vaga wrote:
> [...]
>
> [**] (argumentation based, obviously, on my limited understanding)
>
> These drivers work like this:
>
> child = device_find_child(parent, data, match_function);
> if (child) {
> put_device(child);
> <do something unrelated with child>
> }
>
> In these cases we do not need to get_device(). But we need to know if there
> is a child that match a rule. It can also "disapper" after the
> put_device(child) but the driver continues on its way because it does not
> use the child. For example virtio_rpmsg_bus.c:
>
> /* make sure a similar channel doesn't already exist */
> tmp = device_find_child(dev, chinfo, rpmsg_channel_match);
> if (tmp) {
> /* decrement the matched device's refcount back */
> put_device(tmp);
> dev_err(dev, "channel %s:%x:%x already exist\n",
> chinfo->name, chinfo->src, chinfo->dst);
> return NULL;
> }

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?

- Lars
--
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/