diff mbox series

[v4,15/79] media: sh_vou: fix pm_runtime_get_sync() usage count

Message ID f7fc9697e61bef13937c3455b20e7c855e31d6f7.1619621413.git.mchehab+huawei@kernel.org
State Superseded
Headers show
Series Address some issues with PM runtime at media subsystem | expand

Commit Message

Mauro Carvalho Chehab April 28, 2021, 2:51 p.m. UTC
The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")
in order to properly decrement the usage counter and avoid memory
leaks.

While here, check if the PM runtime error was caught at open time.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/sh_vou.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Jonathan Cameron April 30, 2021, 4:40 p.m. UTC | #1
On Wed, 28 Apr 2021 16:51:36 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> The pm_runtime_get_sync() internally increments the

> dev->power.usage_count without decrementing it, even on errors.

> Replace it by the new pm_runtime_resume_and_get(), introduced by:

> commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")

> in order to properly decrement the usage counter and avoid memory

> leaks.

> 

> While here, check if the PM runtime error was caught at open time.

> 

> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---

>  drivers/media/platform/sh_vou.c | 6 +++++-

>  1 file changed, 5 insertions(+), 1 deletion(-)

> 

> diff --git a/drivers/media/platform/sh_vou.c b/drivers/media/platform/sh_vou.c

> index 4ac48441f22c..ca4310e26c49 100644

> --- a/drivers/media/platform/sh_vou.c

> +++ b/drivers/media/platform/sh_vou.c

> @@ -1133,7 +1133,11 @@ static int sh_vou_open(struct file *file)

>  	if (v4l2_fh_is_singular_file(file) &&

>  	    vou_dev->status == SH_VOU_INITIALISING) {

>  		/* First open */

> -		pm_runtime_get_sync(vou_dev->v4l2_dev.dev);

> +		err = pm_runtime_resume_and_get(vou_dev->v4l2_dev.dev);

> +		if (err < 0) {

> +			v4l2_fh_release(file);

> +			goto done_open;

> +		}

>  		err = sh_vou_hw_init(vou_dev);

>  		if (err < 0) {

>  			pm_runtime_put(vou_dev->v4l2_dev.dev);
diff mbox series

Patch

diff --git a/drivers/media/platform/sh_vou.c b/drivers/media/platform/sh_vou.c
index 4ac48441f22c..ca4310e26c49 100644
--- a/drivers/media/platform/sh_vou.c
+++ b/drivers/media/platform/sh_vou.c
@@ -1133,7 +1133,11 @@  static int sh_vou_open(struct file *file)
 	if (v4l2_fh_is_singular_file(file) &&
 	    vou_dev->status == SH_VOU_INITIALISING) {
 		/* First open */
-		pm_runtime_get_sync(vou_dev->v4l2_dev.dev);
+		err = pm_runtime_resume_and_get(vou_dev->v4l2_dev.dev);
+		if (err < 0) {
+			v4l2_fh_release(file);
+			goto done_open;
+		}
 		err = sh_vou_hw_init(vou_dev);
 		if (err < 0) {
 			pm_runtime_put(vou_dev->v4l2_dev.dev);