mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Federico Vaga <federico.vaga@gmail.com>
To: Lars-Peter Clausen <lars@metafoo.de>
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: Mon, 15 Apr 2013 10:51:29 +0200	[thread overview]
Message-ID: <227672966.BSYPVcyNU7@harkonnen> (raw)
In-Reply-To: <51691053.7060707@metafoo.de>

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

      reply	other threads:[~2013-04-15  8:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 11:52 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
2013-04-15  8:51       ` Federico Vaga [this message]

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=227672966.BSYPVcyNU7@harkonnen \
    --to=federico.vaga@gmail.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregkh@suse.de \
    --cc=lars@metafoo.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

all inboxes | Powered by JetHome®