linux-stable/drivers/clk
Stephen Boyd f114a36246 clk: Evict unregistered clks from parent caches
commit bdcf1dc253 upstream.

We leave a dangling pointer in each clk_core::parents array that has an
unregistered clk as a potential parent when that clk_core pointer is
freed by clk{_hw}_unregister(). It is impossible for the true parent of
a clk to be set with clk_set_parent() once the dangling pointer is left
in the cache because we compare parent pointers in
clk_fetch_parent_index() instead of checking for a matching clk name or
clk_hw pointer.

Before commit ede7785847 ("clk: Remove global clk traversal on fetch
parent index"), we would check clk_hw pointers, which has a higher
chance of being the same between registration and unregistration, but it
can still be allocated and freed by the clk provider. In fact, this has
been a long standing problem since commit da0f0b2c3a ("clk: Correct
lookup logic in clk_fetch_parent_index()") where we stopped trying to
compare clk names and skipped over entries in the cache that weren't
NULL.

There are good (performance) reasons to not do the global tree lookup in
cases where the cache holds dangling pointers to parents that have been
unregistered. Let's take the performance hit on the uncommon
registration path instead. Loop through all the clk_core::parents arrays
when a clk is unregistered and set the entry to NULL when the parent
cache entry and clk being unregistered are the same pointer. This will
fix this problem and avoid the overhead for the "normal" case.

Based on a patch by Bjorn Andersson.

Fixes: da0f0b2c3a ("clk: Correct lookup logic in clk_fetch_parent_index()")
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Tested-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Link: https://lkml.kernel.org/r/20190828181959.204401-1-sboyd@kernel.org
Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-08-26 10:30:00 +02:00
..
at91 clk: at91: usb: continue if clk_hw_round_rate() return zero 2020-04-24 08:01:17 +02:00
axis
axs10x
bcm clk: bcm2835: Fix return type of bcm2835_register_gate 2020-06-25 15:41:55 +02:00
berlin
h8300 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hisilicon clk: hi3660: Mark clk_gate_ufs_subsys as critical 2019-05-25 18:25:20 +02:00
imgtec clk: boston: unregister clks on failure in clk_boston_setup() 2019-11-06 12:42:55 +01:00
imx clk: vf610: fix refcount leak in vf610_clocks_init() 2020-01-27 14:46:10 +01:00
ingenic clk: ingenic: Fix doc of ingenic_cgu_div_info 2019-03-23 14:35:23 +01:00
keystone clk: keystone: Enable TISCI clocks if K3_ARCH 2019-11-24 08:22:58 +01:00
loongson1
mediatek clk: mediatek: fix PWM clock source by adding a fixed-factor clock 2018-04-24 09:36:33 +02:00
meson clk: meson: gxbb: let sar_adc_clk_div set the parent clock rate 2019-12-05 15:36:46 +01:00
microchip
mmp clk: mmp2: Fix the order of timer mux parents 2020-02-05 14:18:18 +00:00
mvebu clk: dove: fix refcount leak in dove_clk_init() 2020-01-27 14:46:11 +01:00
mxs
nxp clk: divider: fix incorrect usage of container_of 2018-04-12 12:32:13 +02:00
pistachio
pxa clk: pxa: fix one of the pxa RTC clocks 2020-01-04 13:59:45 +01:00
qcom clk: qcom: msm8916: Fix the address location of pll->config_reg 2020-06-25 15:41:47 +02:00
renesas clk: renesas: r8a77995: Correct parent clock of DU 2019-12-17 20:38:35 +01:00
rockchip clk: rockchip: fix incorrect configuration of rk3228 aclk_gpu* clocks 2020-05-20 08:17:16 +02:00
samsung clk: samsung: exynos5433: Add IGNORE_UNUSED flag to sclk_i2s1 2020-06-25 15:41:54 +02:00
sirf clk: clk-atlas6: fix return value check in atlas6_clk_init() 2020-08-21 09:48:21 +02:00
socfpga clk: socfpga: fix refcount leak 2020-01-27 14:46:09 +01:00
spear License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
st clk: clk-flexgen: fix clock-critical handling 2020-06-25 15:41:49 +02:00
sunxi clk: sunxi: Fix incorrect usage of round_down() 2020-06-25 15:41:47 +02:00
sunxi-ng clk: sunxi-ng: add mux and pll notifiers for A64 CPU clock 2020-02-28 16:36:02 +01:00
tegra clk: tegra: Fix Tegra PMC clock out parents 2020-04-24 08:01:18 +02:00
ti clk: ti: composite: fix memory leak 2020-06-25 15:41:52 +02:00
uniphier clk: uniphier: Fix update register for CPU-gear 2019-03-23 14:35:23 +01:00
ux500 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
versatile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
x86 clk: x86: Add system specific quirk to mark clocks as critical 2019-05-08 07:20:53 +02:00
zte clk: zx296718: Don't reference clk_init_data after registration 2019-10-07 18:55:01 +02:00
zynq
clk-asm9260.c
clk-axi-clkgen.c clk: axi-clkgen: Correctly handle nocount bit in recalc_rate() 2018-03-24 11:01:28 +01:00
clk-axm5516.c
clk-bulk.c clk: Export clk_bulk_prepare() 2017-09-29 14:17:17 -07:00
clk-cdce706.c
clk-cdce925.c
clk-clps711x.c
clk-composite.c
clk-conf.c
clk-cs2000-cp.c
clk-devres.c
clk-divider.c clk: divider: fix incorrect usage of container_of 2018-04-12 12:32:13 +02:00
clk-efm32gg.c
clk-fixed-factor.c clk: fixed-factor: fix of_node_get-put imbalance 2018-11-27 16:10:48 +01:00
clk-fixed-rate.c clk: fixed-rate: fix of_node_get-put imbalance 2018-11-27 16:10:47 +01:00
clk-fractional-divider.c clk: fractional-divider: check parent rate only if flag is set 2019-04-05 22:31:31 +02:00
clk-gate.c
clk-gemini.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
clk-gpio.c
clk-hi655x.c
clk-highbank.c clk: highbank: fix refcount leak in hb_clk_init() 2020-01-27 14:46:09 +01:00
clk-hsdk-pll.c
clk-max77686.c
clk-moxart.c
clk-multiplier.c
clk-mux.c clk: honor CLK_MUX_ROUND_CLOSEST in generic clk mux 2018-06-21 04:02:42 +09:00
clk-nomadik.c
clk-nspire.c
clk-oxnas.c
clk-palmas.c
clk-pwm.c
clk-qoriq.c clk: qoriq: fix refcount leak in clockgen_init() 2020-01-27 14:46:09 +01:00
clk-rk808.c
clk-s2mps11.c clk: s2mps11: Add used attribute to s2mps11_dt_match 2019-09-16 08:20:46 +02:00
clk-scpi.c
clk-si514.c
clk-si570.c
clk-si5351.c clk: si5351: Rename internal plls to avoid name collisions 2018-03-24 11:01:28 +01:00
clk-si5351.h
clk-stm32f4.c
clk-stm32h7.c clk: stm32h7: fix test of clock config 2017-12-14 09:53:11 +01:00
clk-tango4.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
clk-twl6040.c clk: clk-twl6040: Fix imprecise external abort for pdmclk 2019-03-23 14:35:23 +01:00
clk-u300.c
clk-versaclock5.c clk: vc5: Abort clock configuration without upstream clock 2019-03-05 17:57:58 +01:00
clk-vt8500.c
clk-wm831x.c
clk-xgene.c
clk.c clk: Evict unregistered clks from parent caches 2020-08-26 10:30:00 +02:00
clk.h
clkdev.c
Kconfig
Makefile clk: keystone: Enable TISCI clocks if K3_ARCH 2019-11-24 08:22:58 +01:00