Messages in this thread |  | | Date | Sat, 13 Apr 2013 09:59:15 +0200 | | From | Lars-Peter Clausen <> | | 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
|  |