mbox series

[00/78] media: use pm_runtime_resume_and_get() instead of pm_runtime_get_sync()

Message ID cover.1619191723.git.mchehab+huawei@kernel.org
Headers show
Series media: use pm_runtime_resume_and_get() instead of pm_runtime_get_sync() | expand

Message

Mauro Carvalho Chehab April 24, 2021, 6:44 a.m. UTC
During the review of the patches from unm.edu, one of the patterns
I noticed is the amount of patches trying to fix pm_runtime_get_sync()
calls.

On contrary of the common sense that a foo_get() function will
only increment the usage on success,  pm_runtime_get_sync()
increments it unconditionally.

Due to that, there are bugs on lots of places, that ended being
gradually fixed, but, still there are a few places on media where
this is still broken.

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")
added a new method to does a pm_runtime get, which increments
the usage count only on success.

This series replace all places where the old  pm_runtime_get_sync()
is called, using  pm_runtime_resume_and_get() instead.

This should help to avoid future mistakes like that, as people
tend to use the existing drivers as examples for newer ones.

compile-tested only.

Mauro Carvalho Chehab (78):
  media: atmel: properly get pm_runtime
  media: marvel-ccic: fix some issues when getting pm_runtime
  media: mdk-mdp: fix pm_runtime_get_sync() usage count
  media: rcar_fdp1: fix  usage count
  media: mdk-mdp: fix pm_runtime_get_sync() usage count
  media: renesas-ceu: fix pm_runtime_get_sync() usage count
  media: s5p: fix pm_runtime_get_sync() usage count
  media: am437x:: fix pm_runtime_get_sync() usage count
  media: sh_vou: fix pm_runtime_get_sync() usage count
  media: sti/hva: use pm_runtime_resume_and_get()
  staging: media: rkvdec: fix pm_runtime_get_sync() usage count
  staging: media: atomisp_fops: use pm_runtime_resume_and_get()
  staging: media: hantro_drv: use pm_runtime_resume_and_get()
  staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get()
  staging: media: ipu3: use pm_runtime_resume_and_get()
  staging: media: cedrus_video: use pm_runtime_resume_and_get()
  staging: media: vde: use pm_runtime_resume_and_get()
  staging: media: csi: use pm_runtime_resume_and_get()
  staging: media: vi: use pm_runtime_resume_and_get()
  media: mtk-vcodec: fix pm_runtime_get_sync() usage count
  media: s5p-jpeg: fix pm_runtime_get_sync() usage count
  media: delta-v4l2: fix pm_runtime_get_sync() usage count
  media: sun8i_rotate: fix pm_runtime_get_sync() usage count
  media: i2c: ak7375: use pm_runtime_resume_and_get()
  media: i2c: ccs-core: use pm_runtime_resume_and_get()
  media: i2c: dw9714: use pm_runtime_resume_and_get()
  media: i2c: dw9768: use pm_runtime_resume_and_get()
  media: i2c: dw9807-vcm: use pm_runtime_resume_and_get()
  media: i2c: hi556: use pm_runtime_resume_and_get()
  media: i2c: imx214: use pm_runtime_resume_and_get()
  media: i2c: imx219: use pm_runtime_resume_and_get()
  media: i2c: imx258: use pm_runtime_resume_and_get()
  media: i2c: imx274: use pm_runtime_resume_and_get()
  media: i2c: imx290: use pm_runtime_resume_and_get()
  media: i2c: imx319: use pm_runtime_resume_and_get()
  media: i2c: imx334: use pm_runtime_resume_and_get()
  media: i2c: imx355: use pm_runtime_resume_and_get()
  media: i2c: mt9m001: use pm_runtime_resume_and_get()
  media: i2c: ov02a10: use pm_runtime_resume_and_get()
  media: i2c: ov13858: use pm_runtime_resume_and_get()
  media: i2c: ov2659: use pm_runtime_resume_and_get()
  media: i2c: ov2685: use pm_runtime_resume_and_get()
  media: i2c: ov2740: use pm_runtime_resume_and_get()
  media: i2c: ov5647: use pm_runtime_resume_and_get()
  media: i2c: ov5648: use pm_runtime_resume_and_get()
  media: i2c: ov5670: use pm_runtime_resume_and_get()
  media: i2c: ov5675: use pm_runtime_resume_and_get()
  media: i2c: ov5695: use pm_runtime_resume_and_get()
  media: i2c: ov7740: use pm_runtime_resume_and_get()
  media: i2c: ov8856: use pm_runtime_resume_and_get()
  media: i2c: ov8865: use pm_runtime_resume_and_get()
  media: i2c: ov9734: use pm_runtime_resume_and_get()
  media: i2c: tvp5150: use pm_runtime_resume_and_get()
  media: i2c: video-i2c: use pm_runtime_resume_and_get()
  media: ipu3: use pm_runtime_resume_and_get()
  media: coda: use pm_runtime_resume_and_get()
  media: exynos4-is: use pm_runtime_resume_and_get()
  media: exynos-gsc: use pm_runtime_resume_and_get()
  media: mtk-jpeg: use pm_runtime_resume_and_get()
  media: camss-csid: use pm_runtime_resume_and_get()
  media: camss-csiphy: use pm_runtime_resume_and_get()
  media: camss-ispif: use pm_runtime_resume_and_get()
  media: camss-vfe: use pm_runtime_resume_and_get()
  media: core: use pm_runtime_resume_and_get()
  media: pm_helpers: use pm_runtime_resume_and_get()
  media: vdec: use pm_runtime_resume_and_get()
  media: venc: use pm_runtime_resume_and_get()
  media: rcar-fcp: use pm_runtime_resume_and_get()
  media: rcar-vin: use pm_runtime_resume_and_get()
  media: rga-buf: use pm_runtime_resume_and_get()
  media: rkisp1-capture: use pm_runtime_resume_and_get()
  media: s3c-camif: use pm_runtime_resume_and_get()
  media: s5p-mfc: use pm_runtime_resume_and_get()
  media: bdisp-v4l2: use pm_runtime_resume_and_get()
  media: stm32: use pm_runtime_resume_and_get()
  media: sun4i_v4l2: use pm_runtime_resume_and_get()
  media: ti-vpe: use pm_runtime_resume_and_get()
  media: vsp1: use pm_runtime_resume_and_get()

 drivers/media/cec/platform/s5p/s5p_cec.c      |  5 +++-
 drivers/media/i2c/ak7375.c                    | 10 +------
 drivers/media/i2c/ccs/ccs-core.c              | 11 ++++----
 drivers/media/i2c/dw9714.c                    | 10 +------
 drivers/media/i2c/dw9768.c                    | 10 +------
 drivers/media/i2c/dw9807-vcm.c                | 10 +------
 drivers/media/i2c/hi556.c                     |  3 +--
 drivers/media/i2c/imx214.c                    |  6 ++---
 drivers/media/i2c/imx219.c                    |  6 ++---
 drivers/media/i2c/imx258.c                    |  6 ++---
 drivers/media/i2c/imx274.c                    |  3 +--
 drivers/media/i2c/imx290.c                    |  6 ++---
 drivers/media/i2c/imx319.c                    |  6 ++---
 drivers/media/i2c/imx334.c                    |  5 ++--
 drivers/media/i2c/imx355.c                    |  6 ++---
 drivers/media/i2c/mt9m001.c                   |  7 ++---
 drivers/media/i2c/ov02a10.c                   |  6 ++---
 drivers/media/i2c/ov13858.c                   |  6 ++---
 drivers/media/i2c/ov2659.c                    |  6 ++---
 drivers/media/i2c/ov2685.c                    |  7 +++--
 drivers/media/i2c/ov2740.c                    |  6 ++---
 drivers/media/i2c/ov5647.c                    |  9 ++++---
 drivers/media/i2c/ov5648.c                    |  6 ++---
 drivers/media/i2c/ov5670.c                    |  6 ++---
 drivers/media/i2c/ov5675.c                    |  3 +--
 drivers/media/i2c/ov5695.c                    |  6 ++---
 drivers/media/i2c/ov7740.c                    |  8 +++---
 drivers/media/i2c/ov8856.c                    |  3 +--
 drivers/media/i2c/ov8865.c                    |  6 ++---
 drivers/media/i2c/ov9734.c                    |  3 +--
 drivers/media/i2c/tvp5150.c                   | 16 +++---------
 drivers/media/i2c/video-i2c.c                 | 14 ++++------
 drivers/media/pci/intel/ipu3/ipu3-cio2-main.c |  3 +--
 drivers/media/platform/am437x/am437x-vpfe.c   | 10 ++++---
 drivers/media/platform/atmel/atmel-isc-base.c | 26 ++++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 +++++++++++---
 drivers/media/platform/coda/coda-common.c     |  2 +-
 drivers/media/platform/exynos-gsc/gsc-core.c  |  3 +--
 drivers/media/platform/exynos-gsc/gsc-m2m.c   |  2 +-
 .../media/platform/exynos4-is/fimc-capture.c  |  6 ++---
 drivers/media/platform/exynos4-is/fimc-is.c   |  3 ++-
 .../platform/exynos4-is/fimc-isp-video.c      |  3 +--
 drivers/media/platform/exynos4-is/fimc-isp.c  |  7 +++--
 drivers/media/platform/exynos4-is/fimc-lite.c |  5 ++--
 drivers/media/platform/exynos4-is/fimc-m2m.c  |  2 +-
 drivers/media/platform/exynos4-is/media-dev.c |  8 +++---
 drivers/media/platform/exynos4-is/mipi-csis.c |  5 ++--
 .../media/platform/marvell-ccic/mcam-core.c   |  9 +++++--
 .../media/platform/mtk-jpeg/mtk_jpeg_core.c   |  4 +--
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c  |  6 ++---
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.c   |  4 +--
 .../media/platform/qcom/camss/camss-csid.c    |  6 ++---
 .../media/platform/qcom/camss/camss-csiphy.c  |  6 ++---
 .../media/platform/qcom/camss/camss-ispif.c   |  6 ++---
 drivers/media/platform/qcom/camss/camss-vfe.c |  5 ++--
 drivers/media/platform/qcom/venus/core.c      | 19 +++++++-------
 .../media/platform/qcom/venus/pm_helpers.c    | 10 +++----
 drivers/media/platform/qcom/venus/vdec.c      |  4 +--
 drivers/media/platform/qcom/venus/venc.c      |  5 ++--
 drivers/media/platform/rcar-fcp.c             |  6 ++---
 drivers/media/platform/rcar-vin/rcar-csi2.c   |  2 +-
 drivers/media/platform/rcar-vin/rcar-dma.c    |  6 ++---
 drivers/media/platform/rcar-vin/rcar-v4l2.c   |  6 ++---
 drivers/media/platform/rcar_fdp1.c            | 12 +++++++--
 drivers/media/platform/renesas-ceu.c          |  5 +++-
 drivers/media/platform/rockchip/rga/rga-buf.c |  3 +--
 drivers/media/platform/rockchip/rga/rga.c     |  4 ++-
 .../platform/rockchip/rkisp1/rkisp1-capture.c |  3 +--
 .../media/platform/s3c-camif/camif-capture.c  |  5 ++--
 drivers/media/platform/s3c-camif/camif-core.c |  5 ++--
 drivers/media/platform/s5p-jpeg/jpeg-core.c   |  2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_pm.c   |  6 ++---
 drivers/media/platform/sh_vou.c               |  6 ++++-
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c |  7 ++---
 drivers/media/platform/sti/delta/delta-v4l2.c |  4 +--
 drivers/media/platform/sti/hva/hva-hw.c       | 17 ++++++------
 drivers/media/platform/stm32/stm32-dcmi.c     |  5 ++--
 .../platform/sunxi/sun4i-csi/sun4i_v4l2.c     |  7 +++--
 .../sunxi/sun8i-rotate/sun8i_rotate.c         |  2 +-
 drivers/media/platform/ti-vpe/cal-video.c     |  4 ++-
 drivers/media/platform/ti-vpe/cal.c           |  8 +++---
 drivers/media/platform/ti-vpe/vpe.c           |  4 +--
 drivers/media/platform/vsp1/vsp1_drv.c        |  6 ++---
 .../staging/media/atomisp/pci/atomisp_fops.c  |  6 ++---
 drivers/staging/media/hantro/hantro_drv.c     |  2 +-
 drivers/staging/media/imx/imx7-mipi-csis.c    |  7 +++--
 drivers/staging/media/ipu3/ipu3.c             |  3 +--
 drivers/staging/media/rkvdec/rkvdec.c         |  2 +-
 .../staging/media/sunxi/cedrus/cedrus_video.c |  6 ++---
 drivers/staging/media/tegra-vde/vde.c         | 16 +++++++-----
 drivers/staging/media/tegra-video/csi.c       |  3 +--
 drivers/staging/media/tegra-video/vi.c        |  3 +--
 92 files changed, 270 insertions(+), 322 deletions(-)

Comments

Sylwester Nawrocki April 25, 2021, 8:57 p.m. UTC | #1
On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:
> Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")

> added pm_runtime_resume_and_get() in order to automatically handle

> dev->power.usage_count decrement on errors.

> 

> Use the new API, in order to cleanup the error check logic.

> 

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

> ---

>   drivers/media/platform/exynos4-is/fimc-capture.c   | 6 ++----

>   drivers/media/platform/exynos4-is/fimc-is.c        | 3 ++-

>   drivers/media/platform/exynos4-is/fimc-isp-video.c | 3 +--

>   drivers/media/platform/exynos4-is/fimc-isp.c       | 7 +++----

>   drivers/media/platform/exynos4-is/fimc-lite.c      | 5 +++--

>   drivers/media/platform/exynos4-is/fimc-m2m.c       | 2 +-

>   drivers/media/platform/exynos4-is/media-dev.c      | 8 +++-----

>   drivers/media/platform/exynos4-is/mipi-csis.c      | 5 ++---

>   8 files changed, 17 insertions(+), 22 deletions(-)

> 

> diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c

> index 13c838d3f947..0da36443173c 100644

> --- a/drivers/media/platform/exynos4-is/fimc-capture.c

> +++ b/drivers/media/platform/exynos4-is/fimc-capture.c

> @@ -478,11 +478,9 @@ static int fimc_capture_open(struct file *file)

>   		goto unlock;

>   

>   	set_bit(ST_CAPT_BUSY, &fimc->state);

> -	ret = pm_runtime_get_sync(&fimc->pdev->dev);

> -	if (ret < 0) {

> -		pm_runtime_put_sync(&fimc->pdev->dev);

> +	ret = pm_runtime_resume_and_get(&fimc->pdev->dev);

> +	if (ret < 0)

>   		goto unlock;

> -	}

>   

>   	ret = v4l2_fh_open(file);

>   	if (ret) {

> diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c

> index 972d9601d236..bca35866cc74 100644

> --- a/drivers/media/platform/exynos4-is/fimc-is.c

> +++ b/drivers/media/platform/exynos4-is/fimc-is.c

> @@ -828,7 +828,7 @@ static int fimc_is_probe(struct platform_device *pdev)

>   			goto err_irq;

>   	}

>   

> -	ret = pm_runtime_get_sync(dev);

> +	ret = pm_runtime_resume_and_get(dev);

>   	if (ret < 0)

>   		goto err_pm;


It seems you intended to use err_suspend label here. We don't need
a new label though, instead of err_pm we can jump to err_irq when
pm_runtime_resume_and_get() fails. Note that when runtime PM is
disabled pm_runtime_resume_and_get() always returns 0.

> @@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)

>   	fimc_is_unregister_subdevs(is);

>   err_pm:

>   	pm_runtime_put_noidle(dev);

> +err_suspend:

>   	if (!pm_runtime_enabled(dev))

>   		fimc_is_runtime_suspend(dev);

>   err_irq:



> diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c

> index 1aac167abb17..a0218237d66b 100644

> --- a/drivers/media/platform/exynos4-is/mipi-csis.c

> +++ b/drivers/media/platform/exynos4-is/mipi-csis.c

> @@ -494,7 +494,7 @@ static int s5pcsis_s_power(struct v4l2_subdev *sd, int on)

>   	struct device *dev = &state->pdev->dev;

>   

>   	if (on)

> -		return pm_runtime_get_sync(dev);

> +		return pm_runtime_resume_and_get(dev);

>   

>   	return pm_runtime_put_sync(dev);

>   }

> @@ -509,9 +509,8 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)

>   

>   	if (enable) {

>   		s5pcsis_clear_counters(state);

> -		ret = pm_runtime_get_sync(&state->pdev->dev);

> +		ret = pm_runtime_resume_and_get(&state->pdev->dev);

>   		if (ret && ret != 1) {

> -			pm_runtime_put_noidle(&state->pdev->dev);

>   			return ret;

>   		}


Braces could be dropped as well here.

>   	}



Thanks,
Sylwester
Mauro Carvalho Chehab April 26, 2021, 1:12 p.m. UTC | #2
Em Sun, 25 Apr 2021 22:57:25 +0200
Sylwester Nawrocki <snawrocki@kernel.org> escreveu:

> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:
> > Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")
> > added pm_runtime_resume_and_get() in order to automatically handle
> > dev->power.usage_count decrement on errors.
> > 
> > Use the new API, in order to cleanup the error check logic.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> > ---
> >   drivers/media/platform/exynos4-is/fimc-capture.c   | 6 ++----
> >   drivers/media/platform/exynos4-is/fimc-is.c        | 3 ++-
> >   drivers/media/platform/exynos4-is/fimc-isp-video.c | 3 +--
> >   drivers/media/platform/exynos4-is/fimc-isp.c       | 7 +++----
> >   drivers/media/platform/exynos4-is/fimc-lite.c      | 5 +++--
> >   drivers/media/platform/exynos4-is/fimc-m2m.c       | 2 +-
> >   drivers/media/platform/exynos4-is/media-dev.c      | 8 +++-----
> >   drivers/media/platform/exynos4-is/mipi-csis.c      | 5 ++---
> >   8 files changed, 17 insertions(+), 22 deletions(-)
> > 
> > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > index 13c838d3f947..0da36443173c 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > @@ -478,11 +478,9 @@ static int fimc_capture_open(struct file *file)
> >   		goto unlock;
> >   
> >   	set_bit(ST_CAPT_BUSY, &fimc->state);
> > -	ret = pm_runtime_get_sync(&fimc->pdev->dev);
> > -	if (ret < 0) {
> > -		pm_runtime_put_sync(&fimc->pdev->dev);
> > +	ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
> > +	if (ret < 0)
> >   		goto unlock;
> > -	}
> >   
> >   	ret = v4l2_fh_open(file);
> >   	if (ret) {
> > diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
> > index 972d9601d236..bca35866cc74 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-is.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-is.c
> > @@ -828,7 +828,7 @@ static int fimc_is_probe(struct platform_device *pdev)
> >   			goto err_irq;
> >   	}
> >   
> > -	ret = pm_runtime_get_sync(dev);
> > +	ret = pm_runtime_resume_and_get(dev);
> >   	if (ret < 0)
> >   		goto err_pm;  
> 
> It seems you intended to use err_suspend label here. We don't need
> a new label though, instead of err_pm we can jump to err_irq when
> pm_runtime_resume_and_get() fails. 

Thanks! Will fix at the next version.

> Note that when runtime PM is
> disabled pm_runtime_resume_and_get() always returns 0.

Ok, but there are a couple of conditions at rpm_resume() function
at drivers/base/power/runtime.c (which is the code that actually
handles those PM macros) that could make it to return errors,
which are independent on the PM callbacks, like those:

        if (dev->power.runtime_error)
                retval = -EINVAL;
        else if (dev->power.disable_depth > 0)
                retval = -EACCES;

and more might be added as the PM core changes.

> 
> > @@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)
> >   	fimc_is_unregister_subdevs(is);
> >   err_pm:
> >   	pm_runtime_put_noidle(dev);
> > +err_suspend:
> >   	if (!pm_runtime_enabled(dev))
> >   		fimc_is_runtime_suspend(dev);
> >   err_irq:  
> 
> 
> > diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
> > index 1aac167abb17..a0218237d66b 100644
> > --- a/drivers/media/platform/exynos4-is/mipi-csis.c
> > +++ b/drivers/media/platform/exynos4-is/mipi-csis.c
> > @@ -494,7 +494,7 @@ static int s5pcsis_s_power(struct v4l2_subdev *sd, int on)
> >   	struct device *dev = &state->pdev->dev;
> >   
> >   	if (on)
> > -		return pm_runtime_get_sync(dev);
> > +		return pm_runtime_resume_and_get(dev);
> >   
> >   	return pm_runtime_put_sync(dev);
> >   }
> > @@ -509,9 +509,8 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)
> >   
> >   	if (enable) {
> >   		s5pcsis_clear_counters(state);
> > -		ret = pm_runtime_get_sync(&state->pdev->dev);
> > +		ret = pm_runtime_resume_and_get(&state->pdev->dev);
> >   		if (ret && ret != 1) {
> > -			pm_runtime_put_noidle(&state->pdev->dev);
> >   			return ret;
> >   		}  
> 
> Braces could be dropped as well here.

OK.

> 
> >   	}  
> 
> 
> Thanks,
> Sylwester
> 



Thanks,
Mauro
Sylwester Nawrocki April 27, 2021, 8:06 a.m. UTC | #3
On 26.04.2021 15:12, Mauro Carvalho Chehab wrote:
> Em Sun, 25 Apr 2021 22:57:25 +0200

> Sylwester Nawrocki <snawrocki@kernel.org> escreveu:

> 

>> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:

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

>>> added pm_runtime_resume_and_get() in order to automatically handle

>>> dev->power.usage_count decrement on errors.

>>>

>>> Use the new API, in order to cleanup the error check logic.

>>>

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


>>> diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c

>>> index 972d9601d236..bca35866cc74 100644

>>> --- a/drivers/media/platform/exynos4-is/fimc-is.c

>>> +++ b/drivers/media/platform/exynos4-is/fimc-is.c

>>> @@ -828,7 +828,7 @@ static int fimc_is_probe(struct platform_device *pdev)

>>>    			goto err_irq;

>>>    	}

>>>    

>>> -	ret = pm_runtime_get_sync(dev);

>>> +	ret = pm_runtime_resume_and_get(dev);

>>>    	if (ret < 0)

>>>    		goto err_pm;

>>

>> It seems you intended to use err_suspend label here. We don't need

>> a new label though, instead of err_pm we can jump to err_irq when

>> pm_runtime_resume_and_get() fails.

> 

> Thanks! Will fix at the next version.

> 

>> Note that when runtime PM is

>> disabled pm_runtime_resume_and_get() always returns 0.

> 

> Ok, but there are a couple of conditions at rpm_resume() function

> at drivers/base/power/runtime.c (which is the code that actually

> handles those PM macros) that could make it to return errors,

> which are independent on the PM callbacks, like those:

> 

>          if (dev->power.runtime_error)

>                  retval = -EINVAL;

>          else if (dev->power.disable_depth > 0)

>                  retval = -EACCES;

> 

> and more might be added as the PM core changes.


Right, I looked only at !CONFIG_PM case, this is what the "if (!pm_runtime_enabled(dev))"
test and explicit fimc_is_runtime_{resume,suspend} calls were originally for.
Agreed, better not to rely too much on internal implementation as there is
no specific guarantees about return value at the API documentation.

Regards,
Sylwester

>>> @@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)

>>>    	fimc_is_unregister_subdevs(is);

>>>    err_pm:

>>>    	pm_runtime_put_noidle(dev);

>>> +err_suspend:

>>>    	if (!pm_runtime_enabled(dev))

>>>    		fimc_is_runtime_suspend(dev);

>>>    err_irq:

>>
Dan Carpenter April 28, 2021, 10:13 a.m. UTC | #4
There was a Smatch check for these bugs.  This was a good source of
recurring Reported-by tags for me.  ;)  Thanks for doing this.

regards,
dan carpenter