[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <51691053.7060707@metafoo.de>
Date: Sat, 13 Apr 2013 09:59:15 +0200
From: Lars-Peter Clausen <lars@...afoo.de>
To: Federico Vaga <federico.vaga@...il.com>
CC: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-kernel@...r.kernel.org,
Cornelia Huck <cornelia.huck@...ibm.com>,
Greg Kroah-Hartman <gregkh@...e.de>,
Alessandro Rubini <rubini@...dd.com>
Subject: Re: drivers/base/core.c: about device_find_child() function
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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists