* [PATCH v2 0/2] ASoC: tas2552: Fix runtime PM and supply refcounting
@ 2026-12-03 11:12 Arina Kharlamova via B4 Relay
2026-12-03 11:12 ` [PATCH v2 1/2] ASoC: tas2552: Fix runtime PM usage count underflow in probe Arina Kharlamova via B4 Relay
2026-12-03 11:12 ` [PATCH v2 2/2] ASoC: tas2552: Enable the supplies in the I2C probe Arina Kharlamova via B4 Relay
0 siblings, 2 replies; 5+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-03 11:12 UTC (permalink / raw)
To: Shenghao Ding, Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood,
Mark Brown, Jaroslav Kysela, Takashi Iwai, Dinghao Liu
Cc: linux-sound, Arina Kharlamova
Two refcounting fixes for tas2552. Patch 1 removes an unmatched runtime
PM put from the I2C probe, which warns about a usage count underflow on
every boot, and disables runtime PM when the probe fails. Patch 2 moves
the supply enable from the component probe to the I2C probe, so that
card rebinds no longer leak supply enables.
I found this with spec2patch. I model-checked the probe and remove paths
of the driver with CBMC against formal specifications of the kernel APIs
it calls. The specifications are checked against the kernel source, and
some of them are proved in Rocq against a transcription of the kernel
code. I also checked lock usage separately. With the help of an AI
coding assistant (Claude); I reviewed the analysis and the fix.
Compile-tested only, not tested on hardware.
I noticed the problem fixed in patch 2 while reviewing patch 1.
---
Changes in v2:
- Patch 2: enable the supplies in the I2C probe and disable them from a
devm action instead of in tas2552_component_remove(), which cut the
power while the device was still runtime active (Sashiko review).
- Link to v1: https://patch.msgid.link/20261201-tas2552-rpm-v1-0-2bac34f9f68f@mbzuai.ac.ae
---
Arina Kharlamova (2):
ASoC: tas2552: Fix runtime PM usage count underflow in probe
ASoC: tas2552: Enable the supplies in the I2C probe
sound/soc/codecs/tas2552.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
---
base-commit: fc7af56b230b39863ea6727449269057d85c5253
change-id: 20261201-tas2552-rpm-4d19db003214
Best regards,
--
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 1/2] ASoC: tas2552: Fix runtime PM usage count underflow in probe 2026-12-03 11:12 [PATCH v2 0/2] ASoC: tas2552: Fix runtime PM and supply refcounting Arina Kharlamova via B4 Relay @ 2026-12-03 11:12 ` Arina Kharlamova via B4 Relay 2026-12-03 11:34 ` sashiko-bot 2026-12-03 11:12 ` [PATCH v2 2/2] ASoC: tas2552: Enable the supplies in the I2C probe Arina Kharlamova via B4 Relay 1 sibling, 1 reply; 5+ messages in thread From: Arina Kharlamova via B4 Relay @ 2026-12-03 11:12 UTC (permalink / raw) To: Shenghao Ding, Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai, Dinghao Liu Cc: linux-sound, Arina Kharlamova From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae> tas2552_probe() calls pm_runtime_put_sync_autosuspend() right after pm_runtime_enable(), but nothing took a usage count reference before it. Neither the I2C core nor the driver core holds one on the client during probe, so the count is 0 and the runtime PM core prints "Runtime PM usage count underflow!" on every probe. Before that check was added in v5.19 the count went to -1 instead. Remove the put. The device is active after probe as before, and tas2552_component_probe() takes the first reference. The error path after devm_snd_soc_register_component() made up for the put with pm_runtime_get_noresume() and left runtime PM enabled. Disable runtime PM there instead. Fixes: 5df7f71d5cdf ("ASoC: tas2552: Support TI TAS2552 Amplifier") Fixes: 7b3f5b207da5 ("ASoC: codecs: Fix runtime PM imbalance in tas2552_probe") Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae> --- sound/soc/codecs/tas2552.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c index 7fda383043ed..0f0c6f1afde7 100644 --- a/sound/soc/codecs/tas2552.c +++ b/sound/soc/codecs/tas2552.c @@ -746,7 +746,6 @@ static int tas2552_probe(struct i2c_client *client) pm_runtime_set_autosuspend_delay(&client->dev, 1000); pm_runtime_use_autosuspend(&client->dev); pm_runtime_enable(&client->dev); - pm_runtime_put_sync_autosuspend(&client->dev); dev_set_drvdata(&client->dev, data); @@ -755,7 +754,7 @@ static int tas2552_probe(struct i2c_client *client) tas2552_dai, ARRAY_SIZE(tas2552_dai)); if (ret < 0) { dev_err(&client->dev, "Failed to register component: %d\n", ret); - pm_runtime_get_noresume(&client->dev); + pm_runtime_disable(&client->dev); } return ret; -- Git-157) ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] ASoC: tas2552: Fix runtime PM usage count underflow in probe 2026-12-03 11:12 ` [PATCH v2 1/2] ASoC: tas2552: Fix runtime PM usage count underflow in probe Arina Kharlamova via B4 Relay @ 2026-12-03 11:34 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-03 11:34 UTC (permalink / raw) To: Arina Kharlamova; +Cc: linux-sound Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] ASoC: tas2552: missing pm_runtime_mark_last_busy() in tas2552_probe() -- commit b92bf1fc547071c78df4015b0deecdfec98c7f8a Author: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae> ASoC: tas2552: Fix runtime PM usage count underflow in probe This commit removes the unbalanced pm_runtime_put_sync_autosuspend() call in tas2552_probe() and disables runtime PM on the component registration error path instead of calling pm_runtime_get_noresume(). > diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c > index 7fda383043ed5..0f0c6f1afde78 100644 > --- a/sound/soc/codecs/tas2552.c > +++ b/sound/soc/codecs/tas2552.c > @@ -746,7 +746,6 @@ static int tas2552_probe(struct i2c_client *client) > pm_runtime_set_autosuspend_delay(&client->dev, 1000); > pm_runtime_use_autosuspend(&client->dev); > pm_runtime_enable(&client->dev); > - pm_runtime_put_sync_autosuspend(&client->dev); [Severity: Low] Does removing pm_runtime_put_sync_autosuspend() leave dev->power.last_busy at 0 and bypass the 1000 ms autosuspend delay? Commit bbe5e3c433a3 ("ASoC: codecs: Remove redundant pm_runtime_mark_last_busy() calls") dropped the explicit pm_runtime_mark_last_busy() call here because pm_runtime_put_sync_autosuspend() updated it internally. Right after tas2552_probe() returns, __driver_probe_device() calls pm_request_idle() -> rpm_idle() -> rpm_suspend(). With last_busy still 0 and uptime at least 1 second, pm_runtime_autosuspend_expiration() returns 0 and queues tas2552_runtime_suspend() immediately. That contradicts the commit message's claim that the device stays active after probe and causes an extra suspend/resume and regcache_sync() cycle when the ASoC card binds. Restoring pm_runtime_mark_last_busy(&client->dev) before pm_runtime_enable() would preserve the 1000 ms autosuspend window. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261203-tas2552-rpm-v2-0-7292beb88b1f@mbzuai.ac.ae?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] ASoC: tas2552: Enable the supplies in the I2C probe 2026-12-03 11:12 [PATCH v2 0/2] ASoC: tas2552: Fix runtime PM and supply refcounting Arina Kharlamova via B4 Relay 2026-12-03 11:12 ` [PATCH v2 1/2] ASoC: tas2552: Fix runtime PM usage count underflow in probe Arina Kharlamova via B4 Relay @ 2026-12-03 11:12 ` Arina Kharlamova via B4 Relay 2026-12-03 11:34 ` sashiko-bot 1 sibling, 1 reply; 5+ messages in thread From: Arina Kharlamova via B4 Relay @ 2026-12-03 11:12 UTC (permalink / raw) To: Shenghao Ding, Kevin Lu, Baojun Xu, Sen Wang, Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai, Dinghao Liu Cc: linux-sound, Arina Kharlamova From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae> tas2552_component_probe() enables the supplies, but tas2552_component_remove() never disables them. Each card unbind and rebind raises the regulator enable count by one, the supplies stay on after the card is gone, and unbinding the codec then hits the WARN_ON() in _regulator_put(). Disabling them in tas2552_component_remove() is not enough. The device is still runtime active there, and the runtime PM callbacks access the chip over I2C both after the card is removed and when the codec is unbound. Enable the supplies in the I2C probe instead and disable them from a devm action, as max98396 and da7213 do. The supplies then stay on while the driver is bound, except across system suspend with a card bound, and runtime PM keeps controlling only the enable GPIO and the register cache. Fixes: 5df7f71d5cdf ("ASoC: tas2552: Support TI TAS2552 Amplifier") Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae> --- sound/soc/codecs/tas2552.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c index 0f0c6f1afde7..af270acfd74f 100644 --- a/sound/soc/codecs/tas2552.c +++ b/sound/soc/codecs/tas2552.c @@ -596,15 +596,6 @@ static int tas2552_component_probe(struct snd_soc_component *component) tas2552->component = component; - ret = regulator_bulk_enable(ARRAY_SIZE(tas2552->supplies), - tas2552->supplies); - - if (ret != 0) { - dev_err(component->dev, "Failed to enable supplies: %d\n", - ret); - return ret; - } - gpiod_set_value_cansleep(tas2552->enable_gpio, 1); ret = pm_runtime_resume_and_get(component->dev); @@ -632,8 +623,6 @@ probe_fail: pm_runtime_put_noidle(component->dev); gpiod_set_value_cansleep(tas2552->enable_gpio, 0); - regulator_bulk_disable(ARRAY_SIZE(tas2552->supplies), - tas2552->supplies); return ret; } @@ -706,6 +695,14 @@ static const struct regmap_config tas2552_regmap_config = { .cache_type = REGCACHE_RBTREE, }; +static void tas2552_disable_supplies(void *data) +{ + struct tas2552_data *tas2552 = data; + + regulator_bulk_disable(ARRAY_SIZE(tas2552->supplies), + tas2552->supplies); +} + static int tas2552_probe(struct i2c_client *client) { struct device *dev; @@ -742,6 +739,17 @@ static int tas2552_probe(struct i2c_client *client) return ret; } + ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), + data->supplies); + if (ret != 0) { + dev_err(dev, "Failed to enable supplies: %d\n", ret); + return ret; + } + + ret = devm_add_action_or_reset(dev, tas2552_disable_supplies, data); + if (ret) + return ret; + pm_runtime_set_active(&client->dev); pm_runtime_set_autosuspend_delay(&client->dev, 1000); pm_runtime_use_autosuspend(&client->dev); -- Git-157) ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] ASoC: tas2552: Enable the supplies in the I2C probe 2026-12-03 11:12 ` [PATCH v2 2/2] ASoC: tas2552: Enable the supplies in the I2C probe Arina Kharlamova via B4 Relay @ 2026-12-03 11:34 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-03 11:34 UTC (permalink / raw) To: Arina Kharlamova; +Cc: linux-sound Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] ASoC: tas2552: supplies disabled while enable_gpio stays high on unbind -- commit f841fc84b4ec0bd5de01b4f81bb48d3d5d5fe1d2 Author: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae> ASoC: tas2552: Enable the supplies in the I2C probe This commit moves regulator_bulk_enable() from tas2552_component_probe() to tas2552_probe() and registers a devm action to disable the supplies on driver unbind. > diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c > index 0f0c6f1afde78..af270acfd74f5 100644 > --- a/sound/soc/codecs/tas2552.c > +++ b/sound/soc/codecs/tas2552.c [ ... ] > @@ -706,6 +695,14 @@ static const struct regmap_config tas2552_regmap_config = { > .cache_type = REGCACHE_RBTREE, > }; > > +static void tas2552_disable_supplies(void *data) > +{ > + struct tas2552_data *tas2552 = data; > + > + regulator_bulk_disable(ARRAY_SIZE(tas2552->supplies), > + tas2552->supplies); > +} > + > static int tas2552_probe(struct i2c_client *client) > { > struct device *dev; [Severity: Medium] Can this disable the supplies while enable_gpio is still high and the chip is out of software shutdown? When the device is unbound while runtime suspended, __device_release_driver() calls pm_runtime_get_sync(), running tas2552_runtime_resume() which drives enable_gpio high and exits software shutdown. Its pm_runtime_put_sync() only arms the 1000 ms autosuspend timer instead of suspending immediately. tas2552_i2c_remove() then calls pm_runtime_disable(), which cancels the pending autosuspend timer without running tas2552_runtime_suspend(). Devres teardown runs tas2552_disable_supplies() next, cutting vbat, iovdd, and avdd while enable_gpio stays asserted. That violates the power-down sequence and risks back-powering through enable_gpio or causing audible pops on supply collapse. Putting the chip into software shutdown and driving enable_gpio low before disabling the supplies would avoid this. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261203-tas2552-rpm-v2-0-7292beb88b1f@mbzuai.ac.ae?part=2 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-03 11:34 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-03 11:12 [PATCH v2 0/2] ASoC: tas2552: Fix runtime PM and supply refcounting Arina Kharlamova via B4 Relay 2026-12-03 11:12 ` [PATCH v2 1/2] ASoC: tas2552: Fix runtime PM usage count underflow in probe Arina Kharlamova via B4 Relay 2026-12-03 11:34 ` sashiko-bot 2026-12-03 11:12 ` [PATCH v2 2/2] ASoC: tas2552: Enable the supplies in the I2C probe Arina Kharlamova via B4 Relay 2026-12-03 11:34 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox