From: Wolfram Sang <w.sang@pengutronix.de>
To: linuxppc-dev@ozlabs.org
Cc: Roel Kluin <roel.kluin@gmail.com>, Wolfgang Denk <wd@denx.de>,
Mark Brown <broonie@sirena.org.uk>
Subject: [PATCH V2] mpc512x/clock: fix clk_get logic
Date: Fri, 30 Oct 2009 18:53:51 +0100 [thread overview]
Message-ID: <1256925231-21917-1-git-send-email-w.sang@pengutronix.de> (raw)
In-Reply-To: <20091030105414.GD717@sirena.org.uk>
The current matching logic returns a clock even if only one out of two
arguments matches. This is wrong as devices may utilize more than one clock, so
only the first clock out of those is returned if the dev-match alone is
considered sufficent (noticed while working on the CAN driver). The proposed
new method will:
- return -EINVAL if both arguments are NULL
- skip the relevant check if one argument is NULL (first match wins)
- otherwise both arguments need to match
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: Mark Brown <broonie@sirena.org.uk>
Cc: Roel Kluin <roel.kluin@gmail.com>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
After Mark's valid comment, I'll try harder ;)
arch/powerpc/platforms/512x/clock.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/arch/powerpc/platforms/512x/clock.c b/arch/powerpc/platforms/512x/clock.c
index 84544d0..4168457 100644
--- a/arch/powerpc/platforms/512x/clock.c
+++ b/arch/powerpc/platforms/512x/clock.c
@@ -53,19 +53,21 @@ static DEFINE_MUTEX(clocks_mutex);
static struct clk *mpc5121_clk_get(struct device *dev, const char *id)
{
struct clk *p, *clk = ERR_PTR(-ENOENT);
- int dev_match = 0;
- int id_match = 0;
+ /* If one argument is not given, skip its match */
+ bool id_matched = !id;
+ bool dev_matched = !dev;
- if (dev == NULL || id == NULL)
- return NULL;
+ /* We need at least one argument */
+ if (!dev && !id)
+ return ERR_PTR(-EINVAL);
mutex_lock(&clocks_mutex);
list_for_each_entry(p, &clocks, node) {
if (dev == p->dev)
- dev_match++;
- if (strcmp(id, p->name) == 0)
- id_match++;
- if ((dev_match || id_match) && try_module_get(p->owner)) {
+ dev_matched = true;
+ if (id && strcmp(id, p->name) == 0)
+ id_matched = true;
+ if (dev_matched && id_matched && try_module_get(p->owner)) {
clk = p;
break;
}
--
1.6.3.3
next prev parent reply other threads:[~2009-10-30 17:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-30 9:17 mpc512x/clock: fix clk_get logic Wolfram Sang
2009-10-30 10:54 ` Mark Brown
2009-10-30 11:36 ` Wolfram Sang
2009-10-30 12:02 ` Mark Brown
2009-10-30 17:53 ` Wolfram Sang [this message]
2009-11-02 15:17 ` [PATCH] mpc512x/clocks: initialize CAN clocks Wolfram Sang
2009-11-02 18:02 ` Grant Likely
2009-11-02 18:40 ` Wolfram Sang
2009-11-02 21:13 ` Grant Likely
2009-11-02 17:48 ` [PATCH V2] mpc512x/clock: fix clk_get logic Grant Likely
2009-11-02 23:10 ` Stephen Rothwell
2009-11-02 23:49 ` Grant Likely
2009-10-30 21:54 ` Benjamin Herrenschmidt
2009-10-31 13:01 ` Wolfram Sang
2009-10-31 20:48 ` Benjamin Herrenschmidt
2009-11-02 14:22 ` Wolfram Sang
2009-11-02 16:37 ` Grant Likely
2009-11-02 17:18 ` Wolfram Sang
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=1256925231-21917-1-git-send-email-w.sang@pengutronix.de \
--to=w.sang@pengutronix.de \
--cc=broonie@sirena.org.uk \
--cc=linuxppc-dev@ozlabs.org \
--cc=roel.kluin@gmail.com \
--cc=wd@denx.de \
/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).