public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Federico Vaga <federico.vaga@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org,
	Cornelia Huck <cornelia.huck@de.ibm.com>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	Alessandro Rubini <rubini@gnudd.com>
Subject: Re: drivers/base/core.c: about device_find_child() function
Date: Sat, 13 Apr 2013 09:59:15 +0200	[thread overview]
Message-ID: <51691053.7060707@metafoo.de> (raw)
In-Reply-To: <2849474.HO2K6X9Bdi@harkonnen>

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

  parent reply	other threads:[~2013-04-13  8:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 11:52 drivers/base/core.c: about device_find_child() function Federico Vaga
2013-04-11 13:48 ` Greg Kroah-Hartman
2013-04-12 12:09   ` Federico Vaga
2013-04-12 22:06     ` Greg Kroah-Hartman
2013-04-15  8:55       ` Federico Vaga
2013-04-13  7:59     ` Lars-Peter Clausen [this message]
2013-04-15  8:51       ` Federico Vaga

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51691053.7060707@metafoo.de \
    --to=lars@metafoo.de \
    --cc=cornelia.huck@de.ibm.com \
    --cc=federico.vaga@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rubini@gnudd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox