[PATCH V2] mpc512x/clock: fix clk_get logic
Wolfram Sang
w.sang at pengutronix.de
Sat Oct 31 04:53:51 EST 2009
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 at pengutronix.de>
Cc: Mark Brown <broonie at sirena.org.uk>
Cc: Roel Kluin <roel.kluin at gmail.com>
Cc: Wolfgang Denk <wd at denx.de>
Cc: Grant Likely <grant.likely at 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
More information about the Linuxppc-dev
mailing list