LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: Dave Young <hidave.darkstar@gmail.com>
Cc: Greg KH <gregkh@suse.de>,
	Stefan Richter <stefanr@s5r6.in-berlin.de>,
	James.Bottomley@hansenpartnership.com,
	linux-scsi@vger.kernel.org, a.zummo@towertech.it,
	peterz@infradead.org, cbou@mail.ru, linux-kernel@vger.kernel.org,
	David Brownell <david-b@pacbell.net>,
	krh@redhat.com, stern@rowland.harvard.edu,
	rtc-linux@googlegroups.com,
	spi-devel-general@lists.sourceforge.net,
	linux1394-devel@lists.sourceforge.net, dwmw2@infradead.org,
	davem@davemloft.net, jarkao2@gmail.com
Subject: Re: [PATCH 0/7] convert semaphore to mutex in struct class
Date: Thu, 10 Jan 2008 14:23:41 +0100	[thread overview]
Message-ID: <20080110142341.71af4dc5@gondolin.boeblingen.de.ibm.com> (raw)
In-Reply-To: <20080110094843.GA3014@darkstar.te-china.tietoenator.com>

On Thu, 10 Jan 2008 17:48:43 +0800,
Dave Young <hidave.darkstar@gmail.com> wrote:

Please add a kerneldoc comment for each of the new interfaces.

> +int class_for_each_device(struct class *class, void *data,
> +			   int (*fn)(struct device *, void *))
> +{
> +	struct device *dev;
> +	int error = 0;
> +
> +	if (!class)
> +		return -EINVAL;
> +	mutex_lock(&class->mutex);
> +	list_for_each_entry(dev, &class->devices, node) {
> +		error = fn(dev, data);

Hm, the equivalent _for_each_device() functions all elevate the
device's refcount while calling fn(). I wonder whether we want this
here as well?

> +		if (error)
> +			break;
> +	}
> +	mutex_unlock(&class->mutex);
> +
> +	return error;
> +}
> +EXPORT_SYMBOL_GPL(class_for_each_device);
> +
> +struct device *class_find_device(struct class *class, void *data,
> +				   int (*match)(struct device *, void *))
> +{
> +	struct device *dev;
> +
> +	if (!class)
> +		return NULL;
> +
> +	mutex_lock(&class->mutex);
> +	list_for_each_entry(dev, &class->devices, node)
> +		if (match(dev, data) && get_device(dev))

First get the reference and then drop it if the match function returns
0 to make this analogous to the other _find_device() functions?

> +			break;
> +	mutex_unlock(&class->mutex);
> +
> +	return dev;
> +}
> +EXPORT_SYMBOL_GPL(class_find_device);
> +
> +int class_for_each_child(struct class *class, void *data,
> +			   int (*fn)(struct class_device *, void *))

Haven't looked at the callers, but isn't it better to convert them to
use struct device instead so we don't need to introduce new
class_device api?

> +{
> +	struct class_device *dev;
> +	int error = 0;
> +
> +	if (!class)
> +		return -EINVAL;
> +	mutex_lock(&class->mutex);
> +	list_for_each_entry(dev, &class->children, node) {
> +		error = fn(dev, data);

Same comment as above concerning reference counts.

> +		if (error)
> +			break;
> +	}
> +	mutex_unlock(&class->mutex);
> +
> +	return error;
> +}
> +EXPORT_SYMBOL_GPL(class_for_each_child);
> +
> +struct class_device *class_find_child(struct class *class, void *data,
> +				   int (*match)(struct class_device *, void *))
> +{
> +	struct class_device *dev;
> +
> +	if (!class)
> +		return NULL;
> +
> +	mutex_lock(&class->mutex);
> +	list_for_each_entry(dev, &class->children, node)
> +		if (match(dev, data) && class_device_get(dev))

And here.

> +			break;
> +	mutex_unlock(&class->mutex);
> +
> +	return dev;
> +}
> +EXPORT_SYMBOL_GPL(class_find_child);
> +

  parent reply	other threads:[~2008-01-10 13:24 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-03  5:50 Dave Young
2008-01-03  7:06 ` Jarek Poplawski
2008-01-03  7:24   ` Jarek Poplawski
2008-01-03  7:21     ` Dave Young
2008-01-03  7:41       ` Jarek Poplawski
2008-01-06 18:41 ` Stefan Richter
2008-01-07  2:09   ` Dave Young
2008-01-07  8:45     ` Greg KH
2008-01-07  9:01       ` David Brownell
2008-01-07 13:23         ` Stefan Richter
2008-01-07 14:00           ` Jarek Poplawski
2008-01-07 16:36             ` Stefan Richter
2008-01-07 15:44           ` Greg KH
2008-01-07 17:13             ` Stefan Richter
2008-01-07 17:20               ` Greg KH
2008-01-08  7:05                 ` Dave Young
2008-01-08 22:48                   ` Greg KH
2008-01-09  1:32                     ` Dave Young
2008-01-09  6:13                       ` Dave Young
2008-01-09  6:37                         ` Dave Young
2008-01-09  6:39                           ` Dave Young
2008-01-10  9:48                             ` Dave Young
2008-01-10 12:34                               ` Stefan Richter
2008-01-11  2:18                                 ` Dave Young
2008-01-10 13:23                               ` Cornelia Huck [this message]
2008-01-11  2:33                                 ` Dave Young
2008-01-11  8:23                                   ` Cornelia Huck
2008-01-11  8:53                                     ` Dave Young
2008-01-10 15:41                               ` Alan Stern
2008-01-11  2:37                                 ` Dave Young
2008-01-10 18:39                               ` Greg KH
2008-01-11  2:40                                 ` Dave Young
2008-01-07 17:25               ` Alan Stern
2008-01-07 10:00       ` Dave Young

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=20080110142341.71af4dc5@gondolin.boeblingen.de.ibm.com \
    --to=cornelia.huck@de.ibm.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=a.zummo@towertech.it \
    --cc=cbou@mail.ru \
    --cc=davem@davemloft.net \
    --cc=david-b@pacbell.net \
    --cc=dwmw2@infradead.org \
    --cc=gregkh@suse.de \
    --cc=hidave.darkstar@gmail.com \
    --cc=jarkao2@gmail.com \
    --cc=krh@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=peterz@infradead.org \
    --cc=rtc-linux@googlegroups.com \
    --cc=spi-devel-general@lists.sourceforge.net \
    --cc=stefanr@s5r6.in-berlin.de \
    --cc=stern@rowland.harvard.edu \
    --subject='Re: [PATCH 0/7] convert semaphore to mutex in struct class' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).