From: rjw@sisk.pl (Rafael J. Wysocki)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4] power: introduce library for device-specific OPPs
Date: Mon, 27 Sep 2010 21:53:13 +0200 [thread overview]
Message-ID: <201009272153.13232.rjw@sisk.pl> (raw)
In-Reply-To: <4CA0A95A.4000408@ti.com>
On Monday, September 27, 2010, Nishanth Menon wrote:
> Paul E. McKenney had written, on 09/25/2010 07:56 PM, the following:
> > On Sat, Sep 25, 2010 at 10:55:20PM +0200, Rafael J. Wysocki wrote:
> >> On Friday, September 24, 2010, Paul E. McKenney wrote:
> >>> On Fri, Sep 24, 2010 at 07:50:40AM -0500, Nishanth Menon wrote:
> >> ...
> >>> Looks like a good start!!! Some questions and suggestions about RCU
> >>> usage interspersed below.
> >> ...
> >>>> + * Locking: RCU reader.
> >>>> + */
> >>>> +int opp_get_opp_count(struct device *dev)
> >>>> +{
> >>>> + struct device_opp *dev_opp;
> >>>> + struct opp *temp_opp;
> >>>> + int count = 0;
> >>>> +
> >>>> + dev_opp = find_device_opp(dev);
> >>>> + if (IS_ERR(dev_opp))
> >>>> + return PTR_ERR(dev_opp);
> >>>> +
> >>>> + rcu_read_lock();
> >>>> + list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) {
> >>>> + if (temp_opp->available)
> >>>> + count++;
> >>>> + }
> >>>> + rcu_read_unlock();
> >>> This one is OK as well. You are returning a count, so if all of the
> >>> counted structures are freed at this point, no problem. The count was
> >>> valid when it was accumulated, and the fact that it might now be obsolete
> >>> is (usually) not a problem.
> >> However, it looks like it should run rcu_read_lock() before calling
> >> find_device_opp(dev), shouldn't it?
> >
> > Indeed it does appear that you are right -- good catch!!!
> >
> > Thanx, Paul
> dev_opp as discussed before is safe as it is never freed
> (find_device_opp uses it's own rcu_read_lock, the rcu_read_lock in this
> context is for the opp list. what am I missing?
It's simply safer to put the rcu_read_lock() before find_device_opp(), in case
someone will make it possible to remove things from the opp list in the future.
Besides, your entire data structure consists of the opp list and the per-power
domain lists, so you should really tell the writers when you have finished to
traverse it entirely, not in the middle of the operation.
Thanks,
Rafael
prev parent reply other threads:[~2010-09-27 19:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <[PATCH v3] power: introduce library for device-specific OPPs>
2010-09-24 12:50 ` [PATCH v4] power: introduce library for device-specific OPPs Nishanth Menon
2010-09-24 19:37 ` Paul E. McKenney
2010-09-24 21:26 ` Nishanth Menon
2010-09-24 21:40 ` Paul E. McKenney
2010-09-27 14:29 ` Nishanth Menon
2010-09-25 20:55 ` Rafael J. Wysocki
2010-09-26 0:56 ` Paul E. McKenney
2010-09-27 14:25 ` Nishanth Menon
2010-09-27 19:53 ` Rafael J. Wysocki [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=201009272153.13232.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=linux-arm-kernel@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).