diff mbox

[1/8] clk: add helper function clk_is_match()

Message ID 1424876018-17852-2-git-send-email-shawn.guo@linaro.org
State Not Applicable
Headers show

Commit Message

Shawn Guo Feb. 25, 2015, 2:53 p.m. UTC
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 <shawn.guo@linaro.org>
---
 drivers/clk/clk.c   |  6 ++++++
 include/linux/clk.h | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)

Comments

Shawn Guo Feb. 26, 2015, 12:37 a.m. UTC | #1
On Wed, Feb 25, 2015 at 09:27:57AM -0800, Mike Turquette wrote:
> 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.

Sure, no problem.  My intention was to get rmk's HummingBoard back to
work ASAP :)

> From: Michael Turquette <mturquette@linaro.org>
> 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 <linux@arm.linux.org.uk>
> Cc: Stephen Boyd <sboyd@codeaurora.org>
> Cc: Shawn Guo <shawn.guo@linaro.org>

Tested-by: Shawn Guo <shawn.guo@linaro.org>

> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> Signed-off-by: Michael Turquette <mturquette@linaro.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-pwm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ben Dooks Feb. 26, 2015, 9:02 a.m. UTC | #2
On Wed, Feb 25, 2015 at 09:27:57AM -0800, Mike Turquette wrote:
> 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 <shawn.guo@linaro.org>
> 
> 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 <mturquette@linaro.org>
> 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.

small observaton, clk_is_same() is linguistically nicer.
Philipp Zabel Feb. 26, 2015, 9:56 a.m. UTC | #3
Am Donnerstag, den 26.02.2015, 09:02 +0000 schrieb Ben Dooks:
> On Wed, Feb 25, 2015 at 09:27:57AM -0800, Mike Turquette wrote:
[...]
> > From: Michael Turquette <mturquette@linaro.org>
> > 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.
> 
> small observaton, clk_is_same() is linguistically nicer.

How about clk_equal() ?

regards
Philipp

--
To unsubscribe from this list: send the line "unsubscribe linux-pwm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ben Dooks Feb. 26, 2015, 11:25 a.m. UTC | #4
On Thu, Feb 26, 2015 at 10:56:58AM +0100, Philipp Zabel wrote:
> Am Donnerstag, den 26.02.2015, 09:02 +0000 schrieb Ben Dooks:
> > On Wed, Feb 25, 2015 at 09:27:57AM -0800, Mike Turquette wrote:
> [...]
> > > From: Michael Turquette <mturquette@linaro.org>
> > > 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.
> > 
> > small observaton, clk_is_same() is linguistically nicer.
> 
> How about clk_equal() ?

That's good, the only issue that's not clear in any of these names is
that does this mean "the same clock", a "clock of the same rate" or a
"clock that is equivalent to in the rate and phase but not subject to
the same gate".
Ricard Wanderlof Feb. 26, 2015, 11:59 a.m. UTC | #5
On Thu, 26 Feb 2015, Ben Dooks wrote:

> > > small observaton, clk_is_same() is linguistically nicer.
> > 
> > How about clk_equal() ?
> 
> That's good, the only issue that's not clear in any of these names is
> that does this mean "the same clock", a "clock of the same rate" or a
> "clock that is equivalent to in the rate and phase but not subject to
> the same gate".

clk_identical() ?

/Ricard
Geert Uytterhoeven March 4, 2015, 8:55 a.m. UTC | #6
On Wed, Feb 25, 2015 at 6:27 PM, Mike Turquette <mturquette@linaro.org> wrote:
> From: Michael Turquette <mturquette@linaro.org>
> 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 <linux@arm.linux.org.uk>
> Cc: Stephen Boyd <sboyd@codeaurora.org>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> Signed-off-by: Michael Turquette <mturquette@linaro.org>
> ---
>  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)

const struct clk *p, const struct clk *q

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

const struct clk *p, const 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)

const struct clk *p, const struct clk *q

> +{
> +       return p == q ? true : false;

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-pwm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Russell King - ARM Linux March 4, 2015, 9:51 a.m. UTC | #7
On Wed, Feb 25, 2015 at 09:27:57AM -0800, Mike Turquette wrote:
> +static inline bool clk_is_match(struct clk *p, struct clk *q)
> +{
> +	return p == q ? true : false;

When they created the C standard, they already taught the compiler that
p == q returns a true / false boolean value; there's no need for ?: here.
diff mbox

Patch

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index eb0152961d3c..7df4826d9c7b 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -597,6 +597,12 @@  struct clk *__clk_get_parent(struct clk *clk)
 }
 EXPORT_SYMBOL_GPL(__clk_get_parent);
 
+bool clk_is_match(struct clk *clk1, struct clk *clk2)
+{
+	return __clk_get_hw(clk1) == __clk_get_hw(clk2) ? true : false;
+}
+EXPORT_SYMBOL_GPL(clk_is_match);
+
 static struct clk_core *clk_core_get_parent_by_index(struct clk_core *clk,
 							 u8 index)
 {
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 8381bbfbc308..f8a8a6dd6a98 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -376,6 +376,17 @@  struct clk *clk_get_parent(struct clk *clk);
  */
 struct clk *clk_get_sys(const char *dev_id, const char *con_id);
 
+/**
+ * clk_is_match - test if two given struct clk pointers point to the same
+ * 		  hardware clock, i.e. struct clk_hw.
+ * @clk1: the first clk
+ * @clk2: the second clk
+ *
+ * Returns true if two clk pointers point to the same hardware clock,
+ * or false otherwise.
+ */
+bool clk_is_match(struct clk *clk1, struct clk *clk2);
+
 #else /* !CONFIG_HAVE_CLK */
 
 static inline struct clk *clk_get(struct device *dev, const char *id)
@@ -429,6 +440,11 @@  static inline struct clk *clk_get_parent(struct clk *clk)
 	return NULL;
 }
 
+static inline bool clk_is_match(struct clk *clk1, struct clk *clk2)
+{
+	return clk1 == clk2 ? true : false;
+}
+
 #endif
 
 /* clk_prepare_enable helps cases using clk_enable in non-atomic context. */