clk: tegra: Fix refcounting of gate clocks
authorDmitry Osipenko <digetx@gmail.com>
Sun, 16 May 2021 16:30:34 +0000 (19:30 +0300)
committerThierry Reding <treding@nvidia.com>
Mon, 31 May 2021 13:16:24 +0000 (15:16 +0200)
commitc592c8a28f5821e880ac6675781cd8a151b0737c
tree9926f9c881054adb56cf87479ba6c6becac858b1
parent56bb7c28ad00e7bcfc851c4e183c42d148d3ad4e
clk: tegra: Fix refcounting of gate clocks

The refcounting of the gate clocks has a bug causing the enable_refcnt
to underflow when unused clocks are disabled. This happens because clk
provider erroneously bumps the refcount if clock is enabled at a boot
time, which it shouldn't be doing, and it does this only for the gate
clocks, while peripheral clocks are using the same gate ops and the
peripheral clocks are missing the initial bump. Hence the refcount of
the peripheral clocks is 0 when unused clocks are disabled and then the
counter is decremented further by the gate ops, causing the integer
underflow.

Fix this problem by removing the erroneous bump and by implementing the
disable_unused() callback, which disables the unused gates properly.

The visible effect of the bug is such that the unused clocks are never
gated if a loaded kernel module grabs the unused clocks and starts to use
them. In practice this shouldn't cause any real problems for the drivers
and boards supported by the kernel today.

Acked-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/clk/tegra/clk-periph-gate.c
drivers/clk/tegra/clk-periph.c