From patchwork Wed Feb 25 17:27:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Turquette X-Patchwork-Id: 45094 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8D7DA2142A for ; Wed, 25 Feb 2015 17:28:35 +0000 (UTC) Received: by wghk14 with SMTP id k14sf3960775wgh.0 for ; Wed, 25 Feb 2015 09:28:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:mime-version:to:from :in-reply-to:references:message-id:user-agent:date:cc:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:content-type:content-transfer-encoding :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=LHnoEPhYP0BRfCo2L3wmFhOxillO9ES6PRL6tvl/5vg=; b=g6s4zj3M+ghnfAd+FLepDEPfCikxroIVuZ5pTCVZcrbYWCC47k3667R65IUtcq59jm tlyzo7GinaZFeDZq3KlNV+KWAO5Q1mwygx+NBQiUkniqCE0KqETzrH4xifhAKwcCYY6+ COXefxqgDRFQgga4TDjdPCrdZovG4hs11vuwYrbFHe58VmVJFttOm7nMZpdFky4US875 HVSDPti/IDc/m3YmXOO8WCD7Rti8aWHyBBeKgSw0m203HqwsNJrt8z5XKXLM4jSQbX1o l2pggDZDoaO+7h1sZO5AgUqf4dLc2Lh5Wh/f9EdUYl+shf5OokqsDu6jvwVUoedGyD4+ 2ioA== X-Gm-Message-State: ALoCoQmUyWpcC9MhKlYhpqSM4wA/Z+7MKEC/T+2UyrBZHL+ZxYqOG5Ssclcru21C6sbe6YJlUtx+ X-Received: by 10.180.160.176 with SMTP id xl16mr2199100wib.6.1424885314888; Wed, 25 Feb 2015 09:28:34 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.99 with SMTP id lf3ls425665lac.4.gmail; Wed, 25 Feb 2015 09:28:34 -0800 (PST) X-Received: by 10.112.182.69 with SMTP id ec5mr3683098lbc.118.1424885314676; Wed, 25 Feb 2015 09:28:34 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id ld7si31318630lac.57.2015.02.25.09.28.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 09:28:34 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by labhv19 with SMTP id hv19so5404159lab.10 for ; Wed, 25 Feb 2015 09:28:34 -0800 (PST) X-Received: by 10.152.43.51 with SMTP id t19mr3725255lal.73.1424885314519; Wed, 25 Feb 2015 09:28:34 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp2768606lbj; Wed, 25 Feb 2015 09:28:33 -0800 (PST) X-Received: by 10.194.77.133 with SMTP id s5mr8325185wjw.71.1424885313660; Wed, 25 Feb 2015 09:28:33 -0800 (PST) Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id ej4si30303771wid.64.2015.02.25.09.28.32; Wed, 25 Feb 2015 09:28:33 -0800 (PST) Received-SPF: none (google.com: alsa-devel-bounces@alsa-project.org does not designate permitted sender hosts) client-ip=77.48.224.243; Received: by alsa0.perex.cz (Postfix, from userid 1000) id 6BD7F260609; Wed, 25 Feb 2015 18:28:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on mail1.perex.cz X-Spam-Level: ** X-Spam-Status: No, score=2.0 required=5.0 tests=DNS_FROM_AHBL_RHSBL autolearn=disabled version=3.2.4 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id F15432605A9; Wed, 25 Feb 2015 18:28:22 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5F9D72605B6; Wed, 25 Feb 2015 18:28:21 +0100 (CET) Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by alsa0.perex.cz (Postfix) with ESMTP id 607552605A3 for ; Wed, 25 Feb 2015 18:28:14 +0100 (CET) Received: by mail-ob0-f178.google.com with SMTP id uz6so5273550obc.9 for ; Wed, 25 Feb 2015 09:28:13 -0800 (PST) X-Received: by 10.202.201.71 with SMTP id z68mr2909716oif.32.1424885293286; Wed, 25 Feb 2015 09:28:13 -0800 (PST) Received: from localhost (pool-71-119-96-202.lsanca.fios.verizon.net. [71.119.96.202]) by mx.google.com with ESMTPSA id ot8sm25481897obc.1.2015.02.25.09.28.11 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 25 Feb 2015 09:28:12 -0800 (PST) MIME-Version: 1.0 To: Shawn Guo , From: Mike Turquette In-Reply-To: <1424876018-17852-2-git-send-email-shawn.guo@linaro.org> References: <1424876018-17852-1-git-send-email-shawn.guo@linaro.org> <1424876018-17852-2-git-send-email-shawn.guo@linaro.org> Message-ID: <20150225172757.421.43718@quantum> User-Agent: alot/0.3.5 Date: Wed, 25 Feb 2015 09:27:57 -0800 Cc: linux-pwm@vger.kernel.org, alsa-devel@alsa-project.org, Russell King , linux-serial@vger.kernel.org, Greg Kroah-Hartman , Mark Brown , Stephen Boyd , dri-devel@lists.freedesktop.org, Thierry Reding , kernel@pengutronix.de, Shawn Guo , linux-arm-kernel@lists.infradead.org Subject: Re: [alsa-devel] [PATCH 1/8] clk: add helper function clk_is_match() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mturquette@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Quoting Shawn Guo (2015-02-25 06:53:31) > Since commit 035a61c314eb ("clk: Make clk API return per-user struct clk > instances"), clk API users can no longer check if two struct clk > pointers are pointing to the same hardware clock, i.e. struct clk_hw, by > simply comparing two pointers. That's because with the per-user clk > change, a brand new struct clk is created whenever clients try to look > up the clock by calling clk_get() or sister functions like clk_get_sys() > and of_clk_get(). This changes the original behavior where the struct > clk is only created for once when clock driver registers the clock to > CCF in the first place. The net change here is before commit > 035a61c314eb the struct clk pointer is unique for given hardware > clock, while after the commit the pointers returned by clk lookup calls > become different for the same hardware clock. > > A number of client drivers detecting if two struct clk pointers point to > the same one hardware clock by comparing the pointers are broken now. > As a stop-gap solution, this patch adds a helper function clk_is_match() > to test if two struct clk pointers point to the same hardware clock, so > that these client drivers can use to fix the regression. > > Signed-off-by: Shawn Guo Hi Shawn, Thanks for the patch. I wrote a similar one last night but did not finish fixing up the drivers (and thus did not post it). I prefer my implementation below, and I'm happy to merge your driver fixes with it. Regards, Mike From: Michael Turquette Date: Wed, 25 Feb 2015 09:11:01 -0800 Subject: [PATCH] clk: introduce clk_is_match Some drivers compare struct clk pointers as a means of knowing if the two pointers reference the same clock hardware. This behavior is dubious (drivers must not dereference struct clk), but did not cause any regressions until the per-user struct clk patch was merged. Now the test for matching clk's will always fail with per-user struct clk's. clk_is_match is introduced to fix the regression and prevent drivers from comparing the pointers manually. Fixes: 035a61c314eb ("clk: Make clk API return per-user struct clk instances") Cc: Russell King Cc: Stephen Boyd Cc: Shawn Guo Cc: Tomeu Vizoso Signed-off-by: Michael Turquette --- drivers/clk/clk.c | 26 ++++++++++++++++++++++++++ include/linux/clk.h | 18 ++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index eb01529..09670de 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2171,6 +2171,32 @@ int clk_get_phase(struct clk *clk) } /** + * clk_is_match - check if two clk's point to the same hardware clock + * @p: clk compared against q + * @q: clk compared against p + * + * Returns true if the two struct clk pointers both point to the same hardware + * clock node. Put differently, returns true if struct clk *p and struct clk *q + * share the same struct clk_core object. + * + * Returns false otherwise. Note that two NULL clks are treated as matching. + */ +bool clk_is_match(struct clk *p, struct clk *q) +{ + /* trivial case: identical struct clk's or both NULL */ + if (p == q) + return true; + + /* true if clk->core pointers match. Avoid derefing garbage */ + if (!IS_ERR_OR_NULL(p) && !IS_ERR_OR_NULL(q)) + if (p->core == q->core) + return true; + + return false; +} +EXPORT_SYMBOL_GPL(clk_is_match); + +/** * __clk_init - initialize the data structures in a struct clk * @dev: device initializing this clk, placeholder for now * @clk: clk being initialized diff --git a/include/linux/clk.h b/include/linux/clk.h index 8381bbf..5c076e4 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -376,6 +376,19 @@ struct clk *clk_get_parent(struct clk *clk); */ struct clk *clk_get_sys(const char *dev_id, const char *con_id); +/** + * clk_is_match - check if two clk's point to the same hardware clock + * @p: clk compared against q + * @q: clk compared against p + * + * Returns true if the two struct clk pointers both point to the same hardware + * clock node. Put differently, returns true if struct clk *p and struct clk *q + * share the same struct clk_core object. + * + * Returns false otherwise. Note that two NULL clks are treated as matching. + */ +bool clk_is_match(struct clk *p, struct clk *q); + #else /* !CONFIG_HAVE_CLK */ static inline struct clk *clk_get(struct device *dev, const char *id) @@ -429,6 +442,11 @@ static inline struct clk *clk_get_parent(struct clk *clk) return NULL; } +static inline bool clk_is_match(struct clk *p, struct clk *q) +{ + return p == q ? true : false; +} + #endif /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */