Skip to content

Commit 3d3801e

Browse files
Michael Turquettebebarino
authored andcommitted
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: 035a61c ("clk: Make clk API return per-user struct clk instances") Cc: Russell King <linux@arm.linux.org.uk> Cc: Shawn Guo <shawn.guo@linaro.org> Cc: Tomeu Vizoso <tomeu.vizoso@collabora.com> Signed-off-by: Michael Turquette <mturquette@linaro.org> [arnd@arndb.de: Fix COMMON_CLK=N && HAS_CLK=Y config] Signed-off-by: Arnd Bergmann <arnd@arndb.de> [sboyd@codeaurora.org: const arguments to clk_is_match() and remove unnecessary ternary operation] Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
1 parent f55ac06 commit 3d3801e

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

drivers/clk/clk.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,32 @@ int clk_get_phase(struct clk *clk)
21692169
return clk_core_get_phase(clk->core);
21702170
}
21712171

2172+
/**
2173+
* clk_is_match - check if two clk's point to the same hardware clock
2174+
* @p: clk compared against q
2175+
* @q: clk compared against p
2176+
*
2177+
* Returns true if the two struct clk pointers both point to the same hardware
2178+
* clock node. Put differently, returns true if struct clk *p and struct clk *q
2179+
* share the same struct clk_core object.
2180+
*
2181+
* Returns false otherwise. Note that two NULL clks are treated as matching.
2182+
*/
2183+
bool clk_is_match(const struct clk *p, const struct clk *q)
2184+
{
2185+
/* trivial case: identical struct clk's or both NULL */
2186+
if (p == q)
2187+
return true;
2188+
2189+
/* true if clk->core pointers match. Avoid derefing garbage */
2190+
if (!IS_ERR_OR_NULL(p) && !IS_ERR_OR_NULL(q))
2191+
if (p->core == q->core)
2192+
return true;
2193+
2194+
return false;
2195+
}
2196+
EXPORT_SYMBOL_GPL(clk_is_match);
2197+
21722198
/**
21732199
* __clk_init - initialize the data structures in a struct clk
21742200
* @dev: device initializing this clk, placeholder for now

include/linux/clk.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ int clk_set_phase(struct clk *clk, int degrees);
125125
*/
126126
int clk_get_phase(struct clk *clk);
127127

128+
/**
129+
* clk_is_match - check if two clk's point to the same hardware clock
130+
* @p: clk compared against q
131+
* @q: clk compared against p
132+
*
133+
* Returns true if the two struct clk pointers both point to the same hardware
134+
* clock node. Put differently, returns true if struct clk *p and struct clk *q
135+
* share the same struct clk_core object.
136+
*
137+
* Returns false otherwise. Note that two NULL clks are treated as matching.
138+
*/
139+
bool clk_is_match(const struct clk *p, const struct clk *q);
140+
128141
#else
129142

130143
static inline long clk_get_accuracy(struct clk *clk)
@@ -142,6 +155,11 @@ static inline long clk_get_phase(struct clk *clk)
142155
return -ENOTSUPP;
143156
}
144157

158+
static inline bool clk_is_match(const struct clk *p, const struct clk *q)
159+
{
160+
return p == q;
161+
}
162+
145163
#endif
146164

147165
/**

0 commit comments

Comments
 (0)