* [PATCH 1/2] soundwire: qcom: fix unbalanced pm_runtime_put()
@ 2023-05-17 16:37 Krzysztof Kozlowski
2023-05-17 16:37 ` [PATCH 2/2] soundwire: debugfs: " Krzysztof Kozlowski
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2023-05-17 16:37 UTC (permalink / raw)
To: Vinod Koul, Bard Liao, Pierre-Louis Bossart, Sanyog Kale,
Andy Gross, Bjorn Andersson, Konrad Dybcio, Péter Ujfalusi,
Srinivas Kandagatla, Charles Keepax, alsa-devel, linux-kernel,
linux-arm-msm
Cc: Krzysztof Kozlowski
This reverts commit 57ed510b0547 ("soundwire: qcom: use
pm_runtime_resume_and_get()") which introduced unbalanced
pm_runtime_put(), when device did not have runtime PM enabled.
If pm_runtime_resume_and_get() failed with -EACCES, the driver continued
execution and finally called pm_runtime_put_autosuspend(). Since
pm_runtime_resume_and_get() drops the usage counter on every error, this
lead to double decrement of that counter visible in certain debugfs
actions on unattached devices (still in reset state):
$ cat /sys/kernel/debug/soundwire/master-0-0/sdw:0:0217:f001:00:0/registers
qcom-soundwire 3210000.soundwire-controller: swrm_wait_for_wr_fifo_avail err write overflow
soundwire sdw-master-0: trf on Slave 1 failed:-5 read addr e36 count 1
soundwire sdw:0:0217:f001:00:0: Runtime PM usage count underflow!
Fixes: 57ed510b0547 ("soundwire: qcom: use pm_runtime_resume_and_get()")
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/soundwire/qcom.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index aad5942e5980..f442280af9d3 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -614,11 +614,12 @@ static irqreturn_t qcom_swrm_wake_irq_handler(int irq, void *dev_id)
struct qcom_swrm_ctrl *ctrl = dev_id;
int ret;
- ret = pm_runtime_resume_and_get(ctrl->dev);
+ ret = pm_runtime_get_sync(ctrl->dev);
if (ret < 0 && ret != -EACCES) {
dev_err_ratelimited(ctrl->dev,
- "pm_runtime_resume_and_get failed in %s, ret %d\n",
+ "pm_runtime_get_sync failed in %s, ret %d\n",
__func__, ret);
+ pm_runtime_put_noidle(ctrl->dev);
return ret;
}
@@ -1197,11 +1198,12 @@ static int qcom_swrm_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *codec_dai;
int ret, i;
- ret = pm_runtime_resume_and_get(ctrl->dev);
+ ret = pm_runtime_get_sync(ctrl->dev);
if (ret < 0 && ret != -EACCES) {
dev_err_ratelimited(ctrl->dev,
- "pm_runtime_resume_and_get failed in %s, ret %d\n",
+ "pm_runtime_get_sync failed in %s, ret %d\n",
__func__, ret);
+ pm_runtime_put_noidle(ctrl->dev);
return ret;
}
@@ -1402,11 +1404,12 @@ static int swrm_reg_show(struct seq_file *s_file, void *data)
struct qcom_swrm_ctrl *ctrl = s_file->private;
int reg, reg_val, ret;
- ret = pm_runtime_resume_and_get(ctrl->dev);
+ ret = pm_runtime_get_sync(ctrl->dev);
if (ret < 0 && ret != -EACCES) {
dev_err_ratelimited(ctrl->dev,
- "pm_runtime_resume_and_get failed in %s, ret %d\n",
+ "pm_runtime_get_sync failed in %s, ret %d\n",
__func__, ret);
+ pm_runtime_put_noidle(ctrl->dev);
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] soundwire: debugfs: fix unbalanced pm_runtime_put()
2023-05-17 16:37 [PATCH 1/2] soundwire: qcom: fix unbalanced pm_runtime_put() Krzysztof Kozlowski
@ 2023-05-17 16:37 ` Krzysztof Kozlowski
2023-05-17 16:47 ` Pierre-Louis Bossart
2023-05-17 16:47 ` [PATCH 1/2] soundwire: qcom: " Pierre-Louis Bossart
2023-05-29 5:20 ` Vinod Koul
2 siblings, 1 reply; 5+ messages in thread
From: Krzysztof Kozlowski @ 2023-05-17 16:37 UTC (permalink / raw)
To: Vinod Koul, Bard Liao, Pierre-Louis Bossart, Sanyog Kale,
Andy Gross, Bjorn Andersson, Konrad Dybcio, Péter Ujfalusi,
Srinivas Kandagatla, Charles Keepax, alsa-devel, linux-kernel,
linux-arm-msm
Cc: Krzysztof Kozlowski
If pm_runtime_resume_and_get() failed with -EACCES, the driver continued
execution and finally called pm_runtime_put_autosuspend(). Since
pm_runtime_resume_and_get() drops the usage counter on every error, this
lead to double decrement of that counter.
Fixes: b275bf45ba1d ("soundwire: debugfs: Switch to sdw_read_no_pm")
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/soundwire/debugfs.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/soundwire/debugfs.c b/drivers/soundwire/debugfs.c
index dea782e0edc4..c3a1a359ee5c 100644
--- a/drivers/soundwire/debugfs.c
+++ b/drivers/soundwire/debugfs.c
@@ -56,8 +56,9 @@ static int sdw_slave_reg_show(struct seq_file *s_file, void *data)
if (!buf)
return -ENOMEM;
- ret = pm_runtime_resume_and_get(&slave->dev);
+ ret = pm_runtime_get_sync(&slave->dev);
if (ret < 0 && ret != -EACCES) {
+ pm_runtime_put_noidle(&slave->dev);
kfree(buf);
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] soundwire: qcom: fix unbalanced pm_runtime_put()
2023-05-17 16:37 [PATCH 1/2] soundwire: qcom: fix unbalanced pm_runtime_put() Krzysztof Kozlowski
2023-05-17 16:37 ` [PATCH 2/2] soundwire: debugfs: " Krzysztof Kozlowski
@ 2023-05-17 16:47 ` Pierre-Louis Bossart
2023-05-29 5:20 ` Vinod Koul
2 siblings, 0 replies; 5+ messages in thread
From: Pierre-Louis Bossart @ 2023-05-17 16:47 UTC (permalink / raw)
To: Krzysztof Kozlowski, Vinod Koul, Bard Liao, Sanyog Kale,
Andy Gross, Bjorn Andersson, Konrad Dybcio, Péter Ujfalusi,
Srinivas Kandagatla, Charles Keepax, alsa-devel, linux-kernel,
linux-arm-msm
On 5/17/23 11:37, Krzysztof Kozlowski wrote:
> This reverts commit 57ed510b0547 ("soundwire: qcom: use
> pm_runtime_resume_and_get()") which introduced unbalanced
> pm_runtime_put(), when device did not have runtime PM enabled.
>
> If pm_runtime_resume_and_get() failed with -EACCES, the driver continued
> execution and finally called pm_runtime_put_autosuspend(). Since
> pm_runtime_resume_and_get() drops the usage counter on every error, this
> lead to double decrement of that counter visible in certain debugfs
> actions on unattached devices (still in reset state):
>
> $ cat /sys/kernel/debug/soundwire/master-0-0/sdw:0:0217:f001:00:0/registers
> qcom-soundwire 3210000.soundwire-controller: swrm_wait_for_wr_fifo_avail err write overflow
> soundwire sdw-master-0: trf on Slave 1 failed:-5 read addr e36 count 1
> soundwire sdw:0:0217:f001:00:0: Runtime PM usage count underflow!
>
> Fixes: 57ed510b0547 ("soundwire: qcom: use pm_runtime_resume_and_get()")
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Yes, this resume_and_get() added more problems indeed. One of those
well-intended changes that went sideways.
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> ---
> drivers/soundwire/qcom.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
> index aad5942e5980..f442280af9d3 100644
> --- a/drivers/soundwire/qcom.c
> +++ b/drivers/soundwire/qcom.c
> @@ -614,11 +614,12 @@ static irqreturn_t qcom_swrm_wake_irq_handler(int irq, void *dev_id)
> struct qcom_swrm_ctrl *ctrl = dev_id;
> int ret;
>
> - ret = pm_runtime_resume_and_get(ctrl->dev);
> + ret = pm_runtime_get_sync(ctrl->dev);
> if (ret < 0 && ret != -EACCES) {
> dev_err_ratelimited(ctrl->dev,
> - "pm_runtime_resume_and_get failed in %s, ret %d\n",
> + "pm_runtime_get_sync failed in %s, ret %d\n",
> __func__, ret);
> + pm_runtime_put_noidle(ctrl->dev);
> return ret;
> }
>
> @@ -1197,11 +1198,12 @@ static int qcom_swrm_startup(struct snd_pcm_substream *substream,
> struct snd_soc_dai *codec_dai;
> int ret, i;
>
> - ret = pm_runtime_resume_and_get(ctrl->dev);
> + ret = pm_runtime_get_sync(ctrl->dev);
> if (ret < 0 && ret != -EACCES) {
> dev_err_ratelimited(ctrl->dev,
> - "pm_runtime_resume_and_get failed in %s, ret %d\n",
> + "pm_runtime_get_sync failed in %s, ret %d\n",
> __func__, ret);
> + pm_runtime_put_noidle(ctrl->dev);
> return ret;
> }
>
> @@ -1402,11 +1404,12 @@ static int swrm_reg_show(struct seq_file *s_file, void *data)
> struct qcom_swrm_ctrl *ctrl = s_file->private;
> int reg, reg_val, ret;
>
> - ret = pm_runtime_resume_and_get(ctrl->dev);
> + ret = pm_runtime_get_sync(ctrl->dev);
> if (ret < 0 && ret != -EACCES) {
> dev_err_ratelimited(ctrl->dev,
> - "pm_runtime_resume_and_get failed in %s, ret %d\n",
> + "pm_runtime_get_sync failed in %s, ret %d\n",
> __func__, ret);
> + pm_runtime_put_noidle(ctrl->dev);
> return ret;
> }
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] soundwire: debugfs: fix unbalanced pm_runtime_put()
2023-05-17 16:37 ` [PATCH 2/2] soundwire: debugfs: " Krzysztof Kozlowski
@ 2023-05-17 16:47 ` Pierre-Louis Bossart
0 siblings, 0 replies; 5+ messages in thread
From: Pierre-Louis Bossart @ 2023-05-17 16:47 UTC (permalink / raw)
To: Krzysztof Kozlowski, Vinod Koul, Bard Liao, Sanyog Kale,
Andy Gross, Bjorn Andersson, Konrad Dybcio, Péter Ujfalusi,
Srinivas Kandagatla, Charles Keepax, alsa-devel, linux-kernel,
linux-arm-msm
On 5/17/23 11:37, Krzysztof Kozlowski wrote:
> If pm_runtime_resume_and_get() failed with -EACCES, the driver continued
> execution and finally called pm_runtime_put_autosuspend(). Since
> pm_runtime_resume_and_get() drops the usage counter on every error, this
> lead to double decrement of that counter.
>
> Fixes: b275bf45ba1d ("soundwire: debugfs: Switch to sdw_read_no_pm")
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> ---
> drivers/soundwire/debugfs.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/soundwire/debugfs.c b/drivers/soundwire/debugfs.c
> index dea782e0edc4..c3a1a359ee5c 100644
> --- a/drivers/soundwire/debugfs.c
> +++ b/drivers/soundwire/debugfs.c
> @@ -56,8 +56,9 @@ static int sdw_slave_reg_show(struct seq_file *s_file, void *data)
> if (!buf)
> return -ENOMEM;
>
> - ret = pm_runtime_resume_and_get(&slave->dev);
> + ret = pm_runtime_get_sync(&slave->dev);
> if (ret < 0 && ret != -EACCES) {
> + pm_runtime_put_noidle(&slave->dev);
> kfree(buf);
> return ret;
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] soundwire: qcom: fix unbalanced pm_runtime_put()
2023-05-17 16:37 [PATCH 1/2] soundwire: qcom: fix unbalanced pm_runtime_put() Krzysztof Kozlowski
2023-05-17 16:37 ` [PATCH 2/2] soundwire: debugfs: " Krzysztof Kozlowski
2023-05-17 16:47 ` [PATCH 1/2] soundwire: qcom: " Pierre-Louis Bossart
@ 2023-05-29 5:20 ` Vinod Koul
2 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2023-05-29 5:20 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Bard Liao, Pierre-Louis Bossart, Sanyog Kale, Andy Gross,
Bjorn Andersson, Konrad Dybcio, Péter Ujfalusi,
Srinivas Kandagatla, Charles Keepax, alsa-devel, linux-kernel,
linux-arm-msm
On 17-05-23, 18:37, Krzysztof Kozlowski wrote:
> This reverts commit 57ed510b0547 ("soundwire: qcom: use
> pm_runtime_resume_and_get()") which introduced unbalanced
> pm_runtime_put(), when device did not have runtime PM enabled.
>
> If pm_runtime_resume_and_get() failed with -EACCES, the driver continued
> execution and finally called pm_runtime_put_autosuspend(). Since
> pm_runtime_resume_and_get() drops the usage counter on every error, this
> lead to double decrement of that counter visible in certain debugfs
> actions on unattached devices (still in reset state):
Applied, thanks
--
~Vinod
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-29 5:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-17 16:37 [PATCH 1/2] soundwire: qcom: fix unbalanced pm_runtime_put() Krzysztof Kozlowski
2023-05-17 16:37 ` [PATCH 2/2] soundwire: debugfs: " Krzysztof Kozlowski
2023-05-17 16:47 ` Pierre-Louis Bossart
2023-05-17 16:47 ` [PATCH 1/2] soundwire: qcom: " Pierre-Louis Bossart
2023-05-29 5:20 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox