linux/drivers
Douglas Anderson 607ccb7d3d clk: qcom: lpass-sc7280: Fix pm_runtime usage
[ Upstream commit d470be3c4f ]

The pm_runtime usage in lpass-sc7280 was broken in quite a few
ways. Specifically:

1. At the end of probe it called "put" twice. This is a no-no and will
   end us up with a negative usage count. Even worse than calling
   "put" twice, it never called "get" once. Thus after bootup it could
   be seen that the runtime usage of the devices managed by this
   driver was -2.
2. In some error cases it manually called pm_runtime_disable() even
   though it had previously used devm_add_action_or_reset() to set
   this up to be called automatically. This meant that in these error
   cases we'd double-call pm_runtime_disable().
3. It forgot to call undo pm_runtime_use_autosuspend(), which can
   sometimes have subtle problems (and the docs specifically mention
   that you need to undo this function).

Overall the above seriously calls into question how this driver is
working. It seems like a combination of "it doesn't", "by luck", and
"because of the weirdness of runtime_pm". Specifically I put a
printout to the serial console every time the runtime suspend/resume
was called for the two devices created by this driver (I wrapped the
pm_clk calls). When I had serial console enabled, I found that the
calls got resumed at bootup (when the clk core probed and before our
double-put) and then never touched again. That's no good.
  [    0.829997] DOUG: my_pm_clk_resume, usage=1
  [    0.835487] DOUG: my_pm_clk_resume, usage=1

When I disabled serial console (speeding up boot), I got a different
pattern, which I guess (?) is better:
  [    0.089767] DOUG: my_pm_clk_resume, usage=1
  [    0.090507] DOUG: my_pm_clk_resume, usage=1
  [    0.151885] DOUG: my_pm_clk_suspend, usage=-2
  [    0.151914] DOUG: my_pm_clk_suspend, usage=-2
  [    1.825747] DOUG: my_pm_clk_resume, usage=-1
  [    1.825774] DOUG: my_pm_clk_resume, usage=-1
  [    1.888269] DOUG: my_pm_clk_suspend, usage=-2
  [    1.888282] DOUG: my_pm_clk_suspend, usage=-2

These different patterns have to do with the fact that the core PM
Runtime code really isn't designed to be robust to negative usage
counts and sometimes may happen to stumble upon a behavior that
happens to "work". For instance, you can see that
__pm_runtime_suspend() will treat any non-zero value (including
negative numbers) as if the device is in use.

In any case, let's fix the driver to be correct. We'll hold a
pm_runtime reference for the whole probe and then drop it (once!) at
the end. We'll get rid of manual pm_runtime_disable() calls in the
error handling. We'll also switch to devm_pm_runtime_enable(), which
magically handles undoing pm_runtime_use_autosuspend() as of commit
b4060db925 ("PM: runtime: Have devm_pm_runtime_enable() handle
pm_runtime_dont_use_autosuspend()").

While we're at this, let's also use devm_pm_clk_create() instead of
rolling it ourselves.

Note that the above changes make it obvious that
lpassaudio_create_pm_clks() was doing more than just creating
clocks. It was also setting up pm_runtime parameters. Let's rename it.

All of these problems were found by code inspection. I started looking
at this driver because it was involved in a deadlock that I reported a
while ago [1]. Though I bisected the deadlock to commit 1b771839de
("clk: qcom: gdsc: enable optional power domain support"), it was
never really clear why that patch affected it other than a luck of
timing changes. I'll also note that by fixing the timing (as done in
this change) we also seem to aboid the deadlock, which is a nice
benefit.

Also note that some of the fixes here are much the same type of stuff
that Dmitry did in commit 72cfc73f46 ("clk: qcom: use
devm_pm_runtime_enable and devm_pm_clk_create"), but I guess
lpassaudiocc-sc7280.c didn't exist then.

[1] https://lore.kernel.org/r/20220922154354.2486595-1-dianders@chromium.org

Fixes: a9dd26639d ("clk: qcom: lpass: Add support for LPASS clock controller for SC7280")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
Link: https://lore.kernel.org/r/20221104064055.1.I00a0e4564a25489e85328ec41636497775627564@changeid
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-12-31 13:32:21 +01:00
..
accessibility
acpi ACPICA: Fix use-after-free in acpi_ut_copy_ipackage_to_ipackage() 2022-12-31 13:31:59 +01:00
amba
android
ata ata: libata: fix NCQ autosense logic 2022-12-31 13:32:02 +01:00
atm
auxdisplay
base regmap-irq: Use the new num_config_regs property in regmap_add_irq_chip_fwnode 2022-12-31 13:32:09 +01:00
bcma
block drbd: destroy workqueue when drbd device was freed 2022-12-31 13:32:15 +01:00
bluetooth
bus
cdrom
char ipmi: kcs: Poll OBF briefly to reduce OBE latency 2022-12-31 13:32:03 +01:00
clk clk: qcom: lpass-sc7280: Fix pm_runtime usage 2022-12-31 13:32:21 +01:00
clocksource clocksource/drivers/timer-ti-dm: Fix missing clk_disable_unprepare in dmtimer_systimer_init_clock() 2022-12-31 13:31:59 +01:00
comedi
connector
counter
cpufreq cpufreq: amd_freq_sensitivity: Add missing pci_dev_put() 2022-12-31 13:31:58 +01:00
cpuidle cpuidle: dt: Return the correct numbers of parsed idle states 2022-12-31 13:31:55 +01:00
crypto
cxl
dax
dca
devfreq
dio
dma
dma-buf
edac EDAC/i10nm: fix refcount leak in pci_get_dev_wrapper() 2022-12-31 13:31:57 +01:00
eisa
extcon
firewire
firmware firmware: ti_sci: Fix polled mode during system suspend 2022-12-31 13:31:48 +01:00
fpga
fsi
gnss
gpio
gpu drm/i915/bios: fix a memory leak in generate_lfp_data_ptrs 2022-12-31 13:32:19 +01:00
greybus
hid HID: hid-sensor-custom: set fixed size for custom attributes 2022-12-31 13:32:14 +01:00
hsi
hte
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
idle
iio
infiniband
input Input: wistron_btns - disable on UML 2022-12-31 13:32:19 +01:00
interconnect
iommu
ipack
irqchip irqchip/loongson-liointc: Fix improper error handling in liointc_init() 2022-12-31 13:31:57 +01:00
isdn
leds
macintosh
mailbox mailbox: pcc: Reset pcc_chan_count to zero in case of PCC probe failure 2022-12-31 13:31:57 +01:00
mcb
md dm: track per-add_disk holder relations in DM 2022-12-31 13:32:12 +01:00
media media: s5p-mfc: Add variant data for MFC v7 hardware for Exynos 3250 SoC 2022-12-31 13:32:17 +01:00
memory memory: renesas-rpc-if: Clear HS bit during hardware initialization 2022-12-31 13:31:48 +01:00
memstick
message
mfd
misc
mmc
most
mtd mtd: maps: pxa2xx-flash: fix memory leak in probe 2022-12-31 13:32:15 +01:00
mux
net mt76: mt7915: Fix PCI device refcount leak in mt7915_pci_init_hif2() 2022-12-31 13:32:21 +01:00
nfc
ntb
nubus
nvdimm
nvme nvme: return err on nvme_init_non_mdts_limits fail 2022-12-31 13:32:11 +01:00
nvmem
of
opp
parisc
parport
pci PCI: mt7621: Add sentinel to quirks table 2022-12-21 17:48:02 +01:00
pcmcia
peci
perf drivers/perf: hisi: Fix some event id for hisi-pcie-pmu 2022-12-31 13:31:53 +01:00
phy
pinctrl pinctrl: pinconf-generic: add missing of_node_put() 2022-12-31 13:32:16 +01:00
platform platform/mellanox: mlxbf-pmc: Fix event typo 2022-12-31 13:32:01 +01:00
pnp PNP: fix name memory leak in pnp_alloc_dev() 2022-12-31 13:31:56 +01:00
power
powercap
pps
ps3
ptp
pwm
rapidio rapidio: devices: fix missing put_device in mport_cdev_open 2022-12-31 13:32:00 +01:00
ras
regulator regulator: core: fix module refcount leak in set_supply() 2022-12-31 13:32:21 +01:00
remoteproc
reset
rpmsg
rtc
s390 s390/qeth: fix use-after-free in hsci 2022-12-08 09:12:56 -08:00
sbus
scsi
sh
siox
slimbus
soc soc: apple: rtkit: Stop casting function pointer signatures 2022-12-31 13:31:53 +01:00
soundwire
spi spi: spidev: mask SPI_CS_HIGH in SPI_IOC_RD_MODE 2022-12-31 13:32:20 +01:00
spmi
ssb
staging media: imx: imx7-media-csi: Clear BIT_MIPI_DOUBLE_CMPNT for <16b formats 2022-12-31 13:32:16 +01:00
target
tc
tee
thermal thermal: core: fix some possible name leaks in error paths 2022-12-31 13:31:57 +01:00
thunderbolt
tty
ufs
uio
usb usb: musb: remove extra check in musb_gadget_vbus_draw 2022-12-31 13:31:47 +01:00
vdpa
vfio
vhost
video
virt virt/sev-guest: Add a MODULE_ALIAS 2022-12-31 13:32:09 +01:00
virtio
vlynq
w1
watchdog
xen xen/privcmd: Fix a possible warning in privcmd_ioctl_mmap_resource() 2022-12-31 13:31:59 +01:00
zorro
Kconfig
Makefile