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: 5882061 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CC49EBF440 for ; Wed, 25 Feb 2015 17:28:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C3C3820389 for ; Wed, 25 Feb 2015 17:28:36 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 5FAA22015E for ; Wed, 25 Feb 2015 17:28:33 +0000 (UTC) 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.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 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-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version :content-transfer-encoding:to:from:in-reply-to:cc:references :message-id:user-agent:subject:date; bh=6w8ph5GiCAeWAAivpD9AwTy6o7dBBZCytTo+verJvk8=; b=l9kwsPvY8uIJoS0oYnUp6MSBM3DLdbf4OyU8Fut6g58j83X2Jixcbzo/9mgUzLjR3z jebNQbrPcyEn8ewQlbpgjyfdMo+anEoGX08B7Q778mRqQgjmuXVjU+mv9POXwr4n1IoP aHILQB/JM4GQxAhVuSl3xA2vWwl/W1/ghaBxgbVzdtXQxmpaCa1MqlelEKU1s2LhWWrO qrhshMQ7UD76cbMoGtxkXgssGFK7Y1pdh5c7NvXpQAMMzgd2ynV3eaXEB2gBG+qrtNGf nzY2hEcczrVoZu1zlndnijjCqcy+N6AvKPEu2AwMGwR4hRgo/bh8iOUDR7xJaaU0Dsg7 nDqA== X-Gm-Message-State: ALoCoQmMK5/gUnBXuE2jeHKhWZTqQjjmBQj27Hj0q6SErK+0sdxE5PUVRt29TajRGOSvhsx9j/eb 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: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" 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-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Shawn Guo --- 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. */