From patchwork Fri Oct 30 17:53:51 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 37342 X-Patchwork-Delegate: grant.likely@secretlab.ca Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 210281010A6 for ; Sat, 31 Oct 2009 04:54:26 +1100 (EST) Received: by ozlabs.org (Postfix) id 352CB1007FD; Sat, 31 Oct 2009 04:54:19 +1100 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [92.198.50.35]) by ozlabs.org (Postfix) with ESMTP id CC0D61007F8 for ; Sat, 31 Oct 2009 04:54:18 +1100 (EST) Received: from themisto.ext.pengutronix.de ([92.198.50.58] helo=pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.63) (envelope-from ) id 1N3vfu-0003GW-Du; Fri, 30 Oct 2009 18:54:14 +0100 From: Wolfram Sang To: linuxppc-dev@ozlabs.org Date: Fri, 30 Oct 2009 18:53:51 +0100 Message-Id: <1256925231-21917-1-git-send-email-w.sang@pengutronix.de> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <20091030105414.GD717@sirena.org.uk> References: <20091030105414.GD717@sirena.org.uk> X-SA-Exim-Connect-IP: 92.198.50.58 X-SA-Exim-Mail-From: w.sang@pengutronix.de X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on metis.extern.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-2.5 required=4.5 tests=AWL, BAYES_00 shortcircuit=no autolearn=ham version=3.2.4 Subject: [PATCH V2] mpc512x/clock: fix clk_get logic X-SA-Exim-Version: 4.2.1 (built Tue, 09 Jan 2007 17:23:22 +0000) X-SA-Exim-Scanned: Yes (on metis.ext.pengutronix.de) X-PTX-Original-Recipient: linuxppc-dev@ozlabs.org Cc: Roel Kluin , Wolfgang Denk , Mark Brown X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org 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 Cc: Mark Brown Cc: Roel Kluin Cc: Wolfgang Denk Cc: Grant Likely --- 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; }