linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* mpc512x/clock: fix clk_get logic
@ 2009-10-30  9:17 Wolfram Sang
  2009-10-30 10:54 ` Mark Brown
  2009-10-30 21:54 ` Benjamin Herrenschmidt
  0 siblings, 2 replies; 18+ messages in thread
From: Wolfram Sang @ 2009-10-30  9:17 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Wolfgang Denk

The matching logic returns a clock even if only the dev-part matches. This is
wrong as devices may utilize more than one clock, so the wrong clock may be
returned due to dev being not unique (noticed while working on the CAN driver).
The proposed new method will:

- require the id field (as _this_ is the unique identifier)
- dev need not be given; if NULL, it will match any device.
  if given, it has to match the dev of the clock
- using the above rules, both fields need to match in order to claim the clock

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
---
 arch/powerpc/platforms/512x/clock.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Index: .kernel/arch/powerpc/platforms/512x/clock.c
===================================================================
--- .kernel.orig/arch/powerpc/platforms/512x/clock.c
+++ .kernel/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;
+	bool id_match = false;
+	/* Match any device if no dev given */
+	bool dev_match = !dev;
 
-	if (dev == NULL || id == NULL)
+	/* We need the unique identifier */
+	if (id == NULL)
 		return NULL;
 
 	mutex_lock(&clocks_mutex);
 	list_for_each_entry(p, &clocks, node) {
 		if (dev == p->dev)
-			dev_match++;
+			dev_match = true;
 		if (strcmp(id, p->name) == 0)
-			id_match++;
-		if ((dev_match || id_match) && try_module_get(p->owner)) {
+			id_match = true;
+		if (dev_match && id_match && try_module_get(p->owner)) {
 			clk = p;
 			break;
 		}

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2009-11-02 23:49 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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   ` [PATCH V2] " Wolfram Sang
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

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).