There are two reference counter leaks in greybus moduler refer to gb_pm_runtime_get_sync, and we fixed it.
Zhang Qilong (2): staging: greybus: codecs: Fix reference counter leak in error handling greybus: audio: apbridgea: Fix reference counter leak in error handling
drivers/staging/greybus/audio_apbridgea.c | 6 +++++- drivers/staging/greybus/audio_codec.c | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-)
gb_pm_runtime_get_sync has increased the usage counter of the device here. Forgetting to call gb_pm_runtime_put_noidle will result in usage counter leak in the error branch of (gbcodec_hw_params and gbcodec_prepare). We fixed it by adding it.
Fixes: c388ae7696992 ("greybus: audio: Update pm runtime support in dai_ops callback") Signed-off-by: Zhang Qilong zhangqilong3@huawei.com --- drivers/staging/greybus/audio_codec.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c index 17a39ed63769..b589cf6b1d03 100644 --- a/drivers/staging/greybus/audio_codec.c +++ b/drivers/staging/greybus/audio_codec.c @@ -471,6 +471,7 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream, if (ret) { dev_err_ratelimited(dai->dev, "%d: Error during set_config\n", ret); + gb_pm_runtime_put_noidle(bundle); mutex_unlock(&codec->lock); return ret; } @@ -545,6 +546,7 @@ static int gbcodec_prepare(struct snd_pcm_substream *substream, break; } if (ret) { + gb_pm_runtime_put_noidle(bundle); mutex_unlock(&codec->lock); dev_err_ratelimited(dai->dev, "set_data_size failed:%d\n", ret); return ret;
When gb_audio_apbridgea_register_cport failed, maybe:
1) gb_pm_runtime_get_sync failed, usage counter remained unchanged;
2) gb_hd_output failed, usage counter remained increased;
In error state, there are two different states in usage cpounter. So, if gb_hd_output failed, we should call gb_pm_runtime_put_autosuspend ot decrease usage counter for balabce preventing reference leak. And we fixed it by add gb_pm_runtime_put_autosuspend when gb_hd_output failed.
Fixes: 6ba7fad430d63 ("Add runtime pm support to audio protocol device class driver.") Signed-off-by: Zhang Qilong zhangqilong3@huawei.com --- drivers/staging/greybus/audio_apbridgea.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/greybus/audio_apbridgea.c b/drivers/staging/greybus/audio_apbridgea.c index 26117e390deb..50545fd9756c 100644 --- a/drivers/staging/greybus/audio_apbridgea.c +++ b/drivers/staging/greybus/audio_apbridgea.c @@ -42,8 +42,12 @@ int gb_audio_apbridgea_register_cport(struct gb_connection *connection, if (ret) return ret;
- return gb_hd_output(connection->hd, &req, sizeof(req), + ret = gb_hd_output(connection->hd, &req, sizeof(req), GB_APB_REQUEST_AUDIO_CONTROL, true); + if (ret) + gb_pm_runtime_put_autosuspend(connection->bundle); + + return ret; } EXPORT_SYMBOL_GPL(gb_audio_apbridgea_register_cport);
On Mon, Nov 09, 2020 at 09:13:47PM +0800, Zhang Qilong wrote:
When gb_audio_apbridgea_register_cport failed, maybe:
gb_pm_runtime_get_sync failed, usage counter remained unchanged;
gb_hd_output failed, usage counter remained increased;
In error state, there are two different states in usage cpounter. So, if gb_hd_output failed, we should call gb_pm_runtime_put_autosuspend ot decrease usage counter for balabce preventing reference leak. And we fixed it by add gb_pm_runtime_put_autosuspend when gb_hd_output failed.
Fixes: 6ba7fad430d63 ("Add runtime pm support to audio protocol device class driver.")
That is not the name for that git commit id :(
Please fix up and resend.
thanks,
greg k-h