All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Lad, Prabhakar,
	Paul J. Murphy, Alexandre Torgue, Andrzej Hajda,
	Andrzej Pietrasiewicz, Andy Gross, Benoit Parrot, Bingbu Cao,
	Bjorn Andersson, Chen-Yu Tsai, Chiranjeevi Rapolu,
	Dafna Hirschfeld, Dan Scally, Daniele Alessandrelli,
	Dave Stevenson, Dmitry Osipenko, Dongchun Zhu, Ezequiel Garcia,
	Fabio Estevam, Heiko Stuebner, Helen Koike, Hyungwoo Yang,
	Jacek Anaszewski, Jacob Chen, Jacopo Mondi, Jernej Skrabec,
	Jonathan Hunter, Krzysztof Kozlowski, Leon Luo,
	Manivannan Sadhasivam, Marek Szyprowski, Matt Ranostay,
	Matthias Brugger, Mauro Carvalho Chehab, Maxime Coquelin,
	Maxime Ripard, NXP Linux Team, Paul Kocialkowski,
	Pengutronix Kernel Team, Philipp Zabel, Ricardo Ribalda,
	Robert Foss, Rui Miguel Silva, Sakari Ailus, Sascha Hauer,
	Shawn Guo, Shawn Tu, Shunqian Zheng, Sowjanya Komatineni,
	Stanimir Varbanov, Steve Longerbeam, Sylwester Nawrocki,
	Sylwester Nawrocki, Thierry Reding, Tianshu Qiu, Todor Tomov,
	Wenyou Yang, Yong Zhi, devel, linux-arm-kernel, linux-arm-msm,
	linux-kernel, linux-media, linux-mediatek, linux-renesas-soc,
	linux-rockchip, linux-samsung-soc, linux-stm32, linux-tegra

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.

After analyzing the feedback from version 1 of this series, I noticed
a few other weird behaviors at the PM runtime resume code. So, this
series start addressing some bugs and issues at the current code.
Then, it gets rid of pm_runtime_get_sync() at the media subsystem
(with 2 exceptions).

It should be noticed that
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.

The rationale of getting rid of pm_runtime_get_sync() is:

1. despite its name, this is actually a PM runtime resume call,
   but some developers didn't seem to realize that, as I got this
   pattern on some drivers:

        pm_runtime_get_sync(&client->dev);
        pm_runtime_disable(&client->dev);
        pm_runtime_set_suspended(&client->dev);
        pm_runtime_put_noidle(&client->dev);

   It makes no sense to resume PM just to suspend it again ;-)

2. Usual *_get() methods only increment their use count on success,
   but pm_runtime_get_sync() increments it unconditionally. Due to
   that, several drivers were mistakenly not calling
   pm_runtime_put_noidle() when it fails;

3. The name of the new variant is a lot clearer:
	pm_runtime_resume_and_get()
    As its same clearly says that this is a PM runtime resume function,
    that also increments the usage counter on success;

4. Consistency: we did similar changes subsystem wide with
   for instance strlcpy() and strcpy() that got replaced by
   strscpy(). Having all drivers using the same known-to-be-safe
   methods is a good thing;

5. Prevent newer drivers to copy-and-paste a code that it would
   be easier to break if they don't truly understand what's behind
   the scenes.

This series replace places  pm_runtime_get_sync(), by calling
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.

Patches 1 to 7 fix some issues that already exists at the current
PM runtime code;

patches 8 to 20 fix some usage_count problems that still exists
at the media subsystem;

patches 21 to 78 repaces pm_runtime_get_sync() by 
pm_runtime_resume_and_get();

Patch 79 (and a hunk on patch 78) documents the two exceptions
where pm_runtime_get_sync() will still be used for now.

---

v4:
    - Added a couple of additional fixes at existing PM runtime code;
    - Some patches are now more conservative in order to avoid causing
     regressions.
v3:
    - fix a compilation error;
v2:
    - addressed pointed issues and fixed a few other PM issues.


Mauro Carvalho Chehab (79):
  media: venus: fix PM runtime logic at venus_sys_error_handler()
  media: s6p_cec: decrement usage count if disabled
  media: i2c: ccs-core: return the right error code at suspend
  media: i2c: ov7740: don't resume at remove time
  media: i2c: video-i2c: don't resume at remove time
  media: i2c: imx334: fix the pm runtime get logic
  media: exynos-gsc: don't resume at remove time
  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 pm_runtime_get_sync() usage count
  media: renesas-ceu: Properly check for PM errors
  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: mtk-vcodec: fix pm_runtime_get_sync() usage count
  media: s5p-jpeg: fix pm_runtime_get_sync() usage count
  media: sti/delta: fix pm_runtime_get_sync() usage count
  media: sunxi: fix pm_runtime_get_sync() usage count
  staging: media: rkvdec: fix pm_runtime_get_sync() usage count
  staging: media: atomisp: 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: tegra-vde: use pm_runtime_resume_and_get()
  staging: media: tegra-video: use pm_runtime_resume_and_get()
  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: 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: rockchip/rga: use pm_runtime_resume_and_get()
  media: sti/hva: use pm_runtime_resume_and_get()
  media: sti/bdisp: 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: use pm_runtime_resume_and_get()
  media: venus: use pm_runtime_resume_and_get()
  media: venus: vdec: use pm_runtime_resume_and_get()
  media: venus: venc: use pm_runtime_resume_and_get()
  media: rcar-fcp: use pm_runtime_resume_and_get()
  media: rkisp1: 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: stm32: use pm_runtime_resume_and_get()
  media: sunxi: use pm_runtime_resume_and_get()
  media: ti-vpe: use pm_runtime_resume_and_get()
  media: vsp1: use pm_runtime_resume_and_get()
  media: rcar-vin: use pm_runtime_resume_and_get()
  media: hantro: use pm_runtime_resume_and_get()
  media: hantro: do a PM resume earlier

 drivers/media/cec/platform/s5p/s5p_cec.c      |  7 +++--
 drivers/media/i2c/ak7375.c                    | 10 +------
 drivers/media/i2c/ccs/ccs-core.c              | 18 +++++-------
 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                    |  7 +++--
 drivers/media/i2c/imx355.c                    |  6 ++--
 drivers/media/i2c/mt9m001.c                   |  9 ++++--
 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   | 22 ++++++++++----
 drivers/media/platform/atmel/atmel-isc-base.c | 27 ++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 +++++++++---
 drivers/media/platform/coda/coda-common.c     |  7 +++--
 drivers/media/platform/exynos-gsc/gsc-core.c  | 11 +++----
 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   |  4 +--
 .../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 |  8 ++---
 .../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      | 28 +++++++++++-------
 .../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   | 15 ++++++++--
 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          |  4 +--
 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  |  2 +-
 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     |  6 ++--
 .../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     | 29 ++++++++++++-------
 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         | 19 ++++++++++--
 drivers/staging/media/tegra-video/csi.c       |  3 +-
 drivers/staging/media/tegra-video/vi.c        |  3 +-
 92 files changed, 335 insertions(+), 347 deletions(-)

-- 
2.30.2



^ permalink raw reply	[flat|nested] 208+ messages in thread

* [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: Shawn Tu, Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Pengutronix Kernel Team,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Paul Kocialkowski, Mauro Carvalho Chehab, Dave Stevenson,
	Mauro Carvalho Chehab, Matt Ranostay, Krzysztof Kozlowski,
	Jonathan Hunter, linux-rockchip, Chen-Yu Tsai, Andy Gross,
	Matthias Brugger, Dongchun Zhu, Sakari Ailus, Bingbu Cao,
	Marek Szyprowski, Shunqian Zheng, Tianshu Qiu, NXP Linux Team,
	Philipp Zabel, devel, Jacopo Mondi, Sylwester Nawrocki,
	linux-tegra, Alexandre Torgue, Wenyou Yang,
	Manivannan Sadhasivam, linux-arm-msm, Sascha Hauer,
	Steve Longerbeam, linux-media, Maxime Ripard, Stanimir Varbanov,
	Benoit Parrot, Helen Koike, linux-samsung-soc, linux-mediatek,
	Jacek Anaszewski, mauro.chehab, Sylwester Nawrocki,
	Paul J. Murphy, Ezequiel Garcia, Daniele Alessandrelli,
	Chiranjeevi Rapolu, linux-arm-kernel, Jacob Chen, Jernej Skrabec,
	Hyungwoo Yang, linux-kernel, Robert Foss, Dan Scally,
	Sowjanya Komatineni, Maxime Coquelin, linux-renesas-soc,
	Yong Zhi, Shawn Guo

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.

After analyzing the feedback from version 1 of this series, I noticed
a few other weird behaviors at the PM runtime resume code. So, this
series start addressing some bugs and issues at the current code.
Then, it gets rid of pm_runtime_get_sync() at the media subsystem
(with 2 exceptions).

It should be noticed that
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.

The rationale of getting rid of pm_runtime_get_sync() is:

1. despite its name, this is actually a PM runtime resume call,
   but some developers didn't seem to realize that, as I got this
   pattern on some drivers:

        pm_runtime_get_sync(&client->dev);
        pm_runtime_disable(&client->dev);
        pm_runtime_set_suspended(&client->dev);
        pm_runtime_put_noidle(&client->dev);

   It makes no sense to resume PM just to suspend it again ;-)

2. Usual *_get() methods only increment their use count on success,
   but pm_runtime_get_sync() increments it unconditionally. Due to
   that, several drivers were mistakenly not calling
   pm_runtime_put_noidle() when it fails;

3. The name of the new variant is a lot clearer:
	pm_runtime_resume_and_get()
    As its same clearly says that this is a PM runtime resume function,
    that also increments the usage counter on success;

4. Consistency: we did similar changes subsystem wide with
   for instance strlcpy() and strcpy() that got replaced by
   strscpy(). Having all drivers using the same known-to-be-safe
   methods is a good thing;

5. Prevent newer drivers to copy-and-paste a code that it would
   be easier to break if they don't truly understand what's behind
   the scenes.

This series replace places  pm_runtime_get_sync(), by calling
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.

Patches 1 to 7 fix some issues that already exists at the current
PM runtime code;

patches 8 to 20 fix some usage_count problems that still exists
at the media subsystem;

patches 21 to 78 repaces pm_runtime_get_sync() by 
pm_runtime_resume_and_get();

Patch 79 (and a hunk on patch 78) documents the two exceptions
where pm_runtime_get_sync() will still be used for now.

---

v4:
    - Added a couple of additional fixes at existing PM runtime code;
    - Some patches are now more conservative in order to avoid causing
     regressions.
v3:
    - fix a compilation error;
v2:
    - addressed pointed issues and fixed a few other PM issues.


Mauro Carvalho Chehab (79):
  media: venus: fix PM runtime logic at venus_sys_error_handler()
  media: s6p_cec: decrement usage count if disabled
  media: i2c: ccs-core: return the right error code at suspend
  media: i2c: ov7740: don't resume at remove time
  media: i2c: video-i2c: don't resume at remove time
  media: i2c: imx334: fix the pm runtime get logic
  media: exynos-gsc: don't resume at remove time
  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 pm_runtime_get_sync() usage count
  media: renesas-ceu: Properly check for PM errors
  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: mtk-vcodec: fix pm_runtime_get_sync() usage count
  media: s5p-jpeg: fix pm_runtime_get_sync() usage count
  media: sti/delta: fix pm_runtime_get_sync() usage count
  media: sunxi: fix pm_runtime_get_sync() usage count
  staging: media: rkvdec: fix pm_runtime_get_sync() usage count
  staging: media: atomisp: 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: tegra-vde: use pm_runtime_resume_and_get()
  staging: media: tegra-video: use pm_runtime_resume_and_get()
  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: 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: rockchip/rga: use pm_runtime_resume_and_get()
  media: sti/hva: use pm_runtime_resume_and_get()
  media: sti/bdisp: 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: use pm_runtime_resume_and_get()
  media: venus: use pm_runtime_resume_and_get()
  media: venus: vdec: use pm_runtime_resume_and_get()
  media: venus: venc: use pm_runtime_resume_and_get()
  media: rcar-fcp: use pm_runtime_resume_and_get()
  media: rkisp1: 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: stm32: use pm_runtime_resume_and_get()
  media: sunxi: use pm_runtime_resume_and_get()
  media: ti-vpe: use pm_runtime_resume_and_get()
  media: vsp1: use pm_runtime_resume_and_get()
  media: rcar-vin: use pm_runtime_resume_and_get()
  media: hantro: use pm_runtime_resume_and_get()
  media: hantro: do a PM resume earlier

 drivers/media/cec/platform/s5p/s5p_cec.c      |  7 +++--
 drivers/media/i2c/ak7375.c                    | 10 +------
 drivers/media/i2c/ccs/ccs-core.c              | 18 +++++-------
 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                    |  7 +++--
 drivers/media/i2c/imx355.c                    |  6 ++--
 drivers/media/i2c/mt9m001.c                   |  9 ++++--
 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   | 22 ++++++++++----
 drivers/media/platform/atmel/atmel-isc-base.c | 27 ++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 +++++++++---
 drivers/media/platform/coda/coda-common.c     |  7 +++--
 drivers/media/platform/exynos-gsc/gsc-core.c  | 11 +++----
 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   |  4 +--
 .../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 |  8 ++---
 .../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      | 28 +++++++++++-------
 .../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   | 15 ++++++++--
 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          |  4 +--
 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  |  2 +-
 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     |  6 ++--
 .../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     | 29 ++++++++++++-------
 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         | 19 ++++++++++--
 drivers/staging/media/tegra-video/csi.c       |  3 +-
 drivers/staging/media/tegra-video/vi.c        |  3 +-
 92 files changed, 335 insertions(+), 347 deletions(-)

-- 
2.30.2


_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Lad, Prabhakar,
	Paul J. Murphy, Alexandre Torgue, Andrzej Hajda,
	Andrzej Pietrasiewicz, Andy Gross, Benoit Parrot, Bingbu Cao,
	Bjorn Andersson, Chen-Yu Tsai, Chiranjeevi Rapolu,
	Dafna Hirschfeld, Dan Scally, Daniele Alessandrelli,
	Dave Stevenson, Dmitry Osipenko, Dongchun Zhu, Ezequiel Garcia,
	Fabio Estevam, Heiko Stuebner, Helen Koike, Hyungwoo Yang,
	Jacek Anaszewski, Jacob Chen, Jacopo Mondi, Jernej Skrabec,
	Jonathan Hunter, Krzysztof Kozlowski, Leon Luo,
	Manivannan Sadhasivam, Marek Szyprowski, Matt Ranostay,
	Matthias Brugger, Mauro Carvalho Chehab, Maxime Coquelin,
	Maxime Ripard, NXP Linux Team, Paul Kocialkowski,
	Pengutronix Kernel Team, Philipp Zabel, Ricardo Ribalda,
	Robert Foss, Rui Miguel Silva, Sakari Ailus, Sascha Hauer,
	Shawn Guo, Shawn Tu, Shunqian Zheng, Sowjanya Komatineni,
	Stanimir Varbanov, Steve Longerbeam, Sylwester Nawrocki,
	Sylwester Nawrocki, Thierry Reding, Tianshu Qiu, Todor Tomov,
	Wenyou Yang, Yong Zhi, devel, linux-arm-kernel, linux-arm-msm,
	linux-kernel, linux-media, linux-mediatek, linux-renesas-soc,
	linux-rockchip, linux-samsung-soc, linux-stm32, linux-tegra

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.

After analyzing the feedback from version 1 of this series, I noticed
a few other weird behaviors at the PM runtime resume code. So, this
series start addressing some bugs and issues at the current code.
Then, it gets rid of pm_runtime_get_sync() at the media subsystem
(with 2 exceptions).

It should be noticed that
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.

The rationale of getting rid of pm_runtime_get_sync() is:

1. despite its name, this is actually a PM runtime resume call,
   but some developers didn't seem to realize that, as I got this
   pattern on some drivers:

        pm_runtime_get_sync(&client->dev);
        pm_runtime_disable(&client->dev);
        pm_runtime_set_suspended(&client->dev);
        pm_runtime_put_noidle(&client->dev);

   It makes no sense to resume PM just to suspend it again ;-)

2. Usual *_get() methods only increment their use count on success,
   but pm_runtime_get_sync() increments it unconditionally. Due to
   that, several drivers were mistakenly not calling
   pm_runtime_put_noidle() when it fails;

3. The name of the new variant is a lot clearer:
	pm_runtime_resume_and_get()
    As its same clearly says that this is a PM runtime resume function,
    that also increments the usage counter on success;

4. Consistency: we did similar changes subsystem wide with
   for instance strlcpy() and strcpy() that got replaced by
   strscpy(). Having all drivers using the same known-to-be-safe
   methods is a good thing;

5. Prevent newer drivers to copy-and-paste a code that it would
   be easier to break if they don't truly understand what's behind
   the scenes.

This series replace places  pm_runtime_get_sync(), by calling
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.

Patches 1 to 7 fix some issues that already exists at the current
PM runtime code;

patches 8 to 20 fix some usage_count problems that still exists
at the media subsystem;

patches 21 to 78 repaces pm_runtime_get_sync() by 
pm_runtime_resume_and_get();

Patch 79 (and a hunk on patch 78) documents the two exceptions
where pm_runtime_get_sync() will still be used for now.

---

v4:
    - Added a couple of additional fixes at existing PM runtime code;
    - Some patches are now more conservative in order to avoid causing
     regressions.
v3:
    - fix a compilation error;
v2:
    - addressed pointed issues and fixed a few other PM issues.


Mauro Carvalho Chehab (79):
  media: venus: fix PM runtime logic at venus_sys_error_handler()
  media: s6p_cec: decrement usage count if disabled
  media: i2c: ccs-core: return the right error code at suspend
  media: i2c: ov7740: don't resume at remove time
  media: i2c: video-i2c: don't resume at remove time
  media: i2c: imx334: fix the pm runtime get logic
  media: exynos-gsc: don't resume at remove time
  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 pm_runtime_get_sync() usage count
  media: renesas-ceu: Properly check for PM errors
  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: mtk-vcodec: fix pm_runtime_get_sync() usage count
  media: s5p-jpeg: fix pm_runtime_get_sync() usage count
  media: sti/delta: fix pm_runtime_get_sync() usage count
  media: sunxi: fix pm_runtime_get_sync() usage count
  staging: media: rkvdec: fix pm_runtime_get_sync() usage count
  staging: media: atomisp: 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: tegra-vde: use pm_runtime_resume_and_get()
  staging: media: tegra-video: use pm_runtime_resume_and_get()
  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: 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: rockchip/rga: use pm_runtime_resume_and_get()
  media: sti/hva: use pm_runtime_resume_and_get()
  media: sti/bdisp: 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: use pm_runtime_resume_and_get()
  media: venus: use pm_runtime_resume_and_get()
  media: venus: vdec: use pm_runtime_resume_and_get()
  media: venus: venc: use pm_runtime_resume_and_get()
  media: rcar-fcp: use pm_runtime_resume_and_get()
  media: rkisp1: 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: stm32: use pm_runtime_resume_and_get()
  media: sunxi: use pm_runtime_resume_and_get()
  media: ti-vpe: use pm_runtime_resume_and_get()
  media: vsp1: use pm_runtime_resume_and_get()
  media: rcar-vin: use pm_runtime_resume_and_get()
  media: hantro: use pm_runtime_resume_and_get()
  media: hantro: do a PM resume earlier

 drivers/media/cec/platform/s5p/s5p_cec.c      |  7 +++--
 drivers/media/i2c/ak7375.c                    | 10 +------
 drivers/media/i2c/ccs/ccs-core.c              | 18 +++++-------
 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                    |  7 +++--
 drivers/media/i2c/imx355.c                    |  6 ++--
 drivers/media/i2c/mt9m001.c                   |  9 ++++--
 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   | 22 ++++++++++----
 drivers/media/platform/atmel/atmel-isc-base.c | 27 ++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 +++++++++---
 drivers/media/platform/coda/coda-common.c     |  7 +++--
 drivers/media/platform/exynos-gsc/gsc-core.c  | 11 +++----
 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   |  4 +--
 .../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 |  8 ++---
 .../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      | 28 +++++++++++-------
 .../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   | 15 ++++++++--
 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          |  4 +--
 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  |  2 +-
 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     |  6 ++--
 .../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     | 29 ++++++++++++-------
 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         | 19 ++++++++++--
 drivers/staging/media/tegra-video/csi.c       |  3 +-
 drivers/staging/media/tegra-video/vi.c        |  3 +-
 92 files changed, 335 insertions(+), 347 deletions(-)

-- 
2.30.2



_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 208+ messages in thread

* [PATCH v4 01/79] media: venus: fix PM runtime logic at venus_sys_error_handler()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-30 15:21   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andy Gross,
	Bjorn Andersson, Hans Verkuil, Mauro Carvalho Chehab,
	Stanimir Varbanov, linux-arm-msm, linux-kernel, linux-media

The venus_sys_error_handler() assumes that pm_runtime was
able to resume, as it does things like:

	while (pm_runtime_active(core->dev_dec) || pm_runtime_active(core->dev_enc))
		msleep(10);

Well, if, for whatever reason, this won't happen, the routine
won't do what's expected. So, check for the returned error
condition, warning if it returns an error.

Fixes: af2c3834c8ca ("[media] media: venus: adding core part and helper functions")
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/qcom/venus/core.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c
index 54bac7ec14c5..c80c27c87ccc 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -84,7 +84,11 @@ static void venus_sys_error_handler(struct work_struct *work)
 			container_of(work, struct venus_core, work.work);
 	int ret = 0;
 
-	pm_runtime_get_sync(core->dev);
+	ret = pm_runtime_get_sync(core->dev);
+	if (WARN_ON(ret < 0)) {
+		pm_runtime_put_noidle(core->dev);
+		return;
+	}
 
 	hfi_core_deinit(core, true);
 
@@ -106,9 +110,13 @@ static void venus_sys_error_handler(struct work_struct *work)
 
 	hfi_reinit(core);
 
-	pm_runtime_get_sync(core->dev);
+	ret = pm_runtime_get_sync(core->dev);
+	if (WARN_ON(ret < 0)) {
+		pm_runtime_put_noidle(core->dev);
+		return;
+	}
 
-	ret |= venus_boot(core);
+	ret = venus_boot(core);
 	ret |= hfi_core_resume(core, true);
 
 	enable_irq(core->irq);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 02/79] media: s6p_cec: decrement usage count if disabled
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (2 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-28 15:31   ` Sylwester Nawrocki
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Hans Verkuil,
	Kamil Debski, Marek Szyprowski, Mauro Carvalho Chehab,
	linux-kernel, linux-media, linux-samsung-soc, Sylwester Nawrocki

There's a bug at s5p_cec_adap_enable(): if called to
disable the device, it should call pm_runtime_put()
instead of pm_runtime_disable(), as the goal here is to
decrement the usage_count and not to disable PM runtime.

Reported-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Fixes: 1bcbf6f4b6b0 ("[media] cec: s5p-cec: Add s5p-cec driver")
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/cec/platform/s5p/s5p_cec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/cec/platform/s5p/s5p_cec.c b/drivers/media/cec/platform/s5p/s5p_cec.c
index 2a3e7ffefe0a..3c7c4c3c798c 100644
--- a/drivers/media/cec/platform/s5p/s5p_cec.c
+++ b/drivers/media/cec/platform/s5p/s5p_cec.c
@@ -51,7 +51,7 @@ static int s5p_cec_adap_enable(struct cec_adapter *adap, bool enable)
 	} else {
 		s5p_cec_mask_tx_interrupts(cec);
 		s5p_cec_mask_rx_interrupts(cec);
-		pm_runtime_disable(cec->dev);
+		pm_runtime_put(cec->dev);
 	}
 
 	return 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 03/79] media: i2c: ccs-core: return the right error code at suspend
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (3 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Sakari Ailus, linux-kernel, linux-media

If pm_runtime resume logic fails, return the error code
provided by it, instead of -EAGAIN, as, depending on what
caused it to fail, it may not be something that would be
recovered.

Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Fixes: cbba45d43631 ("[media] smiapp: Use runtime PM")
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/i2c/ccs/ccs-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c
index 9dc3f45da3dc..b05f409014b2 100644
--- a/drivers/media/i2c/ccs/ccs-core.c
+++ b/drivers/media/i2c/ccs/ccs-core.c
@@ -3093,7 +3093,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)
 	if (rval < 0) {
 		pm_runtime_put_noidle(dev);
 
-		return -EAGAIN;
+		return rval;
 	}
 
 	if (sensor->streaming)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 04/79] media: i2c: ov7740: don't resume at remove time
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (4 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Sakari Ailus, Songjun Wu, Wenyou Yang,
	linux-kernel, linux-media

Calling pm_runtime_get_sync() at driver's removal time is
not right, as this will resume PM runtime. This is clearly
not what it is desired there, since it calls
pm_runtime_set_suspended() afterwards.

So, just remove pm runtime get/put logic from the device
removal logic.

Fixes: 39c5c4471b8d ("media: i2c: Add the ov7740 image sensor driver")
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/i2c/ov7740.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
index 47a9003d29d6..ed6904b2e8f5 100644
--- a/drivers/media/i2c/ov7740.c
+++ b/drivers/media/i2c/ov7740.c
@@ -1165,10 +1165,8 @@ static int ov7740_remove(struct i2c_client *client)
 	v4l2_async_unregister_subdev(sd);
 	ov7740_free_controls(ov7740);
 
-	pm_runtime_get_sync(&client->dev);
 	pm_runtime_disable(&client->dev);
 	pm_runtime_set_suspended(&client->dev);
-	pm_runtime_put_noidle(&client->dev);
 
 	ov7740_set_power(ov7740, 0);
 	return 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 05/79] media: i2c: video-i2c: don't resume at remove time
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (5 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Akinobu Mita,
	Hans Verkuil, Matt Ranostay, Mauro Carvalho Chehab, Sakari Ailus,
	linux-kernel, linux-media

Calling pm_runtime_get_sync() at driver's removal time is
not right, as this will resume PM runtime. This is clearly
not what it is desired there, since it calls
pm_runtime_set_suspended() afterwards.

So, just remove pm runtime get/put logic from the device
removal logic.

Fixes: 69d2a734c5dc ("media: video-i2c: support runtime PM")
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/i2c/video-i2c.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index 0465832a4090..c9a774f4c8d2 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -893,10 +893,8 @@ static int video_i2c_remove(struct i2c_client *client)
 {
 	struct video_i2c_data *data = i2c_get_clientdata(client);
 
-	pm_runtime_get_sync(&client->dev);
 	pm_runtime_disable(&client->dev);
 	pm_runtime_set_suspended(&client->dev);
-	pm_runtime_put_noidle(&client->dev);
 
 	if (data->chip->set_power)
 		data->chip->set_power(data, false);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 06/79] media: i2c: imx334: fix the pm runtime get logic
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (6 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-30 15:54   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Paul J. Murphy,
	Daniele Alessandrelli, Mauro Carvalho Chehab, linux-kernel,
	linux-media, Dan Carpenter

The PM runtime get logic is currently broken, as it checks if
ret is zero instead of checking if it is an error code,
as reported by Dan Carpenter.

While here, use the pm_runtime_resume_and_get() as added by:
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.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/i2c/imx334.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c
index 047aa7658d21..23f28606e570 100644
--- a/drivers/media/i2c/imx334.c
+++ b/drivers/media/i2c/imx334.c
@@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(imx334->dev);
-		if (ret)
-			goto error_power_off;
+		ret = pm_runtime_resume_and_get(imx334->dev);
+		if (ret < 0)
+			goto error_unlock;
 
 		ret = imx334_start_streaming(imx334);
 		if (ret)
@@ -737,6 +737,7 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 
 error_power_off:
 	pm_runtime_put(imx334->dev);
+error_unlock:
 	mutex_unlock(&imx334->mutex);
 
 	return ret;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Hans Verkuil, Krzysztof Kozlowski, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-samsung-soc

Calling pm_runtime_get_sync() at driver's removal time is not
needed, as this will resume PM runtime. Also, the PM runtime
code at pm_runtime_disable() already calls it, if it detects
the need.

So, change the logic in order to disable PM runtime earlier.

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

diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index 9f41c2e7097a..8b943075c503 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.c
+++ b/drivers/media/platform/exynos-gsc/gsc-core.c
@@ -1210,18 +1210,19 @@ static int gsc_remove(struct platform_device *pdev)
 	struct gsc_dev *gsc = platform_get_drvdata(pdev);
 	int i;
 
-	pm_runtime_get_sync(&pdev->dev);
-
 	gsc_unregister_m2m_device(gsc);
 	v4l2_device_unregister(&gsc->v4l2_dev);
 
 	vb2_dma_contig_clear_max_seg_size(&pdev->dev);
-	for (i = 0; i < gsc->num_clocks; i++)
-		clk_disable_unprepare(gsc->clock[i]);
 
-	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
+	if (!pm_runtime_status_suspended(dev))
+		for (i = 0; i < gsc->num_clocks; i++)
+			clk_disable_unprepare(gsc->clock[i]);
+
+	pm_runtime_set_suspended(dev);
+
 	dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Hans Verkuil, Krzysztof Kozlowski, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-samsung-soc

Calling pm_runtime_get_sync() at driver's removal time is not
needed, as this will resume PM runtime. Also, the PM runtime
code at pm_runtime_disable() already calls it, if it detects
the need.

So, change the logic in order to disable PM runtime earlier.

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

diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index 9f41c2e7097a..8b943075c503 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.c
+++ b/drivers/media/platform/exynos-gsc/gsc-core.c
@@ -1210,18 +1210,19 @@ static int gsc_remove(struct platform_device *pdev)
 	struct gsc_dev *gsc = platform_get_drvdata(pdev);
 	int i;
 
-	pm_runtime_get_sync(&pdev->dev);
-
 	gsc_unregister_m2m_device(gsc);
 	v4l2_device_unregister(&gsc->v4l2_dev);
 
 	vb2_dma_contig_clear_max_seg_size(&pdev->dev);
-	for (i = 0; i < gsc->num_clocks; i++)
-		clk_disable_unprepare(gsc->clock[i]);
 
-	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
+	if (!pm_runtime_status_suspended(dev))
+		for (i = 0; i < gsc->num_clocks; i++)
+			clk_disable_unprepare(gsc->clock[i]);
+
+	pm_runtime_set_suspended(dev);
+
 	dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
 	return 0;
 }
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 08/79] media: atmel: properly get pm_runtime
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Alexandre Belloni,
	Eugen Hristev, Ludovic Desroches, Mauro Carvalho Chehab,
	Nicolas Ferre, linux-arm-kernel, linux-kernel, linux-media

There are several issues in the way the atmel driver handles
pm_runtime_get_sync():

- it doesn't check return codes;
- it doesn't properly decrement the usage_count on all places;
- it starts streaming even if pm_runtime_get_sync() fails.
- while it tries to get pm_runtime at the clock enable logic,
  it doesn't check if the operation was suceeded.

Replace all occurrences of it to use the new kAPI:
pm_runtime_resume_and_get(), which ensures that, if the
return code is not negative, the usage_count was incremented.

With that, add additional checks when this is called, in order
to ensure that errors will be properly addressed.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/atmel/atmel-isc-base.c | 27 ++++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 ++++++++++---
 2 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index fe3ec8d0eaee..02543fe42e9d 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
 static int isc_clk_prepare(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return 0;
+	}
 
 	return isc_wait_clk_stable(hw);
 }
@@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
 	u32 status;
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return 0;
+	}
 
 	regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
 
@@ -807,7 +815,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 		goto err_start_stream;
 	}
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0)
+		goto err_pm_get;
 
 	ret = isc_configure(isc);
 	if (unlikely(ret))
@@ -838,7 +848,7 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 err_configure:
 	pm_runtime_put_sync(isc->dev);
-
+err_pm_get:
 	v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
 
 err_start_stream:
@@ -1809,6 +1819,7 @@ static void isc_awb_work(struct work_struct *w)
 	u32 baysel;
 	unsigned long flags;
 	u32 min, max;
+	int ret;
 
 	/* streaming is not active anymore */
 	if (isc->stop)
@@ -1831,7 +1842,9 @@ static void isc_awb_work(struct work_struct *w)
 	ctrls->hist_id = hist_id;
 	baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0)
+		return;
 
 	/*
 	 * only update if we have all the required histograms and controls
diff --git a/drivers/media/platform/atmel/atmel-isi.c b/drivers/media/platform/atmel/atmel-isi.c
index 0514be6153df..6a433926726d 100644
--- a/drivers/media/platform/atmel/atmel-isi.c
+++ b/drivers/media/platform/atmel/atmel-isi.c
@@ -422,7 +422,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
 	struct frame_buffer *buf, *node;
 	int ret;
 
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;
 
 	/* Enable stream on the sub device */
 	ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
@@ -782,9 +784,10 @@ static int isi_enum_frameintervals(struct file *file, void *fh,
 	return 0;
 }
 
-static void isi_camera_set_bus_param(struct atmel_isi *isi)
+static int isi_camera_set_bus_param(struct atmel_isi *isi)
 {
 	u32 cfg1 = 0;
+	int ret;
 
 	/* set bus param for ISI */
 	if (isi->pdata.hsync_act_low)
@@ -801,12 +804,16 @@ static void isi_camera_set_bus_param(struct atmel_isi *isi)
 	cfg1 |= ISI_CFG1_THMASK_BEATS_16;
 
 	/* Enable PM and peripheral clock before operate isi registers */
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;
 
 	isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
 	isi_writel(isi, ISI_CFG1, cfg1);
 
 	pm_runtime_put(isi->dev);
+
+	return 0;
 }
 
 /* -----------------------------------------------------------------------*/
@@ -1085,7 +1092,11 @@ static int isi_graph_notify_complete(struct v4l2_async_notifier *notifier)
 		dev_err(isi->dev, "No supported mediabus format found\n");
 		return ret;
 	}
-	isi_camera_set_bus_param(isi);
+	ret = isi_camera_set_bus_param(isi);
+	if (ret) {
+		dev_err(isi->dev, "Can't wake up device\n");
+		return ret;
+	}
 
 	ret = isi_set_default_fmt(isi);
 	if (ret) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 08/79] media: atmel: properly get pm_runtime
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: Alexandre Belloni, Mauro Carvalho Chehab, linux-kernel, linuxarm,
	Ludovic Desroches, mauro.chehab, Eugen Hristev,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-media

There are several issues in the way the atmel driver handles
pm_runtime_get_sync():

- it doesn't check return codes;
- it doesn't properly decrement the usage_count on all places;
- it starts streaming even if pm_runtime_get_sync() fails.
- while it tries to get pm_runtime at the clock enable logic,
  it doesn't check if the operation was suceeded.

Replace all occurrences of it to use the new kAPI:
pm_runtime_resume_and_get(), which ensures that, if the
return code is not negative, the usage_count was incremented.

With that, add additional checks when this is called, in order
to ensure that errors will be properly addressed.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/atmel/atmel-isc-base.c | 27 ++++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 ++++++++++---
 2 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index fe3ec8d0eaee..02543fe42e9d 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
 static int isc_clk_prepare(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return 0;
+	}
 
 	return isc_wait_clk_stable(hw);
 }
@@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
 	u32 status;
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return 0;
+	}
 
 	regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
 
@@ -807,7 +815,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 		goto err_start_stream;
 	}
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0)
+		goto err_pm_get;
 
 	ret = isc_configure(isc);
 	if (unlikely(ret))
@@ -838,7 +848,7 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 err_configure:
 	pm_runtime_put_sync(isc->dev);
-
+err_pm_get:
 	v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
 
 err_start_stream:
@@ -1809,6 +1819,7 @@ static void isc_awb_work(struct work_struct *w)
 	u32 baysel;
 	unsigned long flags;
 	u32 min, max;
+	int ret;
 
 	/* streaming is not active anymore */
 	if (isc->stop)
@@ -1831,7 +1842,9 @@ static void isc_awb_work(struct work_struct *w)
 	ctrls->hist_id = hist_id;
 	baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0)
+		return;
 
 	/*
 	 * only update if we have all the required histograms and controls
diff --git a/drivers/media/platform/atmel/atmel-isi.c b/drivers/media/platform/atmel/atmel-isi.c
index 0514be6153df..6a433926726d 100644
--- a/drivers/media/platform/atmel/atmel-isi.c
+++ b/drivers/media/platform/atmel/atmel-isi.c
@@ -422,7 +422,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
 	struct frame_buffer *buf, *node;
 	int ret;
 
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;
 
 	/* Enable stream on the sub device */
 	ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
@@ -782,9 +784,10 @@ static int isi_enum_frameintervals(struct file *file, void *fh,
 	return 0;
 }
 
-static void isi_camera_set_bus_param(struct atmel_isi *isi)
+static int isi_camera_set_bus_param(struct atmel_isi *isi)
 {
 	u32 cfg1 = 0;
+	int ret;
 
 	/* set bus param for ISI */
 	if (isi->pdata.hsync_act_low)
@@ -801,12 +804,16 @@ static void isi_camera_set_bus_param(struct atmel_isi *isi)
 	cfg1 |= ISI_CFG1_THMASK_BEATS_16;
 
 	/* Enable PM and peripheral clock before operate isi registers */
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;
 
 	isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
 	isi_writel(isi, ISI_CFG1, cfg1);
 
 	pm_runtime_put(isi->dev);
+
+	return 0;
 }
 
 /* -----------------------------------------------------------------------*/
@@ -1085,7 +1092,11 @@ static int isi_graph_notify_complete(struct v4l2_async_notifier *notifier)
 		dev_err(isi->dev, "No supported mediabus format found\n");
 		return ret;
 	}
-	isi_camera_set_bus_param(isi);
+	ret = isi_camera_set_bus_param(isi);
+	if (ret) {
+		dev_err(isi->dev, "Can't wake up device\n");
+		return ret;
+	}
 
 	ret = isi_set_default_fmt(isi);
 	if (ret) {
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 09/79] media: marvel-ccic: fix some issues when getting pm_runtime
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (9 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-30 16:29   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Gustavo A. R. Silva, Allen Pais, Chuhong Yuan, Ezequiel Garcia,
	Hans Verkuil, Helen Koike, Lubomir Rintel, Mauro Carvalho Chehab,
	Sakari Ailus, Vaibhav Gupta, linux-kernel, linux-media

Calling pm_runtime_get_sync() is bad, since even when it
returns an error, pm_runtime_put*() should be called.
So, use instead pm_runtime_resume_and_get().

While here, ensure that the error condition will be checked
during clock enable an media open() calls.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/marvell-ccic/mcam-core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 141bf5d97a04..ea87110d9073 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -918,6 +918,7 @@ static int mclk_enable(struct clk_hw *hw)
 	struct mcam_camera *cam = container_of(hw, struct mcam_camera, mclk_hw);
 	int mclk_src;
 	int mclk_div;
+	int ret;
 
 	/*
 	 * Clock the sensor appropriately.  Controller clock should
@@ -931,7 +932,9 @@ static int mclk_enable(struct clk_hw *hw)
 		mclk_div = 2;
 	}
 
-	pm_runtime_get_sync(cam->dev);
+	ret = pm_runtime_resume_and_get(cam->dev);
+	if (ret < 0)
+		return ret;
 	clk_enable(cam->clk[0]);
 	mcam_reg_write(cam, REG_CLKCTRL, (mclk_src << 29) | mclk_div);
 	mcam_ctlr_power_up(cam);
@@ -1611,7 +1614,9 @@ static int mcam_v4l_open(struct file *filp)
 		ret = sensor_call(cam, core, s_power, 1);
 		if (ret)
 			goto out;
-		pm_runtime_get_sync(cam->dev);
+		ret = pm_runtime_resume_and_get(cam->dev);
+		if (ret < 0)
+			goto out;
 		__mcam_cam_reset(cam);
 		mcam_set_config_needed(cam, 1);
 	}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 10/79] media: mdk-mdp: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrew-CT Chen,
	Houlong Wei, Matthias Brugger, Mauro Carvalho Chehab,
	Minghsiu Tsai, linux-arm-kernel, linux-kernel, linux-media,
	linux-mediatek

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, fix the return contition of mtk_mdp_m2m_start_streaming(),
as it doesn't make any sense to return 0 if the PM runtime failed
to resume.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
index ace4528cdc5e..f14779e7596e 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
@@ -391,12 +391,12 @@ static int mtk_mdp_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct mtk_mdp_ctx *ctx = q->drv_priv;
 	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->mdp_dev->pdev->dev);
+	ret = pm_runtime_resume_and_get(&ctx->mdp_dev->pdev->dev);
 	if (ret < 0)
-		mtk_mdp_dbg(1, "[%d] pm_runtime_get_sync failed:%d",
+		mtk_mdp_dbg(1, "[%d] pm_runtime_resume_and_get failed:%d",
 			    ctx->id, ret);
 
-	return 0;
+	return ret;
 }
 
 static void *mtk_mdp_m2m_buf_remove(struct mtk_mdp_ctx *ctx,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 10/79] media: mdk-mdp: fix pm_runtime_get_sync() usage count
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrew-CT Chen,
	Houlong Wei, Matthias Brugger, Mauro Carvalho Chehab,
	Minghsiu Tsai, linux-arm-kernel, linux-kernel, linux-media,
	linux-mediatek

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, fix the return contition of mtk_mdp_m2m_start_streaming(),
as it doesn't make any sense to return 0 if the PM runtime failed
to resume.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
index ace4528cdc5e..f14779e7596e 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
@@ -391,12 +391,12 @@ static int mtk_mdp_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct mtk_mdp_ctx *ctx = q->drv_priv;
 	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->mdp_dev->pdev->dev);
+	ret = pm_runtime_resume_and_get(&ctx->mdp_dev->pdev->dev);
 	if (ret < 0)
-		mtk_mdp_dbg(1, "[%d] pm_runtime_get_sync failed:%d",
+		mtk_mdp_dbg(1, "[%d] pm_runtime_resume_and_get failed:%d",
 			    ctx->id, ret);
 
-	return 0;
+	return ret;
 }
 
 static void *mtk_mdp_m2m_buf_remove(struct mtk_mdp_ctx *ctx,
-- 
2.30.2


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 10/79] media: mdk-mdp: fix pm_runtime_get_sync() usage count
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrew-CT Chen,
	Houlong Wei, Matthias Brugger, Mauro Carvalho Chehab,
	Minghsiu Tsai, linux-arm-kernel, linux-kernel, linux-media,
	linux-mediatek

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, fix the return contition of mtk_mdp_m2m_start_streaming(),
as it doesn't make any sense to return 0 if the PM runtime failed
to resume.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
index ace4528cdc5e..f14779e7596e 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
@@ -391,12 +391,12 @@ static int mtk_mdp_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct mtk_mdp_ctx *ctx = q->drv_priv;
 	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->mdp_dev->pdev->dev);
+	ret = pm_runtime_resume_and_get(&ctx->mdp_dev->pdev->dev);
 	if (ret < 0)
-		mtk_mdp_dbg(1, "[%d] pm_runtime_get_sync failed:%d",
+		mtk_mdp_dbg(1, "[%d] pm_runtime_resume_and_get failed:%d",
 			    ctx->id, ret);
 
-	return 0;
+	return ret;
 }
 
 static void *mtk_mdp_m2m_buf_remove(struct mtk_mdp_ctx *ctx,
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 11/79] media: rcar_fdp1: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (11 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-30 16:26   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Kieran Bingham,
	Mauro Carvalho Chehab, linux-kernel, linux-media,
	linux-renesas-soc

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.

Also, right now, the driver is ignoring any troubles when
trying to do PM resume. So, add the proper error handling
for the code.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/rcar_fdp1.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/rcar_fdp1.c b/drivers/media/platform/rcar_fdp1.c
index 01c1fbb97bf6..c32d237af618 100644
--- a/drivers/media/platform/rcar_fdp1.c
+++ b/drivers/media/platform/rcar_fdp1.c
@@ -2140,7 +2140,13 @@ static int fdp1_open(struct file *file)
 	}
 
 	/* Perform any power management required */
-	pm_runtime_get_sync(fdp1->dev);
+	ret = pm_runtime_resume_and_get(fdp1->dev);
+	if (ret < 0) {
+		v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
+		v4l2_ctrl_handler_free(&ctx->hdl);
+		kfree(ctx);
+		goto done;
+	}
 
 	v4l2_fh_add(&ctx->fh);
 
@@ -2351,7 +2357,9 @@ static int fdp1_probe(struct platform_device *pdev)
 
 	/* Power up the cells to read HW */
 	pm_runtime_enable(&pdev->dev);
-	pm_runtime_get_sync(fdp1->dev);
+	ret = pm_runtime_resume_and_get(fdp1->dev);
+	if (ret < 0)
+		return ret;
 
 	hw_version = fdp1_read(fdp1, FD1_IP_INTDATA);
 	switch (hw_version) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 12/79] media: renesas-ceu: Properly check for PM errors
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (12 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-30 16:28   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Jacopo Mondi,
	Mauro Carvalho Chehab, linux-kernel, linux-media,
	linux-renesas-soc

Right now, the driver just assumes that PM runtime resume
worked, but it may fail.

Well, the pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.

So, using it is tricky. Let's 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")
and return an error if something bad happens.

This should ensure that the PM runtime usage_count will be
properly decremented if an error happens at open time.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/renesas-ceu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/renesas-ceu.c b/drivers/media/platform/renesas-ceu.c
index cd137101d41e..17f01b6e3fe0 100644
--- a/drivers/media/platform/renesas-ceu.c
+++ b/drivers/media/platform/renesas-ceu.c
@@ -1099,10 +1099,10 @@ static int ceu_open(struct file *file)
 
 	mutex_lock(&ceudev->mlock);
 	/* Causes soft-reset and sensor power on on first open */
-	pm_runtime_get_sync(ceudev->dev);
+	ret = pm_runtime_resume_and_get(ceudev->dev);
 	mutex_unlock(&ceudev->mlock);
 
-	return 0;
+	return ret;
 }
 
 static int ceu_release(struct file *file)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 13/79] media: s5p: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (13 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Hans Verkuil,
	Marek Szyprowski, Mauro Carvalho Chehab, linux-kernel,
	linux-media, linux-samsung-soc, Sylwester Nawrocki

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
s5p_cec_adap_enable().

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/cec/platform/s5p/s5p_cec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/cec/platform/s5p/s5p_cec.c b/drivers/media/cec/platform/s5p/s5p_cec.c
index 3c7c4c3c798c..028a09a7531e 100644
--- a/drivers/media/cec/platform/s5p/s5p_cec.c
+++ b/drivers/media/cec/platform/s5p/s5p_cec.c
@@ -35,10 +35,13 @@ MODULE_PARM_DESC(debug, "debug level (0-2)");
 
 static int s5p_cec_adap_enable(struct cec_adapter *adap, bool enable)
 {
+	int ret;
 	struct s5p_cec_dev *cec = cec_get_drvdata(adap);
 
 	if (enable) {
-		pm_runtime_get_sync(cec->dev);
+		ret = pm_runtime_resume_and_get(cec->dev);
+		if (ret < 0)
+			return ret;
 
 		s5p_cec_reset(cec);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 14/79] media: am437x: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (14 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-30 16:36   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Lad, Prabhakar,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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, ensure that the driver will check if PM runtime
resumed at vpfe_initialize_device().

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/am437x/am437x-vpfe.c | 22 +++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
index 6cdc77dda0e4..bced526f30f2 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -1021,7 +1021,9 @@ static int vpfe_initialize_device(struct vpfe_device *vpfe)
 	if (ret)
 		return ret;
 
-	pm_runtime_get_sync(vpfe->pdev);
+	ret = pm_runtime_resume_and_get(vpfe->pdev);
+	if (ret < 0)
+		return ret;
 
 	vpfe_config_enable(&vpfe->ccdc, 1);
 
@@ -2443,7 +2445,11 @@ static int vpfe_probe(struct platform_device *pdev)
 	pm_runtime_enable(&pdev->dev);
 
 	/* for now just enable it here instead of waiting for the open */
-	pm_runtime_get_sync(&pdev->dev);
+	ret = pm_runtime_resume_and_get(&pdev->dev);
+	if (ret < 0) {
+		vpfe_err(vpfe, "Unable to resume device.\n");
+		goto probe_out_v4l2_unregister;
+	}
 
 	vpfe_ccdc_config_defaults(ccdc);
 
@@ -2527,10 +2533,11 @@ static int vpfe_suspend(struct device *dev)
 {
 	struct vpfe_device *vpfe = dev_get_drvdata(dev);
 	struct vpfe_ccdc *ccdc = &vpfe->ccdc;
+	int ret;
 
 	/* only do full suspend if streaming has started */
 	if (vb2_start_streaming_called(&vpfe->buffer_queue)) {
-		pm_runtime_get_sync(dev);
+		ret = pm_runtime_resume_and_get(dev);
 		vpfe_config_enable(ccdc, 1);
 
 		/* Save VPFE context */
@@ -2541,7 +2548,8 @@ static int vpfe_suspend(struct device *dev)
 		vpfe_config_enable(ccdc, 0);
 
 		/* Disable both master and slave clock */
-		pm_runtime_put_sync(dev);
+		if (ret >= 0)
+			pm_runtime_put_sync(dev);
 	}
 
 	/* Select sleep pin state */
@@ -2583,18 +2591,20 @@ static int vpfe_resume(struct device *dev)
 {
 	struct vpfe_device *vpfe = dev_get_drvdata(dev);
 	struct vpfe_ccdc *ccdc = &vpfe->ccdc;
+	int ret;
 
 	/* only do full resume if streaming has started */
 	if (vb2_start_streaming_called(&vpfe->buffer_queue)) {
 		/* Enable both master and slave clock */
-		pm_runtime_get_sync(dev);
+		ret = pm_runtime_resume_and_get(dev);
 		vpfe_config_enable(ccdc, 1);
 
 		/* Restore VPFE context */
 		vpfe_restore_context(ccdc);
 
 		vpfe_config_enable(ccdc, 0);
-		pm_runtime_put_sync(dev);
+		if (ret >= 0)
+			pm_runtime_put_sync(dev);
 	}
 
 	/* Select default pin state */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 15/79] media: sh_vou: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (15 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-30 16:40   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Gustavo A. R. Silva, Geert Uytterhoeven, Hans Verkuil,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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(-)

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);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 16/79] media: mtk-vcodec: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrew-CT Chen,
	Matthias Brugger, Mauro Carvalho Chehab, Tiffany Lin,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
index ddee7046ce42..fe096fe61c9d 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
@@ -92,9 +92,9 @@ void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
 {
 	int ret;
 
-	ret = pm_runtime_get_sync(pm->dev);
+	ret = pm_runtime_resume_and_get(pm->dev);
 	if (ret)
-		mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
+		mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
 }
 
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 16/79] media: mtk-vcodec: fix pm_runtime_get_sync() usage count
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrew-CT Chen,
	Matthias Brugger, Mauro Carvalho Chehab, Tiffany Lin,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
index ddee7046ce42..fe096fe61c9d 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
@@ -92,9 +92,9 @@ void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
 {
 	int ret;
 
-	ret = pm_runtime_get_sync(pm->dev);
+	ret = pm_runtime_resume_and_get(pm->dev);
 	if (ret)
-		mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
+		mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
 }
 
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)
-- 
2.30.2


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 16/79] media: mtk-vcodec: fix pm_runtime_get_sync() usage count
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrew-CT Chen,
	Matthias Brugger, Mauro Carvalho Chehab, Tiffany Lin,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
index ddee7046ce42..fe096fe61c9d 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
@@ -92,9 +92,9 @@ void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
 {
 	int ret;
 
-	ret = pm_runtime_get_sync(pm->dev);
+	ret = pm_runtime_resume_and_get(pm->dev);
 	if (ret)
-		mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
+		mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
 }
 
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 17/79] media: s5p-jpeg: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Andrzej Pietrasiewicz, Jacek Anaszewski, Mauro Carvalho Chehab,
	Sylwester Nawrocki, linux-arm-kernel, linux-kernel, linux-media

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.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Acked-by: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 026111505f5a..c4f19418a460 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -2568,7 +2568,7 @@ static int s5p_jpeg_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(q);
 	int ret;
 
-	ret = pm_runtime_get_sync(ctx->jpeg->dev);
+	ret = pm_runtime_resume_and_get(ctx->jpeg->dev);
 
 	return ret > 0 ? 0 : ret;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 17/79] media: s5p-jpeg: fix pm_runtime_get_sync() usage count
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Andrzej Pietrasiewicz, Jacek Anaszewski, Mauro Carvalho Chehab,
	Sylwester Nawrocki, linux-arm-kernel, linux-kernel, linux-media

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.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Acked-by: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 026111505f5a..c4f19418a460 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -2568,7 +2568,7 @@ static int s5p_jpeg_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(q);
 	int ret;
 
-	ret = pm_runtime_get_sync(ctx->jpeg->dev);
+	ret = pm_runtime_resume_and_get(ctx->jpeg->dev);
 
 	return ret > 0 ? 0 : ret;
 }
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 18/79] media: sti/delta: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (18 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-30 16:47   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Hugues Fruchet,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/sti/delta/delta-v4l2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/sti/delta/delta-v4l2.c b/drivers/media/platform/sti/delta/delta-v4l2.c
index c691b3d81549..9928b7c46a41 100644
--- a/drivers/media/platform/sti/delta/delta-v4l2.c
+++ b/drivers/media/platform/sti/delta/delta-v4l2.c
@@ -1277,9 +1277,9 @@ int delta_get_sync(struct delta_ctx *ctx)
 	int ret = 0;
 
 	/* enable the hardware */
-	ret = pm_runtime_get_sync(delta->dev);
+	ret = pm_runtime_resume_and_get(delta->dev);
 	if (ret < 0) {
-		dev_err(delta->dev, "%s pm_runtime_get_sync failed (%d)\n",
+		dev_err(delta->dev, "%s pm_runtime_resume_and_get failed (%d)\n",
 			__func__, ret);
 		return ret;
 	}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 19/79] media: sunxi: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Chen-Yu Tsai,
	Jernej Skrabec, Mauro Carvalho Chehab, Maxime Ripard,
	linux-arm-kernel, linux-kernel, linux-media

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
index 3f81dd17755c..fbcca59a0517 100644
--- a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
+++ b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
@@ -494,7 +494,7 @@ static int rotate_start_streaming(struct vb2_queue *vq, unsigned int count)
 		struct device *dev = ctx->dev->dev;
 		int ret;
 
-		ret = pm_runtime_get_sync(dev);
+		ret = pm_runtime_resume_and_get(dev);
 		if (ret < 0) {
 			dev_err(dev, "Failed to enable module\n");
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 19/79] media: sunxi: fix pm_runtime_get_sync() usage count
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Chen-Yu Tsai,
	Jernej Skrabec, Mauro Carvalho Chehab, Maxime Ripard,
	linux-arm-kernel, linux-kernel, linux-media

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
index 3f81dd17755c..fbcca59a0517 100644
--- a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
+++ b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
@@ -494,7 +494,7 @@ static int rotate_start_streaming(struct vb2_queue *vq, unsigned int count)
 		struct device *dev = ctx->dev->dev;
 		int ret;
 
-		ret = pm_runtime_get_sync(dev);
+		ret = pm_runtime_resume_and_get(dev);
 		if (ret < 0) {
 			dev_err(dev, "Failed to enable module\n");
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, devel, linux-kernel,
	linux-media, linux-rockchip

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.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/rkvdec/rkvdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
index d821661d30f3..8c17615f3a7a 100644
--- a/drivers/staging/media/rkvdec/rkvdec.c
+++ b/drivers/staging/media/rkvdec/rkvdec.c
@@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
 	if (WARN_ON(!desc))
 		return;
 
-	ret = pm_runtime_get_sync(rkvdec->dev);
+	ret = pm_runtime_resume_and_get(rkvdec->dev);
 	if (ret < 0) {
 		rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
 		return;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: devel, Mauro Carvalho Chehab, Greg Kroah-Hartman, linuxarm,
	linux-kernel, linux-rockchip, mauro.chehab,
	Mauro Carvalho Chehab, Ezequiel Garcia, linux-media

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.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/rkvdec/rkvdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
index d821661d30f3..8c17615f3a7a 100644
--- a/drivers/staging/media/rkvdec/rkvdec.c
+++ b/drivers/staging/media/rkvdec/rkvdec.c
@@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
 	if (WARN_ON(!desc))
 		return;
 
-	ret = pm_runtime_get_sync(rkvdec->dev);
+	ret = pm_runtime_resume_and_get(rkvdec->dev);
 	if (ret < 0) {
 		rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
 		return;
-- 
2.30.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, devel, linux-kernel,
	linux-media, linux-rockchip

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.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/rkvdec/rkvdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
index d821661d30f3..8c17615f3a7a 100644
--- a/drivers/staging/media/rkvdec/rkvdec.c
+++ b/drivers/staging/media/rkvdec/rkvdec.c
@@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
 	if (WARN_ON(!desc))
 		return;
 
-	ret = pm_runtime_get_sync(rkvdec->dev);
+	ret = pm_runtime_resume_and_get(rkvdec->dev);
 	if (ret < 0) {
 		rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
 		return;
-- 
2.30.2


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 21/79] staging: media: atomisp: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, Sakari Ailus, devel,
	linux-kernel, linux-media

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/staging/media/atomisp/pci/atomisp_fops.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp_fops.c
index f1e6b2597853..26d05474a035 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_fops.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_fops.c
@@ -837,7 +837,7 @@ static int atomisp_open(struct file *file)
 	}
 
 	/* runtime power management, turn on ISP */
-	ret = pm_runtime_get_sync(vdev->v4l2_dev->dev);
+	ret = pm_runtime_resume_and_get(vdev->v4l2_dev->dev);
 	if (ret < 0) {
 		dev_err(isp->dev, "Failed to power on device\n");
 		goto error;
@@ -881,9 +881,9 @@ static int atomisp_open(struct file *file)
 
 css_error:
 	atomisp_css_uninit(isp);
-error:
-	hmm_pool_unregister(HMM_POOL_TYPE_DYNAMIC);
 	pm_runtime_put(vdev->v4l2_dev->dev);
+error:
+	hmm_pool_unregister(HMM_POOL_TYPE_DYNAMIC);
 	rt_mutex_unlock(&isp->mutex);
 	return ret;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 21/79] staging: media: atomisp: use pm_runtime_resume_and_get()
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: devel, Mauro Carvalho Chehab, Greg Kroah-Hartman, linuxarm,
	linux-kernel, Sakari Ailus, mauro.chehab, Mauro Carvalho Chehab,
	linux-media

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/staging/media/atomisp/pci/atomisp_fops.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp_fops.c
index f1e6b2597853..26d05474a035 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_fops.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_fops.c
@@ -837,7 +837,7 @@ static int atomisp_open(struct file *file)
 	}
 
 	/* runtime power management, turn on ISP */
-	ret = pm_runtime_get_sync(vdev->v4l2_dev->dev);
+	ret = pm_runtime_resume_and_get(vdev->v4l2_dev->dev);
 	if (ret < 0) {
 		dev_err(isp->dev, "Failed to power on device\n");
 		goto error;
@@ -881,9 +881,9 @@ static int atomisp_open(struct file *file)
 
 css_error:
 	atomisp_css_uninit(isp);
-error:
-	hmm_pool_unregister(HMM_POOL_TYPE_DYNAMIC);
 	pm_runtime_put(vdev->v4l2_dev->dev);
+error:
+	hmm_pool_unregister(HMM_POOL_TYPE_DYNAMIC);
 	rt_mutex_unlock(&isp->mutex);
 	return ret;
 }
-- 
2.30.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 22/79] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Fabio Estevam,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, NXP Linux Team,
	Pengutronix Kernel Team, Philipp Zabel, Rui Miguel Silva,
	Sascha Hauer, Shawn Guo, Steve Longerbeam, devel,
	linux-arm-kernel, linux-kernel, linux-media

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.

Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 025fdc488bd6..1dc680d94a46 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -695,11 +695,10 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 
 		mipi_csis_clear_counters(state);
 
-		ret = pm_runtime_get_sync(&state->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
 		if (ret < 0 && ret != -ENOIOCTLCMD)
 			goto done;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 22/79] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get()
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: devel, Philipp Zabel, Mauro Carvalho Chehab, Greg Kroah-Hartman,
	Sascha Hauer, linuxarm, linux-kernel, NXP Linux Team,
	Pengutronix Kernel Team, Steve Longerbeam, mauro.chehab,
	Shawn Guo, Mauro Carvalho Chehab, linux-arm-kernel, linux-media

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.

Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 025fdc488bd6..1dc680d94a46 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -695,11 +695,10 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 
 		mipi_csis_clear_counters(state);
 
-		ret = pm_runtime_get_sync(&state->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
 		if (ret < 0 && ret != -ENOIOCTLCMD)
 			goto done;
-- 
2.30.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 22/79] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get()
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Fabio Estevam,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, NXP Linux Team,
	Pengutronix Kernel Team, Philipp Zabel, Rui Miguel Silva,
	Sascha Hauer, Shawn Guo, Steve Longerbeam, devel,
	linux-arm-kernel, linux-kernel, linux-media

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.

Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 025fdc488bd6..1dc680d94a46 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -695,11 +695,10 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 
 		mipi_csis_clear_counters(state);
 
-		ret = pm_runtime_get_sync(&state->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
 		if (ret < 0 && ret != -ENOIOCTLCMD)
 			goto done;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 23/79] staging: media: ipu3: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Bingbu Cao,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, Sakari Ailus,
	Tianshu Qiu, devel, linux-kernel, linux-media

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/staging/media/ipu3/ipu3.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c
index ee1bba6bdcac..8e1e9e46e604 100644
--- a/drivers/staging/media/ipu3/ipu3.c
+++ b/drivers/staging/media/ipu3/ipu3.c
@@ -392,10 +392,9 @@ int imgu_s_stream(struct imgu_device *imgu, int enable)
 	}
 
 	/* Set Power */
-	r = pm_runtime_get_sync(dev);
+	r = pm_runtime_resume_and_get(dev);
 	if (r < 0) {
 		dev_err(dev, "failed to set imgu power\n");
-		pm_runtime_put(dev);
 		return r;
 	}
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 23/79] staging: media: ipu3: use pm_runtime_resume_and_get()
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: devel, Mauro Carvalho Chehab, Greg Kroah-Hartman, linuxarm,
	linux-kernel, Sakari Ailus, mauro.chehab, Bingbu Cao,
	Mauro Carvalho Chehab, Tianshu Qiu, linux-media

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/staging/media/ipu3/ipu3.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c
index ee1bba6bdcac..8e1e9e46e604 100644
--- a/drivers/staging/media/ipu3/ipu3.c
+++ b/drivers/staging/media/ipu3/ipu3.c
@@ -392,10 +392,9 @@ int imgu_s_stream(struct imgu_device *imgu, int enable)
 	}
 
 	/* Set Power */
-	r = pm_runtime_get_sync(dev);
+	r = pm_runtime_resume_and_get(dev);
 	if (r < 0) {
 		dev_err(dev, "failed to set imgu power\n");
-		pm_runtime_put(dev);
 		return r;
 	}
 
-- 
2.30.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 24/79] staging: media: cedrus_video: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Chen-Yu Tsai,
	Greg Kroah-Hartman, Jernej Skrabec, Mauro Carvalho Chehab,
	Maxime Ripard, Paul Kocialkowski, devel, linux-arm-kernel,
	linux-kernel, linux-media

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/staging/media/sunxi/cedrus/cedrus_video.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index b62eb8e84057..9ddd789d0b1f 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -490,11 +490,9 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
 	}
 
 	if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
-		ret = pm_runtime_get_sync(dev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(dev->dev);
+		ret = pm_runtime_resume_and_get(dev->dev);
+		if (ret < 0)
 			goto err_cleanup;
-		}
 
 		if (dev->dec_ops[ctx->current_codec]->start) {
 			ret = dev->dec_ops[ctx->current_codec]->start(ctx);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 24/79] staging: media: cedrus_video: use pm_runtime_resume_and_get()
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: devel, Jernej Skrabec, Mauro Carvalho Chehab, Greg Kroah-Hartman,
	linuxarm, Maxime Ripard, linux-kernel, Paul Kocialkowski,
	Chen-Yu Tsai, mauro.chehab, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-media

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/staging/media/sunxi/cedrus/cedrus_video.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index b62eb8e84057..9ddd789d0b1f 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -490,11 +490,9 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
 	}
 
 	if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
-		ret = pm_runtime_get_sync(dev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(dev->dev);
+		ret = pm_runtime_resume_and_get(dev->dev);
+		if (ret < 0)
 			goto err_cleanup;
-		}
 
 		if (dev->dec_ops[ctx->current_codec]->start) {
 			ret = dev->dec_ops[ctx->current_codec]->start(ctx);
-- 
2.30.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 24/79] staging: media: cedrus_video: use pm_runtime_resume_and_get()
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Chen-Yu Tsai,
	Greg Kroah-Hartman, Jernej Skrabec, Mauro Carvalho Chehab,
	Maxime Ripard, Paul Kocialkowski, devel, linux-arm-kernel,
	linux-kernel, linux-media

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/staging/media/sunxi/cedrus/cedrus_video.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index b62eb8e84057..9ddd789d0b1f 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -490,11 +490,9 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
 	}
 
 	if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
-		ret = pm_runtime_get_sync(dev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(dev->dev);
+		ret = pm_runtime_resume_and_get(dev->dev);
+		if (ret < 0)
 			goto err_cleanup;
-		}
 
 		if (dev->dec_ops[ctx->current_codec]->start) {
 			ret = dev->dec_ops[ctx->current_codec]->start(ctx);
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 25/79] staging: media: tegra-vde: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dmitry Osipenko,
	Greg Kroah-Hartman, Jonathan Hunter, Mauro Carvalho Chehab,
	Thierry Reding, devel, linux-kernel, linux-media, linux-tegra

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/staging/media/tegra-vde/vde.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
index 28845b5bafaf..1cdacb3f781c 100644
--- a/drivers/staging/media/tegra-vde/vde.c
+++ b/drivers/staging/media/tegra-vde/vde.c
@@ -775,9 +775,9 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
 	if (ret)
 		goto release_dpb_frames;
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0)
-		goto put_runtime_pm;
+		goto unlock;
 
 	/*
 	 * We rely on the VDE registers reset value, otherwise VDE
@@ -843,6 +843,8 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
 put_runtime_pm:
 	pm_runtime_mark_last_busy(dev);
 	pm_runtime_put_autosuspend(dev);
+
+unlock:
 	mutex_unlock(&vde->lock);
 
 release_dpb_frames:
@@ -1069,11 +1071,17 @@ static int tegra_vde_probe(struct platform_device *pdev)
 	 * power-cycle it in order to put hardware into a predictable lower
 	 * power state.
 	 */
-	pm_runtime_get_sync(dev);
+	if (pm_runtime_resume_and_get(dev) < 0)
+		goto err_pm_runtime;
+
 	pm_runtime_put(dev);
 
 	return 0;
 
+err_pm_runtime:
+	pm_runtime_dont_use_autosuspend(dev);
+	pm_runtime_disable(dev);
+
 err_deinit_iommu:
 	tegra_vde_iommu_deinit(vde);
 
@@ -1089,7 +1097,12 @@ static int tegra_vde_remove(struct platform_device *pdev)
 	struct tegra_vde *vde = platform_get_drvdata(pdev);
 	struct device *dev = &pdev->dev;
 
+	/*
+	 * As it increments RPM usage_count even on errors, we don't need to
+	 * check the returned code here.
+	 */
 	pm_runtime_get_sync(dev);
+
 	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 25/79] staging: media: tegra-vde: use pm_runtime_resume_and_get()
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: devel, Mauro Carvalho Chehab, Greg Kroah-Hartman, linuxarm,
	Jonathan Hunter, linux-tegra, Thierry Reding, mauro.chehab,
	Dmitry Osipenko, Mauro Carvalho Chehab, linux-kernel,
	linux-media

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/staging/media/tegra-vde/vde.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
index 28845b5bafaf..1cdacb3f781c 100644
--- a/drivers/staging/media/tegra-vde/vde.c
+++ b/drivers/staging/media/tegra-vde/vde.c
@@ -775,9 +775,9 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
 	if (ret)
 		goto release_dpb_frames;
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0)
-		goto put_runtime_pm;
+		goto unlock;
 
 	/*
 	 * We rely on the VDE registers reset value, otherwise VDE
@@ -843,6 +843,8 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
 put_runtime_pm:
 	pm_runtime_mark_last_busy(dev);
 	pm_runtime_put_autosuspend(dev);
+
+unlock:
 	mutex_unlock(&vde->lock);
 
 release_dpb_frames:
@@ -1069,11 +1071,17 @@ static int tegra_vde_probe(struct platform_device *pdev)
 	 * power-cycle it in order to put hardware into a predictable lower
 	 * power state.
 	 */
-	pm_runtime_get_sync(dev);
+	if (pm_runtime_resume_and_get(dev) < 0)
+		goto err_pm_runtime;
+
 	pm_runtime_put(dev);
 
 	return 0;
 
+err_pm_runtime:
+	pm_runtime_dont_use_autosuspend(dev);
+	pm_runtime_disable(dev);
+
 err_deinit_iommu:
 	tegra_vde_iommu_deinit(vde);
 
@@ -1089,7 +1097,12 @@ static int tegra_vde_remove(struct platform_device *pdev)
 	struct tegra_vde *vde = platform_get_drvdata(pdev);
 	struct device *dev = &pdev->dev;
 
+	/*
+	 * As it increments RPM usage_count even on errors, we don't need to
+	 * check the returned code here.
+	 */
 	pm_runtime_get_sync(dev);
+
 	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_disable(dev);
 
-- 
2.30.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 26/79] staging: media: tegra-video: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Greg Kroah-Hartman, Jonathan Hunter, Mauro Carvalho Chehab,
	Sowjanya Komatineni, Thierry Reding, devel, linux-kernel,
	linux-media, linux-tegra

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/staging/media/tegra-video/csi.c | 3 +--
 drivers/staging/media/tegra-video/vi.c  | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
index 033a6935c26d..e938bf4c48b6 100644
--- a/drivers/staging/media/tegra-video/csi.c
+++ b/drivers/staging/media/tegra-video/csi.c
@@ -298,10 +298,9 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)
 	struct tegra_csi *csi = csi_chan->csi;
 	int ret, err;
 
-	ret = pm_runtime_get_sync(csi->dev);
+	ret = pm_runtime_resume_and_get(csi->dev);
 	if (ret < 0) {
 		dev_err(csi->dev, "failed to get runtime PM: %d\n", ret);
-		pm_runtime_put_noidle(csi->dev);
 		return ret;
 	}
 
diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
index 7a09061cda57..1298740a9c6c 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -297,10 +297,9 @@ static int tegra_channel_start_streaming(struct vb2_queue *vq, u32 count)
 	struct tegra_vi_channel *chan = vb2_get_drv_priv(vq);
 	int ret;
 
-	ret = pm_runtime_get_sync(chan->vi->dev);
+	ret = pm_runtime_resume_and_get(chan->vi->dev);
 	if (ret < 0) {
 		dev_err(chan->vi->dev, "failed to get runtime PM: %d\n", ret);
-		pm_runtime_put_noidle(chan->vi->dev);
 		return ret;
 	}
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 26/79] staging: media: tegra-video: use pm_runtime_resume_and_get()
@ 2021-04-28 14:51   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: devel, Mauro Carvalho Chehab, Greg Kroah-Hartman, linuxarm,
	Jonathan Hunter, linux-tegra, Thierry Reding,
	Sowjanya Komatineni, mauro.chehab, Mauro Carvalho Chehab,
	linux-kernel, linux-media

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/staging/media/tegra-video/csi.c | 3 +--
 drivers/staging/media/tegra-video/vi.c  | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
index 033a6935c26d..e938bf4c48b6 100644
--- a/drivers/staging/media/tegra-video/csi.c
+++ b/drivers/staging/media/tegra-video/csi.c
@@ -298,10 +298,9 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)
 	struct tegra_csi *csi = csi_chan->csi;
 	int ret, err;
 
-	ret = pm_runtime_get_sync(csi->dev);
+	ret = pm_runtime_resume_and_get(csi->dev);
 	if (ret < 0) {
 		dev_err(csi->dev, "failed to get runtime PM: %d\n", ret);
-		pm_runtime_put_noidle(csi->dev);
 		return ret;
 	}
 
diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
index 7a09061cda57..1298740a9c6c 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -297,10 +297,9 @@ static int tegra_channel_start_streaming(struct vb2_queue *vq, u32 count)
 	struct tegra_vi_channel *chan = vb2_get_drv_priv(vq);
 	int ret;
 
-	ret = pm_runtime_get_sync(chan->vi->dev);
+	ret = pm_runtime_resume_and_get(chan->vi->dev);
 	if (ret < 0) {
 		dev_err(chan->vi->dev, "failed to get runtime PM: %d\n", ret);
-		pm_runtime_put_noidle(chan->vi->dev);
 		return ret;
 	}
 
-- 
2.30.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 27/79] media: i2c: ak7375: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (27 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  2021-04-30 17:14   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Tianshu Qiu, linux-kernel, linux-media

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/i2c/ak7375.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c
index e1f94ee0f48f..40b1a4aa846c 100644
--- a/drivers/media/i2c/ak7375.c
+++ b/drivers/media/i2c/ak7375.c
@@ -87,15 +87,7 @@ static const struct v4l2_ctrl_ops ak7375_vcm_ctrl_ops = {
 
 static int ak7375_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int ret;
-
-	ret = pm_runtime_get_sync(sd->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return ret;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int ak7375_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 28/79] media: i2c: ccs-core: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (28 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Sakari Ailus, linux-kernel, linux-media

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/i2c/ccs/ccs-core.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c
index b05f409014b2..8cce80557128 100644
--- a/drivers/media/i2c/ccs/ccs-core.c
+++ b/drivers/media/i2c/ccs/ccs-core.c
@@ -1880,12 +1880,11 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
-	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
-
+	rval = pm_runtime_resume_and_get(&client->dev);
+	if (rval < 0)
 		return rval;
-	} else if (!rval) {
+
+	if (!rval) {
 		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->
 					       ctrl_handler);
 		if (rval)
@@ -3089,12 +3088,9 @@ static int __maybe_unused ccs_suspend(struct device *dev)
 	bool streaming = sensor->streaming;
 	int rval;
 
-	rval = pm_runtime_get_sync(dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(dev);
-
+	rval = pm_runtime_resume_and_get(dev);
+	if (rval < 0)
 		return rval;
-	}
 
 	if (sensor->streaming)
 		ccs_stop_streaming(sensor);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 29/79] media: i2c: dw9714: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (29 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Sakari Ailus, linux-kernel, linux-media

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/i2c/dw9714.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/media/i2c/dw9714.c b/drivers/media/i2c/dw9714.c
index 3f0b082f863f..c8b4292512dc 100644
--- a/drivers/media/i2c/dw9714.c
+++ b/drivers/media/i2c/dw9714.c
@@ -85,15 +85,7 @@ static const struct v4l2_ctrl_ops dw9714_vcm_ctrl_ops = {
 
 static int dw9714_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int rval;
-
-	rval = pm_runtime_get_sync(sd->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return rval;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int dw9714_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 30/79] media: i2c: dw9768: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (30 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dongchun Zhu,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/i2c/dw9768.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/media/i2c/dw9768.c b/drivers/media/i2c/dw9768.c
index 8b8cb4b077b5..c086580efac7 100644
--- a/drivers/media/i2c/dw9768.c
+++ b/drivers/media/i2c/dw9768.c
@@ -374,15 +374,7 @@ static const struct v4l2_ctrl_ops dw9768_ctrl_ops = {
 
 static int dw9768_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int ret;
-
-	ret = pm_runtime_get_sync(sd->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return ret;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int dw9768_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 31/79] media: i2c: dw9807-vcm: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (31 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Sakari Ailus, linux-kernel, linux-media

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/i2c/dw9807-vcm.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/media/i2c/dw9807-vcm.c b/drivers/media/i2c/dw9807-vcm.c
index 438a44b76da8..95e06f13bc9e 100644
--- a/drivers/media/i2c/dw9807-vcm.c
+++ b/drivers/media/i2c/dw9807-vcm.c
@@ -130,15 +130,7 @@ static const struct v4l2_ctrl_ops dw9807_vcm_ctrl_ops = {
 
 static int dw9807_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int rval;
-
-	rval = pm_runtime_get_sync(sd->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return rval;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int dw9807_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 32/79] media: i2c: hi556: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (32 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Shawn Tu, linux-kernel, linux-media

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/i2c/hi556.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c
index 6f05c1138e3b..627ccfa34835 100644
--- a/drivers/media/i2c/hi556.c
+++ b/drivers/media/i2c/hi556.c
@@ -813,9 +813,8 @@ static int hi556_set_stream(struct v4l2_subdev *sd, int enable)
 
 	mutex_lock(&hi556->mutex);
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&hi556->mutex);
 			return ret;
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 33/79] media: i2c: imx214: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (33 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Ricardo Ribalda, linux-kernel,
	linux-media

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/i2c/imx214.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c
index e8b281e432e8..1a770a530cf5 100644
--- a/drivers/media/i2c/imx214.c
+++ b/drivers/media/i2c/imx214.c
@@ -776,11 +776,9 @@ static int imx214_s_stream(struct v4l2_subdev *subdev, int enable)
 		return 0;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(imx214->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(imx214->dev);
+		ret = pm_runtime_resume_and_get(imx214->dev);
+		if (ret < 0)
 			return ret;
-		}
 
 		ret = imx214_start_streaming(imx214);
 		if (ret < 0)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 34/79] media: i2c: imx219: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (34 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dave Stevenson,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/i2c/imx219.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 1054ffedaefd..74a0bf9b088b 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1035,11 +1035,9 @@ static int imx219_start_streaming(struct imx219 *imx219)
 	const struct imx219_reg_list *reg_list;
 	int ret;
 
-	ret = pm_runtime_get_sync(&client->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	ret = pm_runtime_resume_and_get(&client->dev);
+	if (ret < 0)
 		return ret;
-	}
 
 	/* Apply default values of current mode */
 	reg_list = &imx219->mode->reg_list;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 35/79] media: i2c: imx258: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (35 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Sakari Ailus, linux-kernel, linux-media

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/i2c/imx258.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index a017ec4e0f50..90529424d5b6 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -1039,11 +1039,9 @@ static int imx258_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		/*
 		 * Apply default & customized values
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 36/79] media: i2c: imx274: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (36 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Leon Luo,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/i2c/imx274.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/i2c/imx274.c b/drivers/media/i2c/imx274.c
index cdccaab3043a..ee2127436f0b 100644
--- a/drivers/media/i2c/imx274.c
+++ b/drivers/media/i2c/imx274.c
@@ -1441,9 +1441,8 @@ static int imx274_s_stream(struct v4l2_subdev *sd, int on)
 	mutex_lock(&imx274->lock);
 
 	if (on) {
-		ret = pm_runtime_get_sync(&imx274->client->dev);
+		ret = pm_runtime_resume_and_get(&imx274->client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&imx274->client->dev);
 			mutex_unlock(&imx274->lock);
 			return ret;
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 37/79] media: i2c: imx290: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (37 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Manivannan Sadhasivam, Mauro Carvalho Chehab, linux-kernel,
	linux-media

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/i2c/imx290.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
index 6319a42057d2..06020e648a97 100644
--- a/drivers/media/i2c/imx290.c
+++ b/drivers/media/i2c/imx290.c
@@ -764,11 +764,9 @@ static int imx290_set_stream(struct v4l2_subdev *sd, int enable)
 	int ret = 0;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(imx290->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(imx290->dev);
+		ret = pm_runtime_resume_and_get(imx290->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
 
 		ret = imx290_start_streaming(imx290);
 		if (ret) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 38/79] media: i2c: imx319: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (38 preceding siblings ...)
  (?)
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Bingbu Cao,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/i2c/imx319.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
index 38540323a156..4e0a8c9d271f 100644
--- a/drivers/media/i2c/imx319.c
+++ b/drivers/media/i2c/imx319.c
@@ -2141,11 +2141,9 @@ static int imx319_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		/*
 		 * Apply default & customized values
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 39/79] media: i2c: imx355: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (39 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Tianshu Qiu, linux-kernel, linux-media

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/i2c/imx355.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
index ccedcd4c520a..93f13a04439a 100644
--- a/drivers/media/i2c/imx355.c
+++ b/drivers/media/i2c/imx355.c
@@ -1442,11 +1442,9 @@ static int imx355_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		/*
 		 * Apply default & customized values
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 40/79] media: i2c: mt9m001: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (40 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Hans Verkuil,
	Jacopo Mondi, Mauro Carvalho Chehab, linux-kernel, linux-media

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/i2c/mt9m001.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/mt9m001.c b/drivers/media/i2c/mt9m001.c
index 3b0ba8ed5233..58c85a3bccf6 100644
--- a/drivers/media/i2c/mt9m001.c
+++ b/drivers/media/i2c/mt9m001.c
@@ -217,9 +217,9 @@ static int mt9m001_s_stream(struct v4l2_subdev *sd, int enable)
 		goto done;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0)
-			goto put_unlock;
+			goto unlock;
 
 		ret = mt9m001_apply_selection(sd);
 		if (ret)
@@ -247,6 +247,7 @@ static int mt9m001_s_stream(struct v4l2_subdev *sd, int enable)
 
 put_unlock:
 	pm_runtime_put(&client->dev);
+unlock:
 	mutex_unlock(&mt9m001->mutex);
 
 	return ret;
@@ -834,6 +835,10 @@ static int mt9m001_remove(struct i2c_client *client)
 {
 	struct mt9m001 *mt9m001 = to_mt9m001(client);
 
+	/*
+	 * As it increments RPM usage_count even on errors, we don't need to
+	 * check the returned code here.
+	 */
 	pm_runtime_get_sync(&client->dev);
 
 	v4l2_async_unregister_subdev(&mt9m001->subdev);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 41/79] media: i2c: ov02a10: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (41 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dongchun Zhu,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/i2c/ov02a10.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov02a10.c b/drivers/media/i2c/ov02a10.c
index c47b1d45d8fd..a1d7314b20a9 100644
--- a/drivers/media/i2c/ov02a10.c
+++ b/drivers/media/i2c/ov02a10.c
@@ -540,11 +540,9 @@ static int ov02a10_s_stream(struct v4l2_subdev *sd, int on)
 	}
 
 	if (on) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
 
 		ret = __ov02a10_start_stream(ov02a10);
 		if (ret) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 42/79] media: i2c: ov13858: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (42 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Sakari Ailus, linux-kernel, linux-media

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/i2c/ov13858.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c
index 4a2885ff0cbe..9598c0b19603 100644
--- a/drivers/media/i2c/ov13858.c
+++ b/drivers/media/i2c/ov13858.c
@@ -1472,11 +1472,9 @@ static int ov13858_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		/*
 		 * Apply default & customized values
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 43/79] media: i2c: ov2659: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (43 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  2021-05-03 12:30   ` Lad, Prabhakar
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Lad, Prabhakar,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/i2c/ov2659.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov2659.c b/drivers/media/i2c/ov2659.c
index 42f64175a6df..a3c8eae68486 100644
--- a/drivers/media/i2c/ov2659.c
+++ b/drivers/media/i2c/ov2659.c
@@ -1186,11 +1186,9 @@ static int ov2659_s_stream(struct v4l2_subdev *sd, int on)
 		goto unlock;
 	}
 
-	ret = pm_runtime_get_sync(&client->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	ret = pm_runtime_resume_and_get(&client->dev);
+	if (ret < 0)
 		goto unlock;
-	}
 
 	ret = ov2659_init(sd, 0);
 	if (!ret)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 44/79] media: i2c: ov2685: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (44 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Shunqian Zheng, linux-kernel, linux-media

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/i2c/ov2685.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov2685.c b/drivers/media/i2c/ov2685.c
index 49a2dcedb347..2f3836dd8eed 100644
--- a/drivers/media/i2c/ov2685.c
+++ b/drivers/media/i2c/ov2685.c
@@ -456,11 +456,10 @@ static int ov2685_s_stream(struct v4l2_subdev *sd, int on)
 		goto unlock_and_return;
 
 	if (on) {
-		ret = pm_runtime_get_sync(&ov2685->client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&ov2685->client->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
+
 		ret = __v4l2_ctrl_handler_setup(&ov2685->ctrl_handler);
 		if (ret) {
 			pm_runtime_put(&client->dev);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 45/79] media: i2c: ov2740: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (45 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  2021-04-30 17:20   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Bingbu Cao,
	Mauro Carvalho Chehab, Shawn Tu, Tianshu Qiu, linux-kernel,
	linux-media

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/i2c/ov2740.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
index 0f3f17f3c426..54779f720f9d 100644
--- a/drivers/media/i2c/ov2740.c
+++ b/drivers/media/i2c/ov2740.c
@@ -751,9 +751,8 @@ static int ov2740_set_stream(struct v4l2_subdev *sd, int enable)
 
 	mutex_lock(&ov2740->mutex);
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&ov2740->mutex);
 			return ret;
 		}
@@ -1049,9 +1048,8 @@ static int ov2740_nvmem_read(void *priv, unsigned int off, void *val,
 		goto exit;
 	}
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(dev);
 		goto exit;
 	}
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 46/79] media: i2c: ov5647: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (46 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dave Stevenson,
	Jacopo Mondi, Mauro Carvalho Chehab, linux-kernel, linux-media

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.

Acked-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/i2c/ov5647.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index 1cefa15729ce..38faa74755e3 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -882,20 +882,20 @@ static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0)
 			goto error_unlock;
 
 		ret = ov5647_stream_on(sd);
 		if (ret < 0) {
 			dev_err(&client->dev, "stream start failed: %d\n", ret);
-			goto error_unlock;
+			goto error_pm;
 		}
 	} else {
 		ret = ov5647_stream_off(sd);
 		if (ret < 0) {
 			dev_err(&client->dev, "stream stop failed: %d\n", ret);
-			goto error_unlock;
+			goto error_pm;
 		}
 		pm_runtime_put(&client->dev);
 	}
@@ -905,8 +905,9 @@ static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)
 
 	return 0;
 
+error_pm:
+	pm_runtime_put(&client->dev);
 error_unlock:
-	pm_runtime_put(&client->dev);
 	mutex_unlock(&sensor->lock);
 
 	return ret;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 47/79] media: i2c: ov5648: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (47 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Colin Ian King,
	Dan Carpenter, Ezequiel Garcia, Mauro Carvalho Chehab,
	Paul Kocialkowski, Sakari Ailus, linux-kernel, linux-media

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/i2c/ov5648.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov5648.c b/drivers/media/i2c/ov5648.c
index 3ecb4a3e8773..07e64ff0be3f 100644
--- a/drivers/media/i2c/ov5648.c
+++ b/drivers/media/i2c/ov5648.c
@@ -2132,11 +2132,9 @@ static int ov5648_s_stream(struct v4l2_subdev *subdev, int enable)
 	int ret;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(sensor->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(sensor->dev);
+		ret = pm_runtime_resume_and_get(sensor->dev);
+		if (ret < 0)
 			return ret;
-		}
 	}
 
 	mutex_lock(&sensor->mutex);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 48/79] media: i2c: ov5670: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (48 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Chiranjeevi Rapolu, Hyungwoo Yang, Mauro Carvalho Chehab,
	linux-kernel, linux-media

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/i2c/ov5670.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c
index dee7df8dd100..182f271f118f 100644
--- a/drivers/media/i2c/ov5670.c
+++ b/drivers/media/i2c/ov5670.c
@@ -2347,11 +2347,9 @@ static int ov5670_set_stream(struct v4l2_subdev *sd, int enable)
 		goto unlock_and_return;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
 
 		ret = ov5670_start_streaming(ov5670);
 		if (ret)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 49/79] media: i2c: ov5675: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (49 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Shawn Tu, linux-kernel, linux-media

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/i2c/ov5675.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov5675.c b/drivers/media/i2c/ov5675.c
index dea32859459a..e7e297a23960 100644
--- a/drivers/media/i2c/ov5675.c
+++ b/drivers/media/i2c/ov5675.c
@@ -863,9 +863,8 @@ static int ov5675_set_stream(struct v4l2_subdev *sd, int enable)
 
 	mutex_lock(&ov5675->mutex);
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&ov5675->mutex);
 			return ret;
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 50/79] media: i2c: ov5695: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (50 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Shunqian Zheng, linux-kernel, linux-media

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/i2c/ov5695.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov5695.c b/drivers/media/i2c/ov5695.c
index 09bee57a241d..469d941813c6 100644
--- a/drivers/media/i2c/ov5695.c
+++ b/drivers/media/i2c/ov5695.c
@@ -946,11 +946,9 @@ static int ov5695_s_stream(struct v4l2_subdev *sd, int on)
 		goto unlock_and_return;
 
 	if (on) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
 
 		ret = __ov5695_start_stream(ov5695);
 		if (ret) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 51/79] media: i2c: ov7740: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (51 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Wenyou Yang, linux-kernel, linux-media

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/i2c/ov7740.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
index ed6904b2e8f5..74219f67f245 100644
--- a/drivers/media/i2c/ov7740.c
+++ b/drivers/media/i2c/ov7740.c
@@ -624,11 +624,9 @@ static int ov7740_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		ret = ov7740_start_streaming(ov7740);
 		if (ret)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 52/79] media: i2c: ov8856: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (52 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dongchun Zhu,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/i2c/ov8856.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov8856.c b/drivers/media/i2c/ov8856.c
index e3af3ea277af..2875f8e4ddcb 100644
--- a/drivers/media/i2c/ov8856.c
+++ b/drivers/media/i2c/ov8856.c
@@ -1340,9 +1340,8 @@ static int ov8856_set_stream(struct v4l2_subdev *sd, int enable)
 
 	mutex_lock(&ov8856->mutex);
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&ov8856->mutex);
 			return ret;
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 53/79] media: i2c: ov8865: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (53 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Colin Ian King,
	Hans Verkuil, Mauro Carvalho Chehab, Paul Kocialkowski,
	Sakari Ailus, Yang Li, linux-kernel, linux-media

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/i2c/ov8865.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
index 9ecf180635ee..3bf6ee4898a9 100644
--- a/drivers/media/i2c/ov8865.c
+++ b/drivers/media/i2c/ov8865.c
@@ -2497,11 +2497,9 @@ static int ov8865_s_stream(struct v4l2_subdev *subdev, int enable)
 	int ret;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(sensor->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(sensor->dev);
+		ret = pm_runtime_resume_and_get(sensor->dev);
+		if (ret < 0)
 			return ret;
-		}
 	}
 
 	mutex_lock(&sensor->mutex);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 54/79] media: i2c: ov9734: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (54 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Bingbu Cao,
	Mauro Carvalho Chehab, Tianshu Qiu, linux-kernel, linux-media

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/i2c/ov9734.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov9734.c b/drivers/media/i2c/ov9734.c
index b7309a551cae..ba156683c533 100644
--- a/drivers/media/i2c/ov9734.c
+++ b/drivers/media/i2c/ov9734.c
@@ -644,9 +644,8 @@ static int ov9734_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&ov9734->mutex);
 			return ret;
 		}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 55/79] media: i2c: tvp5150: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (55 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Gustavo A. R. Silva, Chuhong Yuan, Hans Verkuil, Jacopo Mondi,
	Krzysztof Kozlowski, Marco Felsch, Mauro Carvalho Chehab,
	Sakari Ailus, Zhang Xiaoxu, linux-kernel, linux-media

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/i2c/tvp5150.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index e26e3f544054..374a9da75e4d 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -1448,11 +1448,9 @@ static int tvp5150_s_stream(struct v4l2_subdev *sd, int enable)
 	       TVP5150_MISC_CTL_CLOCK_OE;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(sd->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(sd->dev);
+		ret = pm_runtime_resume_and_get(sd->dev);
+		if (ret < 0)
 			return ret;
-		}
 
 		tvp5150_enable(sd);
 
@@ -1675,15 +1673,7 @@ static int tvp5150_registered(struct v4l2_subdev *sd)
 
 static int tvp5150_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int ret;
-
-	ret = pm_runtime_get_sync(sd->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return ret;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int tvp5150_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 56/79] media: i2c: video-i2c: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (56 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Matt Ranostay,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/i2c/video-i2c.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index c9a774f4c8d2..910a139c5e14 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -286,11 +286,9 @@ static int amg88xx_read(struct device *dev, enum hwmon_sensor_types type,
 	__le16 buf;
 	int tmp;
 
-	tmp = pm_runtime_get_sync(regmap_get_device(data->regmap));
-	if (tmp < 0) {
-		pm_runtime_put_noidle(regmap_get_device(data->regmap));
+	tmp = pm_runtime_resume_and_get(regmap_get_device(data->regmap));
+	if (tmp < 0)
 		return tmp;
-	}
 
 	tmp = regmap_bulk_read(data->regmap, AMG88XX_REG_TTHL, &buf, 2);
 	pm_runtime_mark_last_busy(regmap_get_device(data->regmap));
@@ -512,11 +510,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
 	if (data->kthread_vid_cap)
 		return 0;
 
-	ret = pm_runtime_get_sync(dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(dev);
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret < 0)
 		goto error_del_list;
-	}
 
 	ret = data->chip->setup(data);
 	if (ret)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Heiko Stuebner, Jacob Chen, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-rockchip

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/rockchip/rga/rga-buf.c | 3 +--
 drivers/media/platform/rockchip/rga/rga.c     | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/platform/rockchip/rga/rga-buf.c
index bf9a75b75083..81508ed5abf3 100644
--- a/drivers/media/platform/rockchip/rga/rga-buf.c
+++ b/drivers/media/platform/rockchip/rga/rga-buf.c
@@ -79,9 +79,8 @@ static int rga_buf_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct rockchip_rga *rga = ctx->rga;
 	int ret;
 
-	ret = pm_runtime_get_sync(rga->dev);
+	ret = pm_runtime_resume_and_get(rga->dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(rga->dev);
 		rga_buf_return_buffers(q, VB2_BUF_STATE_QUEUED);
 		return ret;
 	}
diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
index 9d122429706e..bf3fd71ec3af 100644
--- a/drivers/media/platform/rockchip/rga/rga.c
+++ b/drivers/media/platform/rockchip/rga/rga.c
@@ -866,7 +866,9 @@ static int rga_probe(struct platform_device *pdev)
 		goto unreg_video_dev;
 	}
 
-	pm_runtime_get_sync(rga->dev);
+	ret = pm_runtime_resume_and_get(rga->dev);
+	if (ret < 0)
+		goto unreg_video_dev;
 
 	rga->version.major = (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF;
 	rga->version.minor = (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Heiko Stuebner, Jacob Chen, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-rockchip

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/rockchip/rga/rga-buf.c | 3 +--
 drivers/media/platform/rockchip/rga/rga.c     | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/platform/rockchip/rga/rga-buf.c
index bf9a75b75083..81508ed5abf3 100644
--- a/drivers/media/platform/rockchip/rga/rga-buf.c
+++ b/drivers/media/platform/rockchip/rga/rga-buf.c
@@ -79,9 +79,8 @@ static int rga_buf_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct rockchip_rga *rga = ctx->rga;
 	int ret;
 
-	ret = pm_runtime_get_sync(rga->dev);
+	ret = pm_runtime_resume_and_get(rga->dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(rga->dev);
 		rga_buf_return_buffers(q, VB2_BUF_STATE_QUEUED);
 		return ret;
 	}
diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
index 9d122429706e..bf3fd71ec3af 100644
--- a/drivers/media/platform/rockchip/rga/rga.c
+++ b/drivers/media/platform/rockchip/rga/rga.c
@@ -866,7 +866,9 @@ static int rga_probe(struct platform_device *pdev)
 		goto unreg_video_dev;
 	}
 
-	pm_runtime_get_sync(rga->dev);
+	ret = pm_runtime_resume_and_get(rga->dev);
+	if (ret < 0)
+		goto unreg_video_dev;
 
 	rga->version.major = (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF;
 	rga->version.minor = (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F;
-- 
2.30.2


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Heiko Stuebner, Jacob Chen, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-rockchip

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/rockchip/rga/rga-buf.c | 3 +--
 drivers/media/platform/rockchip/rga/rga.c     | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/platform/rockchip/rga/rga-buf.c
index bf9a75b75083..81508ed5abf3 100644
--- a/drivers/media/platform/rockchip/rga/rga-buf.c
+++ b/drivers/media/platform/rockchip/rga/rga-buf.c
@@ -79,9 +79,8 @@ static int rga_buf_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct rockchip_rga *rga = ctx->rga;
 	int ret;
 
-	ret = pm_runtime_get_sync(rga->dev);
+	ret = pm_runtime_resume_and_get(rga->dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(rga->dev);
 		rga_buf_return_buffers(q, VB2_BUF_STATE_QUEUED);
 		return ret;
 	}
diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
index 9d122429706e..bf3fd71ec3af 100644
--- a/drivers/media/platform/rockchip/rga/rga.c
+++ b/drivers/media/platform/rockchip/rga/rga.c
@@ -866,7 +866,9 @@ static int rga_probe(struct platform_device *pdev)
 		goto unreg_video_dev;
 	}
 
-	pm_runtime_get_sync(rga->dev);
+	ret = pm_runtime_resume_and_get(rga->dev);
+	if (ret < 0)
+		goto unreg_video_dev;
 
 	rga->version.major = (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF;
 	rga->version.minor = (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 58/79] media: sti/hva: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (58 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  2021-04-30 17:35   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Jean-Christophe Trotin, Mauro Carvalho Chehab, linux-kernel,
	linux-media

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.

While the hva driver does it right, there are lots of errors
on other drivers due to its misusage. So, let's change
this driver to also use pm_runtime_resume_and_get(), as we're
doing similar changes all over the media subsystem.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/sti/hva/hva-hw.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/sti/hva/hva-hw.c b/drivers/media/platform/sti/hva/hva-hw.c
index f59811e27f51..77b8bfa5e0c5 100644
--- a/drivers/media/platform/sti/hva/hva-hw.c
+++ b/drivers/media/platform/sti/hva/hva-hw.c
@@ -270,9 +270,8 @@ static unsigned long int hva_hw_get_ip_version(struct hva_dev *hva)
 	struct device *dev = hva_to_dev(hva);
 	unsigned long int version;
 
-	if (pm_runtime_get_sync(dev) < 0) {
+	if (pm_runtime_resume_and_get(dev) < 0) {
 		dev_err(dev, "%s     failed to get pm_runtime\n", HVA_PREFIX);
-		pm_runtime_put_noidle(dev);
 		mutex_unlock(&hva->protect_mutex);
 		return -EFAULT;
 	}
@@ -386,10 +385,10 @@ int hva_hw_probe(struct platform_device *pdev, struct hva_dev *hva)
 	pm_runtime_set_suspended(dev);
 	pm_runtime_enable(dev);
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0) {
 		dev_err(dev, "%s     failed to set PM\n", HVA_PREFIX);
-		goto err_pm;
+		goto err_clk;
 	}
 
 	/* check IP hardware version */
@@ -462,6 +461,7 @@ int hva_hw_execute_task(struct hva_ctx *ctx, enum hva_hw_cmd_type cmd,
 	u8 client_id = ctx->id;
 	int ret;
 	u32 reg = 0;
+	bool got_pm = false;
 
 	mutex_lock(&hva->protect_mutex);
 
@@ -469,12 +469,13 @@ int hva_hw_execute_task(struct hva_ctx *ctx, enum hva_hw_cmd_type cmd,
 	enable_irq(hva->irq_its);
 	enable_irq(hva->irq_err);
 
-	if (pm_runtime_get_sync(dev) < 0) {
+	if (pm_runtime_resume_and_get(dev) < 0) {
 		dev_err(dev, "%s     failed to get pm_runtime\n", ctx->name);
 		ctx->sys_errors++;
 		ret = -EFAULT;
 		goto out;
 	}
+	got_pm = true;
 
 	reg = readl_relaxed(hva->regs + HVA_HIF_REG_CLK_GATING);
 	switch (cmd) {
@@ -537,7 +538,8 @@ int hva_hw_execute_task(struct hva_ctx *ctx, enum hva_hw_cmd_type cmd,
 		dev_dbg(dev, "%s     unknown command 0x%x\n", ctx->name, cmd);
 	}
 
-	pm_runtime_put_autosuspend(dev);
+	if (got_pm)
+		pm_runtime_put_autosuspend(dev);
 	mutex_unlock(&hva->protect_mutex);
 
 	return ret;
@@ -553,9 +555,8 @@ void hva_hw_dump_regs(struct hva_dev *hva, struct seq_file *s)
 
 	mutex_lock(&hva->protect_mutex);
 
-	if (pm_runtime_get_sync(dev) < 0) {
+	if (pm_runtime_resume_and_get(dev) < 0) {
 		seq_puts(s, "Cannot wake up IP\n");
-		pm_runtime_put_noidle(dev);
 		mutex_unlock(&hva->protect_mutex);
 		return;
 	}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 59/79] media: sti/bdisp: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (59 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Fabien Dessenne,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/sti/bdisp/bdisp-v4l2.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
index 060ca85f64d5..85288da9d2ae 100644
--- a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
+++ b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
@@ -499,7 +499,7 @@ static int bdisp_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct bdisp_ctx *ctx = q->drv_priv;
 	struct vb2_v4l2_buffer *buf;
-	int ret = pm_runtime_get_sync(ctx->bdisp_dev->dev);
+	int ret = pm_runtime_resume_and_get(ctx->bdisp_dev->dev);
 
 	if (ret < 0) {
 		dev_err(ctx->bdisp_dev->dev, "failed to set runtime PM\n");
@@ -1364,10 +1364,10 @@ static int bdisp_probe(struct platform_device *pdev)
 
 	/* Power management */
 	pm_runtime_enable(dev);
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0) {
 		dev_err(dev, "failed to set PM\n");
-		goto err_pm;
+		goto err_remove;
 	}
 
 	/* Filters */
@@ -1395,6 +1395,7 @@ static int bdisp_probe(struct platform_device *pdev)
 	bdisp_hw_free_filters(bdisp->dev);
 err_pm:
 	pm_runtime_put(dev);
+err_remove:
 	bdisp_debugfs_remove(bdisp);
 	v4l2_device_unregister(&bdisp->v4l2_dev);
 err_clk:
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 60/79] media: ipu3: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (60 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Bingbu Cao,
	Dan Scally, Mauro Carvalho Chehab, Sakari Ailus, Tianshu Qiu,
	Yong Zhi, linux-kernel, linux-media

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/pci/intel/ipu3/ipu3-cio2-main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
index fecef85bd62e..ca8040d1a725 100644
--- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
+++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
@@ -975,10 +975,9 @@ static int cio2_vb2_start_streaming(struct vb2_queue *vq, unsigned int count)
 	cio2->cur_queue = q;
 	atomic_set(&q->frame_sequence, 0);
 
-	r = pm_runtime_get_sync(&cio2->pci_dev->dev);
+	r = pm_runtime_resume_and_get(&cio2->pci_dev->dev);
 	if (r < 0) {
 		dev_info(&cio2->pci_dev->dev, "failed to set power %d\n", r);
-		pm_runtime_put_noidle(&cio2->pci_dev->dev);
 		return r;
 	}
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 61/79] media: coda: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (61 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Philipp Zabel, linux-kernel, linux-media

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.

While here, as noted by Phillip, the labels at the coda_open()
function are currently named after what operation failed,
instead of what they do in response. So, change the name of
the error label that it is called when clk_enable fails,
in order to be consistent.

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/coda/coda-common.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index bd666c858fa1..2017de85713e 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -2660,7 +2660,7 @@ static int coda_open(struct file *file)
 	ctx->use_vdoa = false;
 
 	/* Power up and upload firmware if necessary */
-	ret = pm_runtime_get_sync(dev->dev);
+	ret = pm_runtime_resume_and_get(dev->dev);
 	if (ret < 0) {
 		v4l2_err(&dev->v4l2_dev, "failed to power up: %d\n", ret);
 		goto err_pm_get;
@@ -2668,7 +2668,7 @@ static int coda_open(struct file *file)
 
 	ret = clk_prepare_enable(dev->clk_per);
 	if (ret)
-		goto err_pm_get;
+		goto err_clk_enable;
 
 	ret = clk_prepare_enable(dev->clk_ahb);
 	if (ret)
@@ -2707,8 +2707,9 @@ static int coda_open(struct file *file)
 	clk_disable_unprepare(dev->clk_ahb);
 err_clk_ahb:
 	clk_disable_unprepare(dev->clk_per);
+err_clk_enable:
+	pm_runtime_put_sync(dev->dev);
 err_pm_get:
-	pm_runtime_put_sync(dev->dev);
 	v4l2_fh_del(&ctx->fh);
 	v4l2_fh_exit(&ctx->fh);
 err_coda_name_init:
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 62/79] media: exynos4-is: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, Sylwester Nawrocki,
	linux-arm-kernel, linux-kernel, linux-media, linux-samsung-soc

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.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
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        | 4 ++--
 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      | 8 +++-----
 8 files changed, 18 insertions(+), 25 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..1b24f5bfc4af 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.c
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -828,9 +828,9 @@ 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;
+		goto err_irq;
 
 	vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));
 
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 612b9872afc8..8d9dc597deaa 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -275,7 +275,7 @@ static int isp_video_open(struct file *file)
 	if (ret < 0)
 		goto unlock;
 
-	ret = pm_runtime_get_sync(&isp->pdev->dev);
+	ret = pm_runtime_resume_and_get(&isp->pdev->dev);
 	if (ret < 0)
 		goto rel_fh;
 
@@ -293,7 +293,6 @@ static int isp_video_open(struct file *file)
 	if (!ret)
 		goto unlock;
 rel_fh:
-	pm_runtime_put_noidle(&isp->pdev->dev);
 	v4l2_fh_release(file);
 unlock:
 	mutex_unlock(&isp->video_lock);
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c
index a77c49b18511..74b49d30901e 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp.c
@@ -304,11 +304,10 @@ static int fimc_isp_subdev_s_power(struct v4l2_subdev *sd, int on)
 	pr_debug("on: %d\n", on);
 
 	if (on) {
-		ret = pm_runtime_get_sync(&is->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put(&is->pdev->dev);
+		ret = pm_runtime_resume_and_get(&is->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		set_bit(IS_ST_PWR_ON, &is->state);
 
 		ret = fimc_is_start_firmware(is);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index fe20af3a7178..4d8b18078ff3 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -469,9 +469,9 @@ static int fimc_lite_open(struct file *file)
 	}
 
 	set_bit(ST_FLITE_IN_USE, &fimc->state);
-	ret = pm_runtime_get_sync(&fimc->pdev->dev);
+	ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
 	if (ret < 0)
-		goto err_pm;
+		goto err_in_use;
 
 	ret = v4l2_fh_open(file);
 	if (ret < 0)
@@ -499,6 +499,7 @@ static int fimc_lite_open(struct file *file)
 	v4l2_fh_release(file);
 err_pm:
 	pm_runtime_put_sync(&fimc->pdev->dev);
+err_in_use:
 	clear_bit(ST_FLITE_IN_USE, &fimc->state);
 unlock:
 	mutex_unlock(&fimc->lock);
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index c9704a147e5c..7c1eb05c508f 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -75,7 +75,7 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
 	struct fimc_ctx *ctx = q->drv_priv;
 	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->fimc_dev->pdev->dev);
+	ret = pm_runtime_resume_and_get(&ctx->fimc_dev->pdev->dev);
 	return ret > 0 ? 0 : ret;
 }
 
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 13d192ba4aa6..9346d44a06c2 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -512,11 +512,9 @@ static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
 	if (!fmd->pmf)
 		return -ENXIO;
 
-	ret = pm_runtime_get_sync(fmd->pmf);
-	if (ret < 0) {
-		pm_runtime_put(fmd->pmf);
+	ret = pm_runtime_resume_and_get(fmd->pmf);
+	if (ret < 0)
 		return ret;
-	}
 
 	fmd->num_sensors = 0;
 
@@ -1291,7 +1289,7 @@ static int cam_clk_prepare(struct clk_hw *hw)
 	if (camclk->fmd->pmf == NULL)
 		return -ENODEV;
 
-	ret = pm_runtime_get_sync(camclk->fmd->pmf);
+	ret = pm_runtime_resume_and_get(camclk->fmd->pmf);
 	return ret < 0 ? ret : 0;
 }
 
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
index 1aac167abb17..2a6afb78a049 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,11 +509,9 @@ 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);
-		if (ret && ret != 1) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret && ret != 1)
 			return ret;
-		}
 	}
 
 	mutex_lock(&state->lock);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 62/79] media: exynos4-is: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, Sylwester Nawrocki,
	linux-arm-kernel, linux-kernel, linux-media, linux-samsung-soc

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.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
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        | 4 ++--
 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      | 8 +++-----
 8 files changed, 18 insertions(+), 25 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..1b24f5bfc4af 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.c
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -828,9 +828,9 @@ 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;
+		goto err_irq;
 
 	vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));
 
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 612b9872afc8..8d9dc597deaa 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -275,7 +275,7 @@ static int isp_video_open(struct file *file)
 	if (ret < 0)
 		goto unlock;
 
-	ret = pm_runtime_get_sync(&isp->pdev->dev);
+	ret = pm_runtime_resume_and_get(&isp->pdev->dev);
 	if (ret < 0)
 		goto rel_fh;
 
@@ -293,7 +293,6 @@ static int isp_video_open(struct file *file)
 	if (!ret)
 		goto unlock;
 rel_fh:
-	pm_runtime_put_noidle(&isp->pdev->dev);
 	v4l2_fh_release(file);
 unlock:
 	mutex_unlock(&isp->video_lock);
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c
index a77c49b18511..74b49d30901e 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp.c
@@ -304,11 +304,10 @@ static int fimc_isp_subdev_s_power(struct v4l2_subdev *sd, int on)
 	pr_debug("on: %d\n", on);
 
 	if (on) {
-		ret = pm_runtime_get_sync(&is->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put(&is->pdev->dev);
+		ret = pm_runtime_resume_and_get(&is->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		set_bit(IS_ST_PWR_ON, &is->state);
 
 		ret = fimc_is_start_firmware(is);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index fe20af3a7178..4d8b18078ff3 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -469,9 +469,9 @@ static int fimc_lite_open(struct file *file)
 	}
 
 	set_bit(ST_FLITE_IN_USE, &fimc->state);
-	ret = pm_runtime_get_sync(&fimc->pdev->dev);
+	ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
 	if (ret < 0)
-		goto err_pm;
+		goto err_in_use;
 
 	ret = v4l2_fh_open(file);
 	if (ret < 0)
@@ -499,6 +499,7 @@ static int fimc_lite_open(struct file *file)
 	v4l2_fh_release(file);
 err_pm:
 	pm_runtime_put_sync(&fimc->pdev->dev);
+err_in_use:
 	clear_bit(ST_FLITE_IN_USE, &fimc->state);
 unlock:
 	mutex_unlock(&fimc->lock);
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index c9704a147e5c..7c1eb05c508f 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -75,7 +75,7 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
 	struct fimc_ctx *ctx = q->drv_priv;
 	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->fimc_dev->pdev->dev);
+	ret = pm_runtime_resume_and_get(&ctx->fimc_dev->pdev->dev);
 	return ret > 0 ? 0 : ret;
 }
 
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 13d192ba4aa6..9346d44a06c2 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -512,11 +512,9 @@ static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
 	if (!fmd->pmf)
 		return -ENXIO;
 
-	ret = pm_runtime_get_sync(fmd->pmf);
-	if (ret < 0) {
-		pm_runtime_put(fmd->pmf);
+	ret = pm_runtime_resume_and_get(fmd->pmf);
+	if (ret < 0)
 		return ret;
-	}
 
 	fmd->num_sensors = 0;
 
@@ -1291,7 +1289,7 @@ static int cam_clk_prepare(struct clk_hw *hw)
 	if (camclk->fmd->pmf == NULL)
 		return -ENODEV;
 
-	ret = pm_runtime_get_sync(camclk->fmd->pmf);
+	ret = pm_runtime_resume_and_get(camclk->fmd->pmf);
 	return ret < 0 ? ret : 0;
 }
 
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
index 1aac167abb17..2a6afb78a049 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,11 +509,9 @@ 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);
-		if (ret && ret != 1) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret && ret != 1)
 			return ret;
-		}
 	}
 
 	mutex_lock(&state->lock);
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 63/79] media: exynos-gsc: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Hans Verkuil, Krzysztof Kozlowski, Mauro Carvalho Chehab,
	Sylwester Nawrocki, linux-arm-kernel, linux-kernel, linux-media,
	linux-samsung-soc

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.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index 27a3c92c73bc..09551e96ac15 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -58,7 +58,7 @@ static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct gsc_ctx *ctx = q->drv_priv;
 	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->gsc_dev->pdev->dev);
+	ret = pm_runtime_resume_and_get(&ctx->gsc_dev->pdev->dev);
 	return ret > 0 ? 0 : ret;
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 63/79] media: exynos-gsc: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Hans Verkuil, Krzysztof Kozlowski, Mauro Carvalho Chehab,
	Sylwester Nawrocki, linux-arm-kernel, linux-kernel, linux-media,
	linux-samsung-soc

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.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index 27a3c92c73bc..09551e96ac15 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -58,7 +58,7 @@ static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct gsc_ctx *ctx = q->drv_priv;
 	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->gsc_dev->pdev->dev);
+	ret = pm_runtime_resume_and_get(&ctx->gsc_dev->pdev->dev);
 	return ret > 0 ? 0 : ret;
 }
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 64/79] media: mtk-jpeg: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Bin Liu,
	Matthias Brugger, Mauro Carvalho Chehab, Rick Chang,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

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/mtk-jpeg/mtk_jpeg_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
index 88a23bce569d..a89c7b206eef 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -920,7 +920,7 @@ static void mtk_jpeg_enc_device_run(void *priv)
 	src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 	dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 
-	ret = pm_runtime_get_sync(jpeg->dev);
+	ret = pm_runtime_resume_and_get(jpeg->dev);
 	if (ret < 0)
 		goto enc_end;
 
@@ -973,7 +973,7 @@ static void mtk_jpeg_dec_device_run(void *priv)
 		return;
 	}
 
-	ret = pm_runtime_get_sync(jpeg->dev);
+	ret = pm_runtime_resume_and_get(jpeg->dev);
 	if (ret < 0)
 		goto dec_end;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 64/79] media: mtk-jpeg: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Bin Liu,
	Matthias Brugger, Mauro Carvalho Chehab, Rick Chang,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

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/mtk-jpeg/mtk_jpeg_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
index 88a23bce569d..a89c7b206eef 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -920,7 +920,7 @@ static void mtk_jpeg_enc_device_run(void *priv)
 	src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 	dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 
-	ret = pm_runtime_get_sync(jpeg->dev);
+	ret = pm_runtime_resume_and_get(jpeg->dev);
 	if (ret < 0)
 		goto enc_end;
 
@@ -973,7 +973,7 @@ static void mtk_jpeg_dec_device_run(void *priv)
 		return;
 	}
 
-	ret = pm_runtime_get_sync(jpeg->dev);
+	ret = pm_runtime_resume_and_get(jpeg->dev);
 	if (ret < 0)
 		goto dec_end;
 
-- 
2.30.2


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 64/79] media: mtk-jpeg: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Bin Liu,
	Matthias Brugger, Mauro Carvalho Chehab, Rick Chang,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

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/mtk-jpeg/mtk_jpeg_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
index 88a23bce569d..a89c7b206eef 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -920,7 +920,7 @@ static void mtk_jpeg_enc_device_run(void *priv)
 	src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 	dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 
-	ret = pm_runtime_get_sync(jpeg->dev);
+	ret = pm_runtime_resume_and_get(jpeg->dev);
 	if (ret < 0)
 		goto enc_end;
 
@@ -973,7 +973,7 @@ static void mtk_jpeg_dec_device_run(void *priv)
 		return;
 	}
 
-	ret = pm_runtime_get_sync(jpeg->dev);
+	ret = pm_runtime_resume_and_get(jpeg->dev);
 	if (ret < 0)
 		goto dec_end;
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 65/79] media: camss: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (65 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andy Gross,
	Bjorn Andersson, Mauro Carvalho Chehab, Robert Foss, Todor Tomov,
	linux-arm-msm, linux-kernel, linux-media

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.

Reviewed-by: Robert Foss <robert.foss@linaro.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/qcom/camss/camss-csid.c   | 6 ++----
 drivers/media/platform/qcom/camss/camss-csiphy.c | 6 ++----
 drivers/media/platform/qcom/camss/camss-ispif.c  | 6 ++----
 drivers/media/platform/qcom/camss/camss-vfe.c    | 5 +++--
 4 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c
index cc11fbfdae13..d2a7f2a64f26 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -156,11 +156,9 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
 	int ret;
 
 	if (on) {
-		ret = pm_runtime_get_sync(dev);
-		if (ret < 0) {
-			pm_runtime_put_sync(dev);
+		ret = pm_runtime_resume_and_get(dev);
+		if (ret < 0)
 			return ret;
-		}
 
 		ret = regulator_enable(csid->vdda);
 		if (ret < 0) {
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/media/platform/qcom/camss/camss-csiphy.c
index b3c3bf19e522..8e18b8e668cf 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -197,11 +197,9 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int on)
 	if (on) {
 		int ret;
 
-		ret = pm_runtime_get_sync(dev);
-		if (ret < 0) {
-			pm_runtime_put_sync(dev);
+		ret = pm_runtime_resume_and_get(dev);
+		if (ret < 0)
 			return ret;
-		}
 
 		ret = csiphy_set_clock_rates(csiphy);
 		if (ret < 0) {
diff --git a/drivers/media/platform/qcom/camss/camss-ispif.c b/drivers/media/platform/qcom/camss/camss-ispif.c
index 37611c8861da..d9907742ba79 100644
--- a/drivers/media/platform/qcom/camss/camss-ispif.c
+++ b/drivers/media/platform/qcom/camss/camss-ispif.c
@@ -372,11 +372,9 @@ static int ispif_set_power(struct v4l2_subdev *sd, int on)
 			goto exit;
 		}
 
-		ret = pm_runtime_get_sync(dev);
-		if (ret < 0) {
-			pm_runtime_put_sync(dev);
+		ret = pm_runtime_resume_and_get(dev);
+		if (ret < 0)
 			goto exit;
-		}
 
 		ret = camss_enable_clocks(ispif->nclocks, ispif->clock, dev);
 		if (ret < 0) {
diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c
index 15695fd466c4..cf743e61f798 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -584,9 +584,9 @@ static int vfe_get(struct vfe_device *vfe)
 		if (ret < 0)
 			goto error_pm_domain;
 
-		ret = pm_runtime_get_sync(vfe->camss->dev);
+		ret = pm_runtime_resume_and_get(vfe->camss->dev);
 		if (ret < 0)
-			goto error_pm_runtime_get;
+			goto error_domain_off;
 
 		ret = vfe_set_clock_rates(vfe);
 		if (ret < 0)
@@ -620,6 +620,7 @@ static int vfe_get(struct vfe_device *vfe)
 
 error_pm_runtime_get:
 	pm_runtime_put_sync(vfe->camss->dev);
+error_domain_off:
 	vfe->ops->pm_domain_off(vfe);
 
 error_pm_domain:
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 66/79] media: venus: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (66 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andy Gross,
	Bjorn Andersson, Mauro Carvalho Chehab, Stanimir Varbanov,
	linux-arm-msm, linux-kernel, linux-media

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/qcom/venus/core.c      | 30 +++++++++----------
 .../media/platform/qcom/venus/pm_helpers.c    | 10 +++----
 2 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c
index c80c27c87ccc..aa359f8e82c5 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -84,11 +84,9 @@ static void venus_sys_error_handler(struct work_struct *work)
 			container_of(work, struct venus_core, work.work);
 	int ret = 0;
 
-	ret = pm_runtime_get_sync(core->dev);
-	if (WARN_ON(ret < 0)) {
-		pm_runtime_put_noidle(core->dev);
+	ret = pm_runtime_resume_and_get(core->dev);
+	if (WARN_ON(ret < 0))
 		return;
-	}
 
 	hfi_core_deinit(core, true);
 
@@ -110,11 +108,9 @@ static void venus_sys_error_handler(struct work_struct *work)
 
 	hfi_reinit(core);
 
-	ret = pm_runtime_get_sync(core->dev);
-	if (WARN_ON(ret < 0)) {
-		pm_runtime_put_noidle(core->dev);
+	ret = pm_runtime_resume_and_get(core->dev);
+	if (WARN_ON(ret < 0))
 		return;
-	}
 
 	ret = venus_boot(core);
 	ret |= hfi_core_resume(core, true);
@@ -313,21 +309,21 @@ static int venus_probe(struct platform_device *pdev)
 
 	pm_runtime_enable(dev);
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0)
 		goto err_runtime_disable;
 
 	ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
 	if (ret)
-		goto err_runtime_disable;
+		goto err_pm;
 
 	ret = venus_firmware_init(core);
 	if (ret)
-		goto err_runtime_disable;
+		goto err_pm;
 
 	ret = venus_boot(core);
 	if (ret)
-		goto err_runtime_disable;
+		goto err_pm;
 
 	ret = hfi_core_resume(core, true);
 	if (ret)
@@ -359,8 +355,9 @@ static int venus_probe(struct platform_device *pdev)
 	v4l2_device_unregister(&core->v4l2_dev);
 err_venus_shutdown:
 	venus_shutdown(core);
-err_runtime_disable:
+err_pm:
 	pm_runtime_put_noidle(dev);
+err_runtime_disable:
 	pm_runtime_set_suspended(dev);
 	pm_runtime_disable(dev);
 	hfi_destroy(core);
@@ -379,7 +376,7 @@ static int venus_remove(struct platform_device *pdev)
 	struct device *dev = core->dev;
 	int ret;
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	WARN_ON(ret < 0);
 
 	ret = hfi_core_deinit(core, true);
@@ -390,7 +387,8 @@ static int venus_remove(struct platform_device *pdev)
 
 	venus_firmware_deinit(core);
 
-	pm_runtime_put_sync(dev);
+	if (ret >= 0)
+		pm_runtime_put_sync(dev);
 	pm_runtime_disable(dev);
 
 	if (pm_ops->core_put)
@@ -411,7 +409,7 @@ static void venus_core_shutdown(struct platform_device *pdev)
 {
 	struct venus_core *core = platform_get_drvdata(pdev);
 
-	pm_runtime_get_sync(core->dev);
+	pm_runtime_resume_and_get(core->dev);
 	venus_shutdown(core);
 	venus_firmware_deinit(core);
 	pm_runtime_put_sync(core->dev);
diff --git a/drivers/media/platform/qcom/venus/pm_helpers.c b/drivers/media/platform/qcom/venus/pm_helpers.c
index c7e1ebec47ee..9e32ec866af7 100644
--- a/drivers/media/platform/qcom/venus/pm_helpers.c
+++ b/drivers/media/platform/qcom/venus/pm_helpers.c
@@ -486,7 +486,7 @@ static int poweron_coreid(struct venus_core *core, unsigned int coreid_mask)
 	int ret;
 
 	if (coreid_mask & VIDC_CORE_ID_1) {
-		ret = pm_runtime_get_sync(core->pmdomains[1]);
+		ret = pm_runtime_resume_and_get(core->pmdomains[1]);
 		if (ret < 0)
 			return ret;
 
@@ -504,7 +504,7 @@ static int poweron_coreid(struct venus_core *core, unsigned int coreid_mask)
 	}
 
 	if (coreid_mask & VIDC_CORE_ID_2) {
-		ret = pm_runtime_get_sync(core->pmdomains[2]);
+		ret = pm_runtime_resume_and_get(core->pmdomains[2]);
 		if (ret < 0)
 			return ret;
 
@@ -990,11 +990,9 @@ static int core_power_v4(struct venus_core *core, int on)
 
 	if (on == POWER_ON) {
 		if (pmctrl) {
-			ret = pm_runtime_get_sync(pmctrl);
-			if (ret < 0) {
-				pm_runtime_put_noidle(pmctrl);
+			ret = pm_runtime_resume_and_get(pmctrl);
+			if (ret < 0)
 				return ret;
-			}
 		}
 
 		ret = core_resets_reset(core);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 67/79] media: venus: vdec: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (67 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  2021-04-30 17:53   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andy Gross,
	Bjorn Andersson, Mauro Carvalho Chehab, Stanimir Varbanov,
	linux-arm-msm, linux-kernel, linux-media

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/qcom/venus/vdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
index ddb7cd39424e..347e533ea673 100644
--- a/drivers/media/platform/qcom/venus/vdec.c
+++ b/drivers/media/platform/qcom/venus/vdec.c
@@ -568,7 +568,7 @@ static int vdec_pm_get(struct venus_inst *inst)
 	int ret;
 
 	mutex_lock(&core->pm_lock);
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	mutex_unlock(&core->pm_lock);
 
 	return ret < 0 ? ret : 0;
@@ -601,7 +601,7 @@ static int vdec_pm_get_put(struct venus_inst *inst)
 	mutex_lock(&core->pm_lock);
 
 	if (pm_runtime_suspended(dev)) {
-		ret = pm_runtime_get_sync(dev);
+		ret = pm_runtime_resume_and_get(dev);
 		if (ret < 0)
 			goto error;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 68/79] media: venus: venc: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (68 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andy Gross,
	Bjorn Andersson, Mauro Carvalho Chehab, Stanimir Varbanov,
	linux-arm-msm, linux-kernel, linux-media

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/qcom/venus/venc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
index 4a7291f934b6..8dd49d4f124c 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -1205,9 +1205,9 @@ static int venc_open(struct file *file)
 
 	venus_helper_init_instance(inst);
 
-	ret = pm_runtime_get_sync(core->dev_enc);
+	ret = pm_runtime_resume_and_get(core->dev_enc);
 	if (ret < 0)
-		goto err_put_sync;
+		goto err_free;
 
 	ret = venc_ctrl_init(inst);
 	if (ret)
@@ -1252,6 +1252,7 @@ static int venc_open(struct file *file)
 	venc_ctrl_deinit(inst);
 err_put_sync:
 	pm_runtime_put_sync(core->dev_enc);
+err_free:
 	kfree(inst);
 	return ret;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 69/79] media: rcar-fcp: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (69 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Laurent Pinchart,
	Mauro Carvalho Chehab, linux-kernel, linux-media,
	linux-renesas-soc

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/rcar-fcp.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/rcar-fcp.c b/drivers/media/platform/rcar-fcp.c
index 5c03318ae07b..de76af58013c 100644
--- a/drivers/media/platform/rcar-fcp.c
+++ b/drivers/media/platform/rcar-fcp.c
@@ -101,11 +101,9 @@ int rcar_fcp_enable(struct rcar_fcp_device *fcp)
 	if (!fcp)
 		return 0;
 
-	ret = pm_runtime_get_sync(fcp->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(fcp->dev);
+	ret = pm_runtime_resume_and_get(fcp->dev);
+	if (ret < 0)
 		return ret;
-	}
 
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 70/79] media: rkisp1: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dafna Hirschfeld,
	Heiko Stuebner, Helen Koike, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-rockchip

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/rockchip/rkisp1/rkisp1-capture.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
index 5f6c9d1623e4..3730376897d9 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
@@ -1003,9 +1003,8 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
 	if (ret)
 		goto err_pipeline_stop;
 
-	ret = pm_runtime_get_sync(cap->rkisp1->dev);
+	ret = pm_runtime_resume_and_get(cap->rkisp1->dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(cap->rkisp1->dev);
 		dev_err(cap->rkisp1->dev, "power up failed %d\n", ret);
 		goto err_destroy_dummy;
 	}
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 70/79] media: rkisp1: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dafna Hirschfeld,
	Heiko Stuebner, Helen Koike, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-rockchip

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/rockchip/rkisp1/rkisp1-capture.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
index 5f6c9d1623e4..3730376897d9 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
@@ -1003,9 +1003,8 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
 	if (ret)
 		goto err_pipeline_stop;
 
-	ret = pm_runtime_get_sync(cap->rkisp1->dev);
+	ret = pm_runtime_resume_and_get(cap->rkisp1->dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(cap->rkisp1->dev);
 		dev_err(cap->rkisp1->dev, "power up failed %d\n", ret);
 		goto err_destroy_dummy;
 	}
-- 
2.30.2


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 70/79] media: rkisp1: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dafna Hirschfeld,
	Heiko Stuebner, Helen Koike, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-rockchip

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/rockchip/rkisp1/rkisp1-capture.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
index 5f6c9d1623e4..3730376897d9 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
@@ -1003,9 +1003,8 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
 	if (ret)
 		goto err_pipeline_stop;
 
-	ret = pm_runtime_get_sync(cap->rkisp1->dev);
+	ret = pm_runtime_resume_and_get(cap->rkisp1->dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(cap->rkisp1->dev);
 		dev_err(cap->rkisp1->dev, "power up failed %d\n", ret);
 		goto err_destroy_dummy;
 	}
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 71/79] media: s3c-camif: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (71 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Mauro Carvalho Chehab, Sylwester Nawrocki, linux-kernel,
	linux-media, linux-samsung-soc, Sylwester Nawrocki

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.

Reviewed-by: Sylwester Nawrocki <snawrocki@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/s3c-camif/camif-capture.c | 2 +-
 drivers/media/platform/s3c-camif/camif-core.c    | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index 9ca49af29542..62241ec3b978 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -547,7 +547,7 @@ static int s3c_camif_open(struct file *file)
 	if (ret < 0)
 		goto unlock;
 
-	ret = pm_runtime_get_sync(camif->dev);
+	ret = pm_runtime_resume_and_get(camif->dev);
 	if (ret < 0)
 		goto err_pm;
 
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index 4c3c00d59c92..e1d51fd3e700 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -460,9 +460,9 @@ static int s3c_camif_probe(struct platform_device *pdev)
 
 	pm_runtime_enable(dev);
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0)
-		goto err_pm;
+		goto err_disable;
 
 	ret = camif_media_dev_init(camif);
 	if (ret < 0)
@@ -502,6 +502,7 @@ static int s3c_camif_probe(struct platform_device *pdev)
 	camif_unregister_media_entities(camif);
 err_pm:
 	pm_runtime_put(dev);
+err_disable:
 	pm_runtime_disable(dev);
 	camif_clk_put(camif);
 err_clk:
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 72/79] media: s5p-mfc: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrzej Hajda,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-kernel,
	linux-media, Sylwester Nawrocki

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.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/s5p-mfc/s5p_mfc_pm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
index 62d2320a7218..88b7d33c9197 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
@@ -78,11 +78,9 @@ int s5p_mfc_power_on(void)
 {
 	int i, ret = 0;
 
-	ret = pm_runtime_get_sync(pm->device);
-	if (ret < 0) {
-		pm_runtime_put_noidle(pm->device);
+	ret = pm_runtime_resume_and_get(pm->device);
+	if (ret < 0)
 		return ret;
-	}
 
 	/* clock control */
 	for (i = 0; i < pm->num_clocks; i++) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 72/79] media: s5p-mfc: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrzej Hajda,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-kernel,
	linux-media, Sylwester Nawrocki

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.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/s5p-mfc/s5p_mfc_pm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
index 62d2320a7218..88b7d33c9197 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
@@ -78,11 +78,9 @@ int s5p_mfc_power_on(void)
 {
 	int i, ret = 0;
 
-	ret = pm_runtime_get_sync(pm->device);
-	if (ret < 0) {
-		pm_runtime_put_noidle(pm->device);
+	ret = pm_runtime_resume_and_get(pm->device);
+	if (ret < 0)
 		return ret;
-	}
 
 	/* clock control */
 	for (i = 0; i < pm->num_clocks; i++) {
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 73/79] media: stm32: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Alexandre Torgue,
	Hugues Fruchet, Mauro Carvalho Chehab, Maxime Coquelin,
	linux-arm-kernel, linux-kernel, linux-media, linux-stm32

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/stm32/stm32-dcmi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
index bbcc2254fa2e..5f4e1db8cfcd 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -723,11 +723,11 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
 	u32 val = 0;
 	int ret;
 
-	ret = pm_runtime_get_sync(dcmi->dev);
+	ret = pm_runtime_resume_and_get(dcmi->dev);
 	if (ret < 0) {
 		dev_err(dcmi->dev, "%s: Failed to start streaming, cannot get sync (%d)\n",
 			__func__, ret);
-		goto err_pm_put;
+		goto err_unlock;
 	}
 
 	ret = media_pipeline_start(&dcmi->vdev->entity, &dcmi->pipeline);
@@ -848,6 +848,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 err_pm_put:
 	pm_runtime_put(dcmi->dev);
+err_unlock:
 	spin_lock_irq(&dcmi->irqlock);
 	/*
 	 * Return all buffers to vb2 in QUEUED state.
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 73/79] media: stm32: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Alexandre Torgue,
	Hugues Fruchet, Mauro Carvalho Chehab, Maxime Coquelin,
	linux-arm-kernel, linux-kernel, linux-media, linux-stm32

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/stm32/stm32-dcmi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
index bbcc2254fa2e..5f4e1db8cfcd 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -723,11 +723,11 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
 	u32 val = 0;
 	int ret;
 
-	ret = pm_runtime_get_sync(dcmi->dev);
+	ret = pm_runtime_resume_and_get(dcmi->dev);
 	if (ret < 0) {
 		dev_err(dcmi->dev, "%s: Failed to start streaming, cannot get sync (%d)\n",
 			__func__, ret);
-		goto err_pm_put;
+		goto err_unlock;
 	}
 
 	ret = media_pipeline_start(&dcmi->vdev->entity, &dcmi->pipeline);
@@ -848,6 +848,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 err_pm_put:
 	pm_runtime_put(dcmi->dev);
+err_unlock:
 	spin_lock_irq(&dcmi->irqlock);
 	/*
 	 * Return all buffers to vb2 in QUEUED state.
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 74/79] media: sunxi: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Chen-Yu Tsai,
	Jernej Skrabec, Mauro Carvalho Chehab, Maxime Ripard,
	linux-arm-kernel, linux-kernel, linux-media

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/sunxi/sun4i-csi/sun4i_v4l2.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
index 4785faddf630..54b909987caa 100644
--- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
+++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
@@ -206,9 +206,9 @@ static int sun4i_csi_open(struct file *file)
 	if (ret)
 		return ret;
 
-	ret = pm_runtime_get_sync(csi->dev);
+	ret = pm_runtime_resume_and_get(csi->dev);
 	if (ret < 0)
-		goto err_pm_put;
+		goto err_unlock;
 
 	ret = v4l2_pipeline_pm_get(&csi->vdev.entity);
 	if (ret)
@@ -227,6 +227,8 @@ static int sun4i_csi_open(struct file *file)
 
 err_pm_put:
 	pm_runtime_put(csi->dev);
+
+err_unlock:
 	mutex_unlock(&csi->lock);
 
 	return ret;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 74/79] media: sunxi: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Chen-Yu Tsai,
	Jernej Skrabec, Mauro Carvalho Chehab, Maxime Ripard,
	linux-arm-kernel, linux-kernel, linux-media

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/sunxi/sun4i-csi/sun4i_v4l2.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
index 4785faddf630..54b909987caa 100644
--- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
+++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
@@ -206,9 +206,9 @@ static int sun4i_csi_open(struct file *file)
 	if (ret)
 		return ret;
 
-	ret = pm_runtime_get_sync(csi->dev);
+	ret = pm_runtime_resume_and_get(csi->dev);
 	if (ret < 0)
-		goto err_pm_put;
+		goto err_unlock;
 
 	ret = v4l2_pipeline_pm_get(&csi->vdev.entity);
 	if (ret)
@@ -227,6 +227,8 @@ static int sun4i_csi_open(struct file *file)
 
 err_pm_put:
 	pm_runtime_put(csi->dev);
+
+err_unlock:
 	mutex_unlock(&csi->lock);
 
 	return ret;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 75/79] media: ti-vpe: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (75 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  2021-04-30 18:03   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Benoit Parrot,
	Mauro Carvalho Chehab, linux-kernel, linux-media

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/ti-vpe/cal-video.c | 4 +++-
 drivers/media/platform/ti-vpe/cal.c       | 8 +++++---
 drivers/media/platform/ti-vpe/vpe.c       | 4 +---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
index 7b7436a355ee..15fb5360cf13 100644
--- a/drivers/media/platform/ti-vpe/cal-video.c
+++ b/drivers/media/platform/ti-vpe/cal-video.c
@@ -700,7 +700,9 @@ static int cal_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 	addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
 
-	pm_runtime_get_sync(ctx->cal->dev);
+	ret = pm_runtime_resume_and_get(ctx->cal->dev);
+	if (ret < 0)
+		goto error_pipeline;
 
 	cal_ctx_set_dma_addr(ctx, addr);
 	cal_ctx_start(ctx);
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 2e2bef91b2b0..76fe7a8b33f6 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -1024,7 +1024,7 @@ static int cal_probe(struct platform_device *pdev)
 
 	/* Read the revision and hardware info to verify hardware access. */
 	pm_runtime_enable(&pdev->dev);
-	ret = pm_runtime_get_sync(&pdev->dev);
+	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret)
 		goto error_pm_runtime;
 
@@ -1098,10 +1098,11 @@ static int cal_remove(struct platform_device *pdev)
 {
 	struct cal_dev *cal = platform_get_drvdata(pdev);
 	unsigned int i;
+	int ret;
 
 	cal_dbg(1, cal, "Removing %s\n", CAL_MODULE_NAME);
 
-	pm_runtime_get_sync(&pdev->dev);
+	ret = pm_runtime_resume_and_get(&pdev->dev);
 
 	cal_media_unregister(cal);
 
@@ -1115,7 +1116,8 @@ static int cal_remove(struct platform_device *pdev)
 	for (i = 0; i < cal->data->num_csi2_phy; i++)
 		cal_camerarx_destroy(cal->phy[i]);
 
-	pm_runtime_put_sync(&pdev->dev);
+	if (ret >= 0)
+		pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
 	return 0;
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index 10251b787674..07cb2c140295 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2471,10 +2471,8 @@ static int vpe_runtime_get(struct platform_device *pdev)
 
 	dev_dbg(&pdev->dev, "vpe_runtime_get\n");
 
-	r = pm_runtime_get_sync(&pdev->dev);
+	r = pm_runtime_resume_and_get(&pdev->dev);
 	WARN_ON(r < 0);
-	if (r)
-		pm_runtime_put_noidle(&pdev->dev);
 	return r < 0 ? r : 0;
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 76/79] media: vsp1: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (76 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Kieran Bingham,
	Laurent Pinchart, Mauro Carvalho Chehab, linux-kernel,
	linux-media, linux-renesas-soc

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/vsp1/vsp1_drv.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index aa66e4f5f3f3..c2bdb6629657 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -561,11 +561,9 @@ int vsp1_device_get(struct vsp1_device *vsp1)
 {
 	int ret;
 
-	ret = pm_runtime_get_sync(vsp1->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(vsp1->dev);
+	ret = pm_runtime_resume_and_get(vsp1->dev);
+	if (ret < 0)
 		return ret;
-	}
 
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 77/79] media: rcar-vin: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
                   ` (77 preceding siblings ...)
  (?)
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
  2021-04-30 18:05   ` Jonathan Cameron
  -1 siblings, 1 reply; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Niklas Söderlund, Mauro Carvalho Chehab, linux-kernel,
	linux-media, linux-renesas-soc, Niklas Söderlund

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.

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/rcar-vin/rcar-csi2.c | 15 ++++++++++++---
 drivers/media/platform/rcar-vin/rcar-dma.c  |  6 ++----
 drivers/media/platform/rcar-vin/rcar-v4l2.c |  6 ++----
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index e06cd512aba2..436fb17f73ea 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -406,10 +406,17 @@ static void rcsi2_enter_standby(struct rcar_csi2 *priv)
 	pm_runtime_put(priv->dev);
 }
 
-static void rcsi2_exit_standby(struct rcar_csi2 *priv)
+static int rcsi2_exit_standby(struct rcar_csi2 *priv)
 {
-	pm_runtime_get_sync(priv->dev);
+	int ret;
+
+	ret = pm_runtime_resume_and_get(priv->dev);
+	if (ret < 0)
+		return ret;
+
 	reset_control_deassert(priv->rstc);
+
+	return ret;
 }
 
 static int rcsi2_wait_phy_start(struct rcar_csi2 *priv,
@@ -657,7 +664,9 @@ static int rcsi2_start(struct rcar_csi2 *priv)
 {
 	int ret;
 
-	rcsi2_exit_standby(priv);
+	ret = rcsi2_exit_standby(priv);
+	if (ret < 0)
+		return ret;
 
 	ret = rcsi2_start_receiver(priv);
 	if (ret) {
diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
index f30dafbdf61c..f5f722ab1d4e 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -1458,11 +1458,9 @@ int rvin_set_channel_routing(struct rvin_dev *vin, u8 chsel)
 	u32 vnmc;
 	int ret;
 
-	ret = pm_runtime_get_sync(vin->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(vin->dev);
+	ret = pm_runtime_resume_and_get(vin->dev);
+	if (ret < 0)
 		return ret;
-	}
 
 	/* Make register writes take effect immediately. */
 	vnmc = rvin_read(vin, VNMC_REG);
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 457a65bf6b66..b1e9f86caa5c 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -870,11 +870,9 @@ static int rvin_open(struct file *file)
 	struct rvin_dev *vin = video_drvdata(file);
 	int ret;
 
-	ret = pm_runtime_get_sync(vin->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(vin->dev);
+	ret = pm_runtime_resume_and_get(vin->dev);
+	if (ret < 0)
 		return ret;
-	}
 
 	ret = mutex_lock_interruptible(&vin->lock);
 	if (ret)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, Philipp Zabel, devel,
	linux-kernel, linux-media, linux-rockchip

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.

While there's nothing wrong with the current usage on this driver,
as we're getting rid of the pm_runtime_get_sync() call all over
the media subsystem, let's remove the last occurrence on this
driver.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 595e82a82728..25fa36e7e773 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
 	return hantro_get_dec_buf_addr(ctx, buf);
 }
 
-static void hantro_job_finish(struct hantro_dev *vpu,
-			      struct hantro_ctx *ctx,
-			      enum vb2_buffer_state result)
+static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
+				    struct hantro_ctx *ctx,
+				    enum vb2_buffer_state result)
 {
 	struct vb2_v4l2_buffer *src, *dst;
 
-	pm_runtime_mark_last_busy(vpu->dev);
-	pm_runtime_put_autosuspend(vpu->dev);
 	clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
 
 	src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
@@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
 					 result);
 }
 
+static void hantro_job_finish(struct hantro_dev *vpu,
+			      struct hantro_ctx *ctx,
+			      enum vb2_buffer_state result)
+{
+	pm_runtime_mark_last_busy(vpu->dev);
+	pm_runtime_put_autosuspend(vpu->dev);
+
+	hantro_job_finish_no_pm(vpu, ctx, result);
+}
+
 void hantro_irq_done(struct hantro_dev *vpu,
 		     enum vb2_buffer_state result)
 {
@@ -155,7 +163,8 @@ static void device_run(void *priv)
 	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
 	if (ret)
 		goto err_cancel_job;
-	ret = pm_runtime_get_sync(ctx->dev->dev);
+
+	ret = pm_runtime_resume_and_get(ctx->dev->dev);
 	if (ret < 0)
 		goto err_cancel_job;
 
@@ -165,7 +174,7 @@ static void device_run(void *priv)
 	return;
 
 err_cancel_job:
-	hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
+	hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
 }
 
 static struct v4l2_m2m_ops vpu_m2m_ops = {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: devel, Mauro Carvalho Chehab, Greg Kroah-Hartman, linuxarm,
	linux-kernel, linux-rockchip, Philipp Zabel, mauro.chehab,
	Mauro Carvalho Chehab, Ezequiel Garcia, linux-media

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.

While there's nothing wrong with the current usage on this driver,
as we're getting rid of the pm_runtime_get_sync() call all over
the media subsystem, let's remove the last occurrence on this
driver.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 595e82a82728..25fa36e7e773 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
 	return hantro_get_dec_buf_addr(ctx, buf);
 }
 
-static void hantro_job_finish(struct hantro_dev *vpu,
-			      struct hantro_ctx *ctx,
-			      enum vb2_buffer_state result)
+static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
+				    struct hantro_ctx *ctx,
+				    enum vb2_buffer_state result)
 {
 	struct vb2_v4l2_buffer *src, *dst;
 
-	pm_runtime_mark_last_busy(vpu->dev);
-	pm_runtime_put_autosuspend(vpu->dev);
 	clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
 
 	src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
@@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
 					 result);
 }
 
+static void hantro_job_finish(struct hantro_dev *vpu,
+			      struct hantro_ctx *ctx,
+			      enum vb2_buffer_state result)
+{
+	pm_runtime_mark_last_busy(vpu->dev);
+	pm_runtime_put_autosuspend(vpu->dev);
+
+	hantro_job_finish_no_pm(vpu, ctx, result);
+}
+
 void hantro_irq_done(struct hantro_dev *vpu,
 		     enum vb2_buffer_state result)
 {
@@ -155,7 +163,8 @@ static void device_run(void *priv)
 	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
 	if (ret)
 		goto err_cancel_job;
-	ret = pm_runtime_get_sync(ctx->dev->dev);
+
+	ret = pm_runtime_resume_and_get(ctx->dev->dev);
 	if (ret < 0)
 		goto err_cancel_job;
 
@@ -165,7 +174,7 @@ static void device_run(void *priv)
 	return;
 
 err_cancel_job:
-	hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
+	hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
 }
 
 static struct v4l2_m2m_ops vpu_m2m_ops = {
-- 
2.30.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, Philipp Zabel, devel,
	linux-kernel, linux-media, linux-rockchip

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.

While there's nothing wrong with the current usage on this driver,
as we're getting rid of the pm_runtime_get_sync() call all over
the media subsystem, let's remove the last occurrence on this
driver.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 595e82a82728..25fa36e7e773 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
 	return hantro_get_dec_buf_addr(ctx, buf);
 }
 
-static void hantro_job_finish(struct hantro_dev *vpu,
-			      struct hantro_ctx *ctx,
-			      enum vb2_buffer_state result)
+static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
+				    struct hantro_ctx *ctx,
+				    enum vb2_buffer_state result)
 {
 	struct vb2_v4l2_buffer *src, *dst;
 
-	pm_runtime_mark_last_busy(vpu->dev);
-	pm_runtime_put_autosuspend(vpu->dev);
 	clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
 
 	src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
@@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
 					 result);
 }
 
+static void hantro_job_finish(struct hantro_dev *vpu,
+			      struct hantro_ctx *ctx,
+			      enum vb2_buffer_state result)
+{
+	pm_runtime_mark_last_busy(vpu->dev);
+	pm_runtime_put_autosuspend(vpu->dev);
+
+	hantro_job_finish_no_pm(vpu, ctx, result);
+}
+
 void hantro_irq_done(struct hantro_dev *vpu,
 		     enum vb2_buffer_state result)
 {
@@ -155,7 +163,8 @@ static void device_run(void *priv)
 	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
 	if (ret)
 		goto err_cancel_job;
-	ret = pm_runtime_get_sync(ctx->dev->dev);
+
+	ret = pm_runtime_resume_and_get(ctx->dev->dev);
 	if (ret < 0)
 		goto err_cancel_job;
 
@@ -165,7 +174,7 @@ static void device_run(void *priv)
 	return;
 
 err_cancel_job:
-	hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
+	hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
 }
 
 static struct v4l2_m2m_ops vpu_m2m_ops = {
-- 
2.30.2


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 79/79] media: hantro: do a PM resume earlier
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, Philipp Zabel, devel,
	linux-kernel, linux-media, linux-rockchip

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume,
it would be better to detect it beforehand.

So, change the order inside device_run().

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 25fa36e7e773..67de6b15236d 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -160,14 +160,14 @@ static void device_run(void *priv)
 	src = hantro_get_src_buf(ctx);
 	dst = hantro_get_dst_buf(ctx);
 
-	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
-	if (ret)
-		goto err_cancel_job;
-
 	ret = pm_runtime_resume_and_get(ctx->dev->dev);
 	if (ret < 0)
 		goto err_cancel_job;
 
+	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
+	if (ret)
+		goto err_cancel_job;
+
 	v4l2_m2m_buf_copy_metadata(src, dst, true);
 
 	ctx->codec_ops->run(ctx);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 79/79] media: hantro: do a PM resume earlier
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: devel, Mauro Carvalho Chehab, Greg Kroah-Hartman, linuxarm,
	linux-kernel, linux-rockchip, Philipp Zabel, mauro.chehab,
	Mauro Carvalho Chehab, Ezequiel Garcia, linux-media

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume,
it would be better to detect it beforehand.

So, change the order inside device_run().

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 25fa36e7e773..67de6b15236d 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -160,14 +160,14 @@ static void device_run(void *priv)
 	src = hantro_get_src_buf(ctx);
 	dst = hantro_get_dst_buf(ctx);
 
-	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
-	if (ret)
-		goto err_cancel_job;
-
 	ret = pm_runtime_resume_and_get(ctx->dev->dev);
 	if (ret < 0)
 		goto err_cancel_job;
 
+	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
+	if (ret)
+		goto err_cancel_job;
+
 	v4l2_m2m_buf_copy_metadata(src, dst, true);
 
 	ctx->codec_ops->run(ctx);
-- 
2.30.2

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* [PATCH v4 79/79] media: hantro: do a PM resume earlier
@ 2021-04-28 14:52   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, Philipp Zabel, devel,
	linux-kernel, linux-media, linux-rockchip

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume,
it would be better to detect it beforehand.

So, change the order inside device_run().

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 25fa36e7e773..67de6b15236d 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -160,14 +160,14 @@ static void device_run(void *priv)
 	src = hantro_get_src_buf(ctx);
 	dst = hantro_get_dst_buf(ctx);
 
-	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
-	if (ret)
-		goto err_cancel_job;
-
 	ret = pm_runtime_resume_and_get(ctx->dev->dev);
 	if (ret < 0)
 		goto err_cancel_job;
 
+	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
+	if (ret)
+		goto err_cancel_job;
+
 	v4l2_m2m_buf_copy_metadata(src, dst, true);
 
 	ctx->codec_ops->run(ctx);
-- 
2.30.2


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 15:09     ` Johan Hovold
  -1 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-04-28 15:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, mauro.chehab, Mauro Carvalho Chehab,
	Ezequiel Garcia, linux-media

On Wed, Apr 28, 2021 at 04:51:41PM +0200, Mauro Carvalho Chehab 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.

Again, there is no memory leak here either. Just a potential PM usage
counter leak.

> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/staging/media/rkvdec/rkvdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
> index d821661d30f3..8c17615f3a7a 100644
> --- a/drivers/staging/media/rkvdec/rkvdec.c
> +++ b/drivers/staging/media/rkvdec/rkvdec.c
> @@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
>  	if (WARN_ON(!desc))
>  		return;
>  
> -	ret = pm_runtime_get_sync(rkvdec->dev);
> +	ret = pm_runtime_resume_and_get(rkvdec->dev);
>  	if (ret < 0) {
>  		rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
>  		return;

Johan

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
@ 2021-04-28 15:09     ` Johan Hovold
  0 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-04-28 15:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, mauro.chehab, Mauro Carvalho Chehab,
	Ezequiel Garcia, linux-media

On Wed, Apr 28, 2021 at 04:51:41PM +0200, Mauro Carvalho Chehab 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.

Again, there is no memory leak here either. Just a potential PM usage
counter leak.

> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/staging/media/rkvdec/rkvdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
> index d821661d30f3..8c17615f3a7a 100644
> --- a/drivers/staging/media/rkvdec/rkvdec.c
> +++ b/drivers/staging/media/rkvdec/rkvdec.c
> @@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
>  	if (WARN_ON(!desc))
>  		return;
>  
> -	ret = pm_runtime_get_sync(rkvdec->dev);
> +	ret = pm_runtime_resume_and_get(rkvdec->dev);
>  	if (ret < 0) {
>  		rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
>  		return;

Johan
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
@ 2021-04-28 15:09     ` Johan Hovold
  0 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-04-28 15:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, mauro.chehab, Mauro Carvalho Chehab,
	Ezequiel Garcia, linux-media

On Wed, Apr 28, 2021 at 04:51:41PM +0200, Mauro Carvalho Chehab 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.

Again, there is no memory leak here either. Just a potential PM usage
counter leak.

> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/staging/media/rkvdec/rkvdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
> index d821661d30f3..8c17615f3a7a 100644
> --- a/drivers/staging/media/rkvdec/rkvdec.c
> +++ b/drivers/staging/media/rkvdec/rkvdec.c
> @@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
>  	if (WARN_ON(!desc))
>  		return;
>  
> -	ret = pm_runtime_get_sync(rkvdec->dev);
> +	ret = pm_runtime_resume_and_get(rkvdec->dev);
>  	if (ret < 0) {
>  		rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
>  		return;

Johan

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
  2021-04-28 14:51   ` Mauro Carvalho Chehab
@ 2021-04-28 15:25     ` Sylwester Nawrocki
  -1 siblings, 0 replies; 208+ messages in thread
From: Sylwester Nawrocki @ 2021-04-28 15:25 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

On 28.04.2021 16:51, Mauro Carvalho Chehab wrote:
> Calling pm_runtime_get_sync() at driver's removal time is not
> needed, as this will resume PM runtime. Also, the PM runtime
> code at pm_runtime_disable() already calls it, if it detects
> the need.
> 
> So, change the logic in order to disable PM runtime earlier.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Thank you for correcting that.

> ---
>  drivers/media/platform/exynos-gsc/gsc-core.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
> index 9f41c2e7097a..8b943075c503 100644
> --- a/drivers/media/platform/exynos-gsc/gsc-core.c
> +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
> @@ -1210,18 +1210,19 @@ static int gsc_remove(struct platform_device *pdev)
>  	struct gsc_dev *gsc = platform_get_drvdata(pdev);
>  	int i;
>  
> -	pm_runtime_get_sync(&pdev->dev);
> -
>  	gsc_unregister_m2m_device(gsc);
>  	v4l2_device_unregister(&gsc->v4l2_dev);
>  
>  	vb2_dma_contig_clear_max_seg_size(&pdev->dev);
> -	for (i = 0; i < gsc->num_clocks; i++)
> -		clk_disable_unprepare(gsc->clock[i]);
>  
> -	pm_runtime_put_noidle(&pdev->dev);
>  	pm_runtime_disable(&pdev->dev);
> +	if (!pm_runtime_status_suspended(dev)) {

It should be &pdev->dev here rather than dev...

> +		for (i = 0; i < gsc->num_clocks; i++)
> +			clk_disable_unprepare(gsc->clock[i]);
> +	}
> +	pm_runtime_set_suspended(dev);

and here s/dev/&pdev->dev.

With above issues fixed,
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>

>  	dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
>  	return 0;
>  }
 

Thanks,
Sylwester

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
@ 2021-04-28 15:25     ` Sylwester Nawrocki
  0 siblings, 0 replies; 208+ messages in thread
From: Sylwester Nawrocki @ 2021-04-28 15:25 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

On 28.04.2021 16:51, Mauro Carvalho Chehab wrote:
> Calling pm_runtime_get_sync() at driver's removal time is not
> needed, as this will resume PM runtime. Also, the PM runtime
> code at pm_runtime_disable() already calls it, if it detects
> the need.
> 
> So, change the logic in order to disable PM runtime earlier.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Thank you for correcting that.

> ---
>  drivers/media/platform/exynos-gsc/gsc-core.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
> index 9f41c2e7097a..8b943075c503 100644
> --- a/drivers/media/platform/exynos-gsc/gsc-core.c
> +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
> @@ -1210,18 +1210,19 @@ static int gsc_remove(struct platform_device *pdev)
>  	struct gsc_dev *gsc = platform_get_drvdata(pdev);
>  	int i;
>  
> -	pm_runtime_get_sync(&pdev->dev);
> -
>  	gsc_unregister_m2m_device(gsc);
>  	v4l2_device_unregister(&gsc->v4l2_dev);
>  
>  	vb2_dma_contig_clear_max_seg_size(&pdev->dev);
> -	for (i = 0; i < gsc->num_clocks; i++)
> -		clk_disable_unprepare(gsc->clock[i]);
>  
> -	pm_runtime_put_noidle(&pdev->dev);
>  	pm_runtime_disable(&pdev->dev);
> +	if (!pm_runtime_status_suspended(dev)) {

It should be &pdev->dev here rather than dev...

> +		for (i = 0; i < gsc->num_clocks; i++)
> +			clk_disable_unprepare(gsc->clock[i]);
> +	}
> +	pm_runtime_set_suspended(dev);

and here s/dev/&pdev->dev.

With above issues fixed,
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>

>  	dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
>  	return 0;
>  }
 

Thanks,
Sylwester

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 02/79] media: s6p_cec: decrement usage count if disabled
  2021-04-28 14:51 ` [PATCH v4 02/79] media: s6p_cec: decrement usage count if disabled Mauro Carvalho Chehab
@ 2021-04-28 15:31   ` Sylwester Nawrocki
  0 siblings, 0 replies; 208+ messages in thread
From: Sylwester Nawrocki @ 2021-04-28 15:31 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Hans Verkuil, Kamil Debski,
	Marek Szyprowski, Mauro Carvalho Chehab, linux-kernel,
	linux-media, linux-samsung-soc

On 28.04.2021 16:51, Mauro Carvalho Chehab wrote:
> There's a bug at s5p_cec_adap_enable(): if called to
> disable the device, it should call pm_runtime_put()
> instead of pm_runtime_disable(), as the goal here is to
> decrement the usage_count and not to disable PM runtime.
> 
> Reported-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
> Fixes: 1bcbf6f4b6b0 ("[media] cec: s5p-cec: Add s5p-cec driver")
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Thanks,
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>

There is a typo in the subject, s6p_cec -> s5p_cec.

> ---
>  drivers/media/cec/platform/s5p/s5p_cec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/cec/platform/s5p/s5p_cec.c b/drivers/media/cec/platform/s5p/s5p_cec.c
> index 2a3e7ffefe0a..3c7c4c3c798c 100644
> --- a/drivers/media/cec/platform/s5p/s5p_cec.c
> +++ b/drivers/media/cec/platform/s5p/s5p_cec.c
> @@ -51,7 +51,7 @@ static int s5p_cec_adap_enable(struct cec_adapter *adap, bool enable)
>  	} else {
>  		s5p_cec_mask_tx_interrupts(cec);
>  		s5p_cec_mask_rx_interrupts(cec);
> -		pm_runtime_disable(cec->dev);
> +		pm_runtime_put(cec->dev);
>  	}
>  
>  	return 0;

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
  2021-04-28 14:51 ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 15:50   ` Johan Hovold
  -1 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-04-28 15:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shawn Tu, Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Pengutronix Kernel Team,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Paul Kocialkowski, Mauro Carvalho Chehab, Dave Stevenson,
	Matt Ranostay, Krzysztof Kozlowski, Jonathan Hunter,
	linux-rockchip, Chen-Yu Tsai, Andy Gross, Matthias Brugger,
	Dongchun Zhu, Sakari Ailus, Bingbu Cao, Marek Szyprowski,
	Shunqian Zheng, Tianshu Qiu, NXP Linux Team, Philipp Zabel,
	devel, Jacopo Mondi, Sylwester Nawrocki, linux-tegra,
	Alexandre Torgue, Wenyou Yang, Manivannan Sadhasivam,
	linux-arm-msm, Sascha Hauer, Steve Longerbeam, linux-media,
	Maxime Ripard, Stanimir Varbanov, Benoit Parrot, Helen Koike,
	linux-samsung-soc, linux-mediatek, Jacek Anaszewski,
	mauro.chehab, Sylwester Nawrocki, Paul J. Murphy,
	Ezequiel Garcia, Daniele Alessandrelli, Chiranjeevi Rapolu,
	linux-arm-kernel, Jacob Chen, Jernej Skrabec, Hyungwoo Yang,
	linux-kernel, Robert Foss, Dan Scally, Sowjanya Komatineni,
	Maxime Coquelin, linux-renesas-soc, Yong Zhi, Shawn Guo

On Wed, Apr 28, 2021 at 04:51:21PM +0200, Mauro Carvalho Chehab wrote:
> 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.
> 
> After analyzing the feedback from version 1 of this series, I noticed
> a few other weird behaviors at the PM runtime resume code. So, this
> series start addressing some bugs and issues at the current code.
> Then, it gets rid of pm_runtime_get_sync() at the media subsystem
> (with 2 exceptions).
> 
> It should be noticed that
> 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.
> 
> The rationale of getting rid of pm_runtime_get_sync() is:
> 
> 1. despite its name, this is actually a PM runtime resume call,
>    but some developers didn't seem to realize that, as I got this
>    pattern on some drivers:
> 
>         pm_runtime_get_sync(&client->dev);
>         pm_runtime_disable(&client->dev);
>         pm_runtime_set_suspended(&client->dev);
>         pm_runtime_put_noidle(&client->dev);
> 
>    It makes no sense to resume PM just to suspend it again ;-)

This is perfectly alright. Take a look at ov7740_remove() for example:

	pm_runtime_get_sync(&client->dev);
	pm_runtime_disable(&client->dev);
	pm_runtime_set_suspended(&client->dev);
	pm_runtime_put_noidle(&client->dev);
	
	ov7740_set_power(ov7740, 0);

There's an explicit power-off after balancing the PM count and this will
work regardless of the power state when entering this function.

So this has nothing to do with pm_runtime_get_sync() per se.

> 2. Usual *_get() methods only increment their use count on success,
>    but pm_runtime_get_sync() increments it unconditionally. Due to
>    that, several drivers were mistakenly not calling
>    pm_runtime_put_noidle() when it fails;

Sure, but pm_runtime_get_async() also works this way. You just won't be
notified if the async resume fails.

> 3. The name of the new variant is a lot clearer:
> 	pm_runtime_resume_and_get()
>     As its same clearly says that this is a PM runtime resume function,
>     that also increments the usage counter on success;

It also introduced an inconsistency in the API and does not pair as well
with the pm_runtime_put variants.

> 4. Consistency: we did similar changes subsystem wide with
>    for instance strlcpy() and strcpy() that got replaced by
>    strscpy(). Having all drivers using the same known-to-be-safe
>    methods is a good thing;

It's not known to be safe; there are ways to get also this interface
wrong as for example this series has shown.

> 5. Prevent newer drivers to copy-and-paste a code that it would
>    be easier to break if they don't truly understand what's behind
>    the scenes.

Cargo-cult programming always runs that risk.

> This series replace places  pm_runtime_get_sync(), by calling
> 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.

The only valid point about and use for pm_runtime_resume_and_get() is to
avoid leaking a PM usage count reference in the unlikely case that
resume fails (something which hardly any driver implements recovery
from anyway).

It's a convenience wrapper that saves you from writing one extra line in
some cases (depending on how you implement runtime-pm support) and not a
silver bullet against bugs.
 
> compile-tested only.
> 
> Patches 1 to 7 fix some issues that already exists at the current
> PM runtime code;
> 
> patches 8 to 20 fix some usage_count problems that still exists
> at the media subsystem;
> 
> patches 21 to 78 repaces pm_runtime_get_sync() by 
> pm_runtime_resume_and_get();
> 
> Patch 79 (and a hunk on patch 78) documents the two exceptions
> where pm_runtime_get_sync() will still be used for now.
> 
> ---
> 
> v4:
>     - Added a couple of additional fixes at existing PM runtime code;
>     - Some patches are now more conservative in order to avoid causing
>      regressions.
> v3:
>     - fix a compilation error;
> v2:
>     - addressed pointed issues and fixed a few other PM issues.

This really doesn't say much more than "changed stuff" so kinda hard to
track if review feedback has been taken into account for example.

Johan

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-28 15:50   ` Johan Hovold
  0 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-04-28 15:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner, mauro.chehab,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Robert Foss, Sylwester Nawrocki,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Dan Scally, linux-samsung-soc, Dave Stevenson,
	Manivannan Sadhasivam, Chen-Yu Tsai, Krzysztof Kozlowski,
	Jonathan Hunter, linux-rockchip, Matt Ranostay, Andy Gross,
	Dongchun Zhu, Maxime Coquelin, Steve Longerbeam, Bingbu Cao,
	Marek Szyprowski, Shunqian Zheng, Tianshu Qiu, NXP Linux Team,
	Shawn Tu, devel, Jacopo Mondi, linux-tegra, Sakari Ailus,
	Wenyou Yang, Alexandre Torgue, linux-arm-msm, Sascha Hauer,
	linux-renesas-soc, Maxime Ripard, Stanimir Varbanov,
	Benoit Parrot, Helen Koike, Yong Zhi, linux-mediatek,
	Jacek Anaszewski, Matthias Brugger, Sylwester Nawrocki,
	Mauro Carvalho Chehab, Ezequiel Garcia, Daniele Alessandrelli,
	Chiranjeevi Rapolu, linux-arm-kernel, Jacob Chen, Jernej Skrabec,
	Philipp Zabel, Hyungwoo Yang, linux-kernel, Paul J. Murphy,
	Paul Kocialkowski, Sowjanya Komatineni, Pengutronix Kernel Team,
	linux-media, Shawn Guo

On Wed, Apr 28, 2021 at 04:51:21PM +0200, Mauro Carvalho Chehab wrote:
> 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.
> 
> After analyzing the feedback from version 1 of this series, I noticed
> a few other weird behaviors at the PM runtime resume code. So, this
> series start addressing some bugs and issues at the current code.
> Then, it gets rid of pm_runtime_get_sync() at the media subsystem
> (with 2 exceptions).
> 
> It should be noticed that
> 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.
> 
> The rationale of getting rid of pm_runtime_get_sync() is:
> 
> 1. despite its name, this is actually a PM runtime resume call,
>    but some developers didn't seem to realize that, as I got this
>    pattern on some drivers:
> 
>         pm_runtime_get_sync(&client->dev);
>         pm_runtime_disable(&client->dev);
>         pm_runtime_set_suspended(&client->dev);
>         pm_runtime_put_noidle(&client->dev);
> 
>    It makes no sense to resume PM just to suspend it again ;-)

This is perfectly alright. Take a look at ov7740_remove() for example:

	pm_runtime_get_sync(&client->dev);
	pm_runtime_disable(&client->dev);
	pm_runtime_set_suspended(&client->dev);
	pm_runtime_put_noidle(&client->dev);
	
	ov7740_set_power(ov7740, 0);

There's an explicit power-off after balancing the PM count and this will
work regardless of the power state when entering this function.

So this has nothing to do with pm_runtime_get_sync() per se.

> 2. Usual *_get() methods only increment their use count on success,
>    but pm_runtime_get_sync() increments it unconditionally. Due to
>    that, several drivers were mistakenly not calling
>    pm_runtime_put_noidle() when it fails;

Sure, but pm_runtime_get_async() also works this way. You just won't be
notified if the async resume fails.

> 3. The name of the new variant is a lot clearer:
> 	pm_runtime_resume_and_get()
>     As its same clearly says that this is a PM runtime resume function,
>     that also increments the usage counter on success;

It also introduced an inconsistency in the API and does not pair as well
with the pm_runtime_put variants.

> 4. Consistency: we did similar changes subsystem wide with
>    for instance strlcpy() and strcpy() that got replaced by
>    strscpy(). Having all drivers using the same known-to-be-safe
>    methods is a good thing;

It's not known to be safe; there are ways to get also this interface
wrong as for example this series has shown.

> 5. Prevent newer drivers to copy-and-paste a code that it would
>    be easier to break if they don't truly understand what's behind
>    the scenes.

Cargo-cult programming always runs that risk.

> This series replace places  pm_runtime_get_sync(), by calling
> 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.

The only valid point about and use for pm_runtime_resume_and_get() is to
avoid leaking a PM usage count reference in the unlikely case that
resume fails (something which hardly any driver implements recovery
from anyway).

It's a convenience wrapper that saves you from writing one extra line in
some cases (depending on how you implement runtime-pm support) and not a
silver bullet against bugs.
 
> compile-tested only.
> 
> Patches 1 to 7 fix some issues that already exists at the current
> PM runtime code;
> 
> patches 8 to 20 fix some usage_count problems that still exists
> at the media subsystem;
> 
> patches 21 to 78 repaces pm_runtime_get_sync() by 
> pm_runtime_resume_and_get();
> 
> Patch 79 (and a hunk on patch 78) documents the two exceptions
> where pm_runtime_get_sync() will still be used for now.
> 
> ---
> 
> v4:
>     - Added a couple of additional fixes at existing PM runtime code;
>     - Some patches are now more conservative in order to avoid causing
>      regressions.
> v3:
>     - fix a compilation error;
> v2:
>     - addressed pointed issues and fixed a few other PM issues.

This really doesn't say much more than "changed stuff" so kinda hard to
track if review feedback has been taken into account for example.

Johan
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-28 15:50   ` Johan Hovold
  0 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-04-28 15:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shawn Tu, Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Pengutronix Kernel Team,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Paul Kocialkowski, Mauro Carvalho Chehab, Dave Stevenson,
	Matt Ranostay, Krzysztof Kozlowski, Jonathan Hunter,
	linux-rockchip, Chen-Yu Tsai, Andy Gross, Matthias Brugger,
	Dongchun Zhu, Sakari Ailus, Bingbu Cao, Marek Szyprowski,
	Shunqian Zheng, Tianshu Qiu, NXP Linux Team, Philipp Zabel,
	devel, Jacopo Mondi, Sylwester Nawrocki, linux-tegra,
	Alexandre Torgue, Wenyou Yang, Manivannan Sadhasivam,
	linux-arm-msm, Sascha Hauer, Steve Longerbeam, linux-media,
	Maxime Ripard, Stanimir Varbanov, Benoit Parrot, Helen Koike,
	linux-samsung-soc, linux-mediatek, Jacek Anaszewski,
	mauro.chehab, Sylwester Nawrocki, Paul J. Murphy,
	Ezequiel Garcia, Daniele Alessandrelli, Chiranjeevi Rapolu,
	linux-arm-kernel, Jacob Chen, Jernej Skrabec, Hyungwoo Yang,
	linux-kernel, Robert Foss, Dan Scally, Sowjanya Komatineni,
	Maxime Coquelin, linux-renesas-soc, Yong Zhi, Shawn Guo

On Wed, Apr 28, 2021 at 04:51:21PM +0200, Mauro Carvalho Chehab wrote:
> 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.
> 
> After analyzing the feedback from version 1 of this series, I noticed
> a few other weird behaviors at the PM runtime resume code. So, this
> series start addressing some bugs and issues at the current code.
> Then, it gets rid of pm_runtime_get_sync() at the media subsystem
> (with 2 exceptions).
> 
> It should be noticed that
> 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.
> 
> The rationale of getting rid of pm_runtime_get_sync() is:
> 
> 1. despite its name, this is actually a PM runtime resume call,
>    but some developers didn't seem to realize that, as I got this
>    pattern on some drivers:
> 
>         pm_runtime_get_sync(&client->dev);
>         pm_runtime_disable(&client->dev);
>         pm_runtime_set_suspended(&client->dev);
>         pm_runtime_put_noidle(&client->dev);
> 
>    It makes no sense to resume PM just to suspend it again ;-)

This is perfectly alright. Take a look at ov7740_remove() for example:

	pm_runtime_get_sync(&client->dev);
	pm_runtime_disable(&client->dev);
	pm_runtime_set_suspended(&client->dev);
	pm_runtime_put_noidle(&client->dev);
	
	ov7740_set_power(ov7740, 0);

There's an explicit power-off after balancing the PM count and this will
work regardless of the power state when entering this function.

So this has nothing to do with pm_runtime_get_sync() per se.

> 2. Usual *_get() methods only increment their use count on success,
>    but pm_runtime_get_sync() increments it unconditionally. Due to
>    that, several drivers were mistakenly not calling
>    pm_runtime_put_noidle() when it fails;

Sure, but pm_runtime_get_async() also works this way. You just won't be
notified if the async resume fails.

> 3. The name of the new variant is a lot clearer:
> 	pm_runtime_resume_and_get()
>     As its same clearly says that this is a PM runtime resume function,
>     that also increments the usage counter on success;

It also introduced an inconsistency in the API and does not pair as well
with the pm_runtime_put variants.

> 4. Consistency: we did similar changes subsystem wide with
>    for instance strlcpy() and strcpy() that got replaced by
>    strscpy(). Having all drivers using the same known-to-be-safe
>    methods is a good thing;

It's not known to be safe; there are ways to get also this interface
wrong as for example this series has shown.

> 5. Prevent newer drivers to copy-and-paste a code that it would
>    be easier to break if they don't truly understand what's behind
>    the scenes.

Cargo-cult programming always runs that risk.

> This series replace places  pm_runtime_get_sync(), by calling
> 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.

The only valid point about and use for pm_runtime_resume_and_get() is to
avoid leaking a PM usage count reference in the unlikely case that
resume fails (something which hardly any driver implements recovery
from anyway).

It's a convenience wrapper that saves you from writing one extra line in
some cases (depending on how you implement runtime-pm support) and not a
silver bullet against bugs.
 
> compile-tested only.
> 
> Patches 1 to 7 fix some issues that already exists at the current
> PM runtime code;
> 
> patches 8 to 20 fix some usage_count problems that still exists
> at the media subsystem;
> 
> patches 21 to 78 repaces pm_runtime_get_sync() by 
> pm_runtime_resume_and_get();
> 
> Patch 79 (and a hunk on patch 78) documents the two exceptions
> where pm_runtime_get_sync() will still be used for now.
> 
> ---
> 
> v4:
>     - Added a couple of additional fixes at existing PM runtime code;
>     - Some patches are now more conservative in order to avoid causing
>      regressions.
> v3:
>     - fix a compilation error;
> v2:
>     - addressed pointed issues and fixed a few other PM issues.

This really doesn't say much more than "changed stuff" so kinda hard to
track if review feedback has been taken into account for example.

Johan

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get()
  2021-04-28 14:52   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 17:11     ` Ezequiel Garcia
  -1 siblings, 0 replies; 208+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Heiko Stuebner, Jacob Chen,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-kernel,
	linux-media, linux-rockchip

On Wed, 2021-04-28 at 16:52 +0200, 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>

Ugh, sigh... OK, there was a v4. Sorry for the noise!

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

> ---
>  drivers/media/platform/rockchip/rga/rga-buf.c | 3 +--
>  drivers/media/platform/rockchip/rga/rga.c     | 4 +++-
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/platform/rockchip/rga/rga-buf.c
> index bf9a75b75083..81508ed5abf3 100644
> --- a/drivers/media/platform/rockchip/rga/rga-buf.c
> +++ b/drivers/media/platform/rockchip/rga/rga-buf.c
> @@ -79,9 +79,8 @@ static int rga_buf_start_streaming(struct vb2_queue *q, unsigned int count)
>         struct rockchip_rga *rga = ctx->rga;
>         int ret;
>  
> -       ret = pm_runtime_get_sync(rga->dev);
> +       ret = pm_runtime_resume_and_get(rga->dev);
>         if (ret < 0) {
> -               pm_runtime_put_noidle(rga->dev);
>                 rga_buf_return_buffers(q, VB2_BUF_STATE_QUEUED);
>                 return ret;
>         }
> diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
> index 9d122429706e..bf3fd71ec3af 100644
> --- a/drivers/media/platform/rockchip/rga/rga.c
> +++ b/drivers/media/platform/rockchip/rga/rga.c
> @@ -866,7 +866,9 @@ static int rga_probe(struct platform_device *pdev)
>                 goto unreg_video_dev;
>         }
>  
> -       pm_runtime_get_sync(rga->dev);
> +       ret = pm_runtime_resume_and_get(rga->dev);
> +       if (ret < 0)
> +               goto unreg_video_dev;
>  
>         rga->version.major = (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF;
>         rga->version.minor = (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F;



^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get()
@ 2021-04-28 17:11     ` Ezequiel Garcia
  0 siblings, 0 replies; 208+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Heiko Stuebner, Jacob Chen,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-kernel,
	linux-media, linux-rockchip

On Wed, 2021-04-28 at 16:52 +0200, 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>

Ugh, sigh... OK, there was a v4. Sorry for the noise!

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

> ---
>  drivers/media/platform/rockchip/rga/rga-buf.c | 3 +--
>  drivers/media/platform/rockchip/rga/rga.c     | 4 +++-
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/platform/rockchip/rga/rga-buf.c
> index bf9a75b75083..81508ed5abf3 100644
> --- a/drivers/media/platform/rockchip/rga/rga-buf.c
> +++ b/drivers/media/platform/rockchip/rga/rga-buf.c
> @@ -79,9 +79,8 @@ static int rga_buf_start_streaming(struct vb2_queue *q, unsigned int count)
>         struct rockchip_rga *rga = ctx->rga;
>         int ret;
>  
> -       ret = pm_runtime_get_sync(rga->dev);
> +       ret = pm_runtime_resume_and_get(rga->dev);
>         if (ret < 0) {
> -               pm_runtime_put_noidle(rga->dev);
>                 rga_buf_return_buffers(q, VB2_BUF_STATE_QUEUED);
>                 return ret;
>         }
> diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
> index 9d122429706e..bf3fd71ec3af 100644
> --- a/drivers/media/platform/rockchip/rga/rga.c
> +++ b/drivers/media/platform/rockchip/rga/rga.c
> @@ -866,7 +866,9 @@ static int rga_probe(struct platform_device *pdev)
>                 goto unreg_video_dev;
>         }
>  
> -       pm_runtime_get_sync(rga->dev);
> +       ret = pm_runtime_resume_and_get(rga->dev);
> +       if (ret < 0)
> +               goto unreg_video_dev;
>  
>         rga->version.major = (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF;
>         rga->version.minor = (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F;



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get()
@ 2021-04-28 17:11     ` Ezequiel Garcia
  0 siblings, 0 replies; 208+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Heiko Stuebner, Jacob Chen,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-kernel,
	linux-media, linux-rockchip

On Wed, 2021-04-28 at 16:52 +0200, 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>

Ugh, sigh... OK, there was a v4. Sorry for the noise!

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

> ---
>  drivers/media/platform/rockchip/rga/rga-buf.c | 3 +--
>  drivers/media/platform/rockchip/rga/rga.c     | 4 +++-
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/platform/rockchip/rga/rga-buf.c
> index bf9a75b75083..81508ed5abf3 100644
> --- a/drivers/media/platform/rockchip/rga/rga-buf.c
> +++ b/drivers/media/platform/rockchip/rga/rga-buf.c
> @@ -79,9 +79,8 @@ static int rga_buf_start_streaming(struct vb2_queue *q, unsigned int count)
>         struct rockchip_rga *rga = ctx->rga;
>         int ret;
>  
> -       ret = pm_runtime_get_sync(rga->dev);
> +       ret = pm_runtime_resume_and_get(rga->dev);
>         if (ret < 0) {
> -               pm_runtime_put_noidle(rga->dev);
>                 rga_buf_return_buffers(q, VB2_BUF_STATE_QUEUED);
>                 return ret;
>         }
> diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
> index 9d122429706e..bf3fd71ec3af 100644
> --- a/drivers/media/platform/rockchip/rga/rga.c
> +++ b/drivers/media/platform/rockchip/rga/rga.c
> @@ -866,7 +866,9 @@ static int rga_probe(struct platform_device *pdev)
>                 goto unreg_video_dev;
>         }
>  
> -       pm_runtime_get_sync(rga->dev);
> +       ret = pm_runtime_resume_and_get(rga->dev);
> +       if (ret < 0)
> +               goto unreg_video_dev;
>  
>         rga->version.major = (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF;
>         rga->version.minor = (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F;



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
  2021-04-28 14:52   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 17:14     ` Ezequiel Garcia
  -1 siblings, 0 replies; 208+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:14 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Philipp Zabel, devel, linux-kernel,
	linux-media, linux-rockchip

On Wed, 2021-04-28 at 16:52 +0200, 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.
> 
> While there's nothing wrong with the current usage on this driver,
> as we're getting rid of the pm_runtime_get_sync() call all over
> the media subsystem, let's remove the last occurrence on this
> driver.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Looks good.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

Thanks,
Ezequiel

> ---
>  drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 595e82a82728..25fa36e7e773 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
>         return hantro_get_dec_buf_addr(ctx, buf);
>  }
>  
> -static void hantro_job_finish(struct hantro_dev *vpu,
> -                             struct hantro_ctx *ctx,
> -                             enum vb2_buffer_state result)
> +static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
> +                                   struct hantro_ctx *ctx,
> +                                   enum vb2_buffer_state result)
>  {
>         struct vb2_v4l2_buffer *src, *dst;
>  
> -       pm_runtime_mark_last_busy(vpu->dev);
> -       pm_runtime_put_autosuspend(vpu->dev);
>         clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
>  
>         src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
>                                          result);
>  }
>  
> +static void hantro_job_finish(struct hantro_dev *vpu,
> +                             struct hantro_ctx *ctx,
> +                             enum vb2_buffer_state result)
> +{
> +       pm_runtime_mark_last_busy(vpu->dev);
> +       pm_runtime_put_autosuspend(vpu->dev);
> +
> +       hantro_job_finish_no_pm(vpu, ctx, result);
> +}
> +
>  void hantro_irq_done(struct hantro_dev *vpu,
>                      enum vb2_buffer_state result)
>  {
> @@ -155,7 +163,8 @@ static void device_run(void *priv)
>         ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
>         if (ret)
>                 goto err_cancel_job;
> -       ret = pm_runtime_get_sync(ctx->dev->dev);
> +
> +       ret = pm_runtime_resume_and_get(ctx->dev->dev);
>         if (ret < 0)
>                 goto err_cancel_job;
>  
> @@ -165,7 +174,7 @@ static void device_run(void *priv)
>         return;
>  
>  err_cancel_job:
> -       hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> +       hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
>  }
>  
>  static struct v4l2_m2m_ops vpu_m2m_ops = {



^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
@ 2021-04-28 17:14     ` Ezequiel Garcia
  0 siblings, 0 replies; 208+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:14 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, Philipp Zabel, mauro.chehab,
	Mauro Carvalho Chehab, linux-media

On Wed, 2021-04-28 at 16:52 +0200, 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.
> 
> While there's nothing wrong with the current usage on this driver,
> as we're getting rid of the pm_runtime_get_sync() call all over
> the media subsystem, let's remove the last occurrence on this
> driver.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Looks good.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

Thanks,
Ezequiel

> ---
>  drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 595e82a82728..25fa36e7e773 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
>         return hantro_get_dec_buf_addr(ctx, buf);
>  }
>  
> -static void hantro_job_finish(struct hantro_dev *vpu,
> -                             struct hantro_ctx *ctx,
> -                             enum vb2_buffer_state result)
> +static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
> +                                   struct hantro_ctx *ctx,
> +                                   enum vb2_buffer_state result)
>  {
>         struct vb2_v4l2_buffer *src, *dst;
>  
> -       pm_runtime_mark_last_busy(vpu->dev);
> -       pm_runtime_put_autosuspend(vpu->dev);
>         clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
>  
>         src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
>                                          result);
>  }
>  
> +static void hantro_job_finish(struct hantro_dev *vpu,
> +                             struct hantro_ctx *ctx,
> +                             enum vb2_buffer_state result)
> +{
> +       pm_runtime_mark_last_busy(vpu->dev);
> +       pm_runtime_put_autosuspend(vpu->dev);
> +
> +       hantro_job_finish_no_pm(vpu, ctx, result);
> +}
> +
>  void hantro_irq_done(struct hantro_dev *vpu,
>                      enum vb2_buffer_state result)
>  {
> @@ -155,7 +163,8 @@ static void device_run(void *priv)
>         ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
>         if (ret)
>                 goto err_cancel_job;
> -       ret = pm_runtime_get_sync(ctx->dev->dev);
> +
> +       ret = pm_runtime_resume_and_get(ctx->dev->dev);
>         if (ret < 0)
>                 goto err_cancel_job;
>  
> @@ -165,7 +174,7 @@ static void device_run(void *priv)
>         return;
>  
>  err_cancel_job:
> -       hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> +       hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
>  }
>  
>  static struct v4l2_m2m_ops vpu_m2m_ops = {


_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
@ 2021-04-28 17:14     ` Ezequiel Garcia
  0 siblings, 0 replies; 208+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:14 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Philipp Zabel, devel, linux-kernel,
	linux-media, linux-rockchip

On Wed, 2021-04-28 at 16:52 +0200, 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.
> 
> While there's nothing wrong with the current usage on this driver,
> as we're getting rid of the pm_runtime_get_sync() call all over
> the media subsystem, let's remove the last occurrence on this
> driver.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Looks good.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

Thanks,
Ezequiel

> ---
>  drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 595e82a82728..25fa36e7e773 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
>         return hantro_get_dec_buf_addr(ctx, buf);
>  }
>  
> -static void hantro_job_finish(struct hantro_dev *vpu,
> -                             struct hantro_ctx *ctx,
> -                             enum vb2_buffer_state result)
> +static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
> +                                   struct hantro_ctx *ctx,
> +                                   enum vb2_buffer_state result)
>  {
>         struct vb2_v4l2_buffer *src, *dst;
>  
> -       pm_runtime_mark_last_busy(vpu->dev);
> -       pm_runtime_put_autosuspend(vpu->dev);
>         clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
>  
>         src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
>                                          result);
>  }
>  
> +static void hantro_job_finish(struct hantro_dev *vpu,
> +                             struct hantro_ctx *ctx,
> +                             enum vb2_buffer_state result)
> +{
> +       pm_runtime_mark_last_busy(vpu->dev);
> +       pm_runtime_put_autosuspend(vpu->dev);
> +
> +       hantro_job_finish_no_pm(vpu, ctx, result);
> +}
> +
>  void hantro_irq_done(struct hantro_dev *vpu,
>                      enum vb2_buffer_state result)
>  {
> @@ -155,7 +163,8 @@ static void device_run(void *priv)
>         ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
>         if (ret)
>                 goto err_cancel_job;
> -       ret = pm_runtime_get_sync(ctx->dev->dev);
> +
> +       ret = pm_runtime_resume_and_get(ctx->dev->dev);
>         if (ret < 0)
>                 goto err_cancel_job;
>  
> @@ -165,7 +174,7 @@ static void device_run(void *priv)
>         return;
>  
>  err_cancel_job:
> -       hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> +       hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
>  }
>  
>  static struct v4l2_m2m_ops vpu_m2m_ops = {



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 79/79] media: hantro: do a PM resume earlier
  2021-04-28 14:52   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 17:17     ` Ezequiel Garcia
  -1 siblings, 0 replies; 208+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:17 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Philipp Zabel, devel, linux-kernel,
	linux-media, linux-rockchip

Hi Mauro,

Thanks a lot for taking care of this.

On Wed, 2021-04-28 at 16:52 +0200, Mauro Carvalho Chehab wrote:
> The device_run() first enables the clock and then
> tries to resume PM runtime, checking for errors.
> 
> Well, if for some reason the pm_runtime can not resume,
> it would be better to detect it beforehand.
> 
> So, change the order inside device_run().
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Clocks could be behind power-domains, IIRC, so this change
is fixing that.

However, this has ever been a problem for this driver,
so I don't think it makes sense to bother with Fixes tag.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

Thanks,
Ezequiel

> ---
>  drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 25fa36e7e773..67de6b15236d 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -160,14 +160,14 @@ static void device_run(void *priv)
>         src = hantro_get_src_buf(ctx);
>         dst = hantro_get_dst_buf(ctx);
>  
> -       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> -       if (ret)
> -               goto err_cancel_job;
> -
>         ret = pm_runtime_resume_and_get(ctx->dev->dev);
>         if (ret < 0)
>                 goto err_cancel_job;
>  
> +       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> +       if (ret)
> +               goto err_cancel_job;
> +
>         v4l2_m2m_buf_copy_metadata(src, dst, true);
>  
>         ctx->codec_ops->run(ctx);



^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 79/79] media: hantro: do a PM resume earlier
@ 2021-04-28 17:17     ` Ezequiel Garcia
  0 siblings, 0 replies; 208+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:17 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, Philipp Zabel, mauro.chehab,
	Mauro Carvalho Chehab, linux-media

Hi Mauro,

Thanks a lot for taking care of this.

On Wed, 2021-04-28 at 16:52 +0200, Mauro Carvalho Chehab wrote:
> The device_run() first enables the clock and then
> tries to resume PM runtime, checking for errors.
> 
> Well, if for some reason the pm_runtime can not resume,
> it would be better to detect it beforehand.
> 
> So, change the order inside device_run().
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Clocks could be behind power-domains, IIRC, so this change
is fixing that.

However, this has ever been a problem for this driver,
so I don't think it makes sense to bother with Fixes tag.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

Thanks,
Ezequiel

> ---
>  drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 25fa36e7e773..67de6b15236d 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -160,14 +160,14 @@ static void device_run(void *priv)
>         src = hantro_get_src_buf(ctx);
>         dst = hantro_get_dst_buf(ctx);
>  
> -       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> -       if (ret)
> -               goto err_cancel_job;
> -
>         ret = pm_runtime_resume_and_get(ctx->dev->dev);
>         if (ret < 0)
>                 goto err_cancel_job;
>  
> +       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> +       if (ret)
> +               goto err_cancel_job;
> +
>         v4l2_m2m_buf_copy_metadata(src, dst, true);
>  
>         ctx->codec_ops->run(ctx);


_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 79/79] media: hantro: do a PM resume earlier
@ 2021-04-28 17:17     ` Ezequiel Garcia
  0 siblings, 0 replies; 208+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:17 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Philipp Zabel, devel, linux-kernel,
	linux-media, linux-rockchip

Hi Mauro,

Thanks a lot for taking care of this.

On Wed, 2021-04-28 at 16:52 +0200, Mauro Carvalho Chehab wrote:
> The device_run() first enables the clock and then
> tries to resume PM runtime, checking for errors.
> 
> Well, if for some reason the pm_runtime can not resume,
> it would be better to detect it beforehand.
> 
> So, change the order inside device_run().
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Clocks could be behind power-domains, IIRC, so this change
is fixing that.

However, this has ever been a problem for this driver,
so I don't think it makes sense to bother with Fixes tag.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

Thanks,
Ezequiel

> ---
>  drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 25fa36e7e773..67de6b15236d 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -160,14 +160,14 @@ static void device_run(void *priv)
>         src = hantro_get_src_buf(ctx);
>         dst = hantro_get_dst_buf(ctx);
>  
> -       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> -       if (ret)
> -               goto err_cancel_job;
> -
>         ret = pm_runtime_resume_and_get(ctx->dev->dev);
>         if (ret < 0)
>                 goto err_cancel_job;
>  
> +       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> +       if (ret)
> +               goto err_cancel_job;
> +
>         v4l2_m2m_buf_copy_metadata(src, dst, true);
>  
>         ctx->codec_ops->run(ctx);



_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
  2021-04-28 14:51   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 19:44     ` kernel test robot
  -1 siblings, 0 replies; 208+ messages in thread
From: kernel test robot @ 2021-04-28 19:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: kbuild-all, linux-media, linuxarm, mauro.chehab,
	Mauro Carvalho Chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, linux-arm-kernel, linux-kernel,
	linux-samsung-soc

[-- Attachment #1: Type: text/plain, Size: 2819 bytes --]

Hi Mauro,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on rockchip/for-next tegra/for-next v5.12 next-20210428]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
base:   git://linuxtv.org/media_tree.git master
config: nds32-randconfig-r035-20210428 (attached as .config)
compiler: nds32le-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
        git checkout b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=nds32 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/media/platform/exynos-gsc/gsc-core.c: In function 'gsc_remove':
>> drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: error: 'dev' undeclared (first use in this function); did you mean 'pdev'?
    1220 |  if (!pm_runtime_status_suspended(dev))
         |                                   ^~~
         |                                   pdev
   drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: note: each undeclared identifier is reported only once for each function it appears in


vim +1220 drivers/media/platform/exynos-gsc/gsc-core.c

  1207	
  1208	static int gsc_remove(struct platform_device *pdev)
  1209	{
  1210		struct gsc_dev *gsc = platform_get_drvdata(pdev);
  1211		int i;
  1212	
  1213		gsc_unregister_m2m_device(gsc);
  1214		v4l2_device_unregister(&gsc->v4l2_dev);
  1215	
  1216		vb2_dma_contig_clear_max_seg_size(&pdev->dev);
  1217	
  1218		pm_runtime_disable(&pdev->dev);
  1219	
> 1220		if (!pm_runtime_status_suspended(dev))
  1221			for (i = 0; i < gsc->num_clocks; i++)
  1222				clk_disable_unprepare(gsc->clock[i]);
  1223	
  1224		pm_runtime_set_suspended(dev);
  1225	
  1226		dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
  1227		return 0;
  1228	}
  1229	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 37801 bytes --]

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
@ 2021-04-28 19:44     ` kernel test robot
  0 siblings, 0 replies; 208+ messages in thread
From: kernel test robot @ 2021-04-28 19:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: kbuild-all, linux-media, linuxarm, mauro.chehab,
	Mauro Carvalho Chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, linux-arm-kernel, linux-kernel,
	linux-samsung-soc

[-- Attachment #1: Type: text/plain, Size: 2819 bytes --]

Hi Mauro,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on rockchip/for-next tegra/for-next v5.12 next-20210428]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
base:   git://linuxtv.org/media_tree.git master
config: nds32-randconfig-r035-20210428 (attached as .config)
compiler: nds32le-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
        git checkout b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=nds32 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/media/platform/exynos-gsc/gsc-core.c: In function 'gsc_remove':
>> drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: error: 'dev' undeclared (first use in this function); did you mean 'pdev'?
    1220 |  if (!pm_runtime_status_suspended(dev))
         |                                   ^~~
         |                                   pdev
   drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: note: each undeclared identifier is reported only once for each function it appears in


vim +1220 drivers/media/platform/exynos-gsc/gsc-core.c

  1207	
  1208	static int gsc_remove(struct platform_device *pdev)
  1209	{
  1210		struct gsc_dev *gsc = platform_get_drvdata(pdev);
  1211		int i;
  1212	
  1213		gsc_unregister_m2m_device(gsc);
  1214		v4l2_device_unregister(&gsc->v4l2_dev);
  1215	
  1216		vb2_dma_contig_clear_max_seg_size(&pdev->dev);
  1217	
  1218		pm_runtime_disable(&pdev->dev);
  1219	
> 1220		if (!pm_runtime_status_suspended(dev))
  1221			for (i = 0; i < gsc->num_clocks; i++)
  1222				clk_disable_unprepare(gsc->clock[i]);
  1223	
  1224		pm_runtime_set_suspended(dev);
  1225	
  1226		dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
  1227		return 0;
  1228	}
  1229	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 37801 bytes --]

[-- Attachment #3: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
@ 2021-04-28 19:44     ` kernel test robot
  0 siblings, 0 replies; 208+ messages in thread
From: kernel test robot @ 2021-04-28 19:44 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2887 bytes --]

Hi Mauro,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on rockchip/for-next tegra/for-next v5.12 next-20210428]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
base:   git://linuxtv.org/media_tree.git master
config: nds32-randconfig-r035-20210428 (attached as .config)
compiler: nds32le-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
        git checkout b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=nds32 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/media/platform/exynos-gsc/gsc-core.c: In function 'gsc_remove':
>> drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: error: 'dev' undeclared (first use in this function); did you mean 'pdev'?
    1220 |  if (!pm_runtime_status_suspended(dev))
         |                                   ^~~
         |                                   pdev
   drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: note: each undeclared identifier is reported only once for each function it appears in


vim +1220 drivers/media/platform/exynos-gsc/gsc-core.c

  1207	
  1208	static int gsc_remove(struct platform_device *pdev)
  1209	{
  1210		struct gsc_dev *gsc = platform_get_drvdata(pdev);
  1211		int i;
  1212	
  1213		gsc_unregister_m2m_device(gsc);
  1214		v4l2_device_unregister(&gsc->v4l2_dev);
  1215	
  1216		vb2_dma_contig_clear_max_seg_size(&pdev->dev);
  1217	
  1218		pm_runtime_disable(&pdev->dev);
  1219	
> 1220		if (!pm_runtime_status_suspended(dev))
  1221			for (i = 0; i < gsc->num_clocks; i++)
  1222				clk_disable_unprepare(gsc->clock[i]);
  1223	
  1224		pm_runtime_set_suspended(dev);
  1225	
  1226		dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
  1227		return 0;
  1228	}
  1229	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 37801 bytes --]

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
  2021-04-28 14:51   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-28 19:56     ` kernel test robot
  -1 siblings, 0 replies; 208+ messages in thread
From: kernel test robot @ 2021-04-28 19:56 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: kbuild-all, linux-media, linuxarm, mauro.chehab,
	Mauro Carvalho Chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, linux-arm-kernel, linux-kernel,
	linux-samsung-soc

[-- Attachment #1: Type: text/plain, Size: 2802 bytes --]

Hi Mauro,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on rockchip/for-next tegra/for-next v5.12 next-20210428]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
base:   git://linuxtv.org/media_tree.git master
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
        git checkout b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/media/platform/exynos-gsc/gsc-core.c: In function 'gsc_remove':
>> drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: error: 'dev' undeclared (first use in this function); did you mean 'pdev'?
    1220 |  if (!pm_runtime_status_suspended(dev))
         |                                   ^~~
         |                                   pdev
   drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: note: each undeclared identifier is reported only once for each function it appears in


vim +1220 drivers/media/platform/exynos-gsc/gsc-core.c

  1207	
  1208	static int gsc_remove(struct platform_device *pdev)
  1209	{
  1210		struct gsc_dev *gsc = platform_get_drvdata(pdev);
  1211		int i;
  1212	
  1213		gsc_unregister_m2m_device(gsc);
  1214		v4l2_device_unregister(&gsc->v4l2_dev);
  1215	
  1216		vb2_dma_contig_clear_max_seg_size(&pdev->dev);
  1217	
  1218		pm_runtime_disable(&pdev->dev);
  1219	
> 1220		if (!pm_runtime_status_suspended(dev))
  1221			for (i = 0; i < gsc->num_clocks; i++)
  1222				clk_disable_unprepare(gsc->clock[i]);
  1223	
  1224		pm_runtime_set_suspended(dev);
  1225	
  1226		dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
  1227		return 0;
  1228	}
  1229	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 63872 bytes --]

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
@ 2021-04-28 19:56     ` kernel test robot
  0 siblings, 0 replies; 208+ messages in thread
From: kernel test robot @ 2021-04-28 19:56 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: kbuild-all, linux-media, linuxarm, mauro.chehab,
	Mauro Carvalho Chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, linux-arm-kernel, linux-kernel,
	linux-samsung-soc

[-- Attachment #1: Type: text/plain, Size: 2802 bytes --]

Hi Mauro,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on rockchip/for-next tegra/for-next v5.12 next-20210428]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
base:   git://linuxtv.org/media_tree.git master
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
        git checkout b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/media/platform/exynos-gsc/gsc-core.c: In function 'gsc_remove':
>> drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: error: 'dev' undeclared (first use in this function); did you mean 'pdev'?
    1220 |  if (!pm_runtime_status_suspended(dev))
         |                                   ^~~
         |                                   pdev
   drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: note: each undeclared identifier is reported only once for each function it appears in


vim +1220 drivers/media/platform/exynos-gsc/gsc-core.c

  1207	
  1208	static int gsc_remove(struct platform_device *pdev)
  1209	{
  1210		struct gsc_dev *gsc = platform_get_drvdata(pdev);
  1211		int i;
  1212	
  1213		gsc_unregister_m2m_device(gsc);
  1214		v4l2_device_unregister(&gsc->v4l2_dev);
  1215	
  1216		vb2_dma_contig_clear_max_seg_size(&pdev->dev);
  1217	
  1218		pm_runtime_disable(&pdev->dev);
  1219	
> 1220		if (!pm_runtime_status_suspended(dev))
  1221			for (i = 0; i < gsc->num_clocks; i++)
  1222				clk_disable_unprepare(gsc->clock[i]);
  1223	
  1224		pm_runtime_set_suspended(dev);
  1225	
  1226		dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
  1227		return 0;
  1228	}
  1229	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 63872 bytes --]

[-- Attachment #3: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time
@ 2021-04-28 19:56     ` kernel test robot
  0 siblings, 0 replies; 208+ messages in thread
From: kernel test robot @ 2021-04-28 19:56 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2870 bytes --]

Hi Mauro,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on rockchip/for-next tegra/for-next v5.12 next-20210428]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
base:   git://linuxtv.org/media_tree.git master
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mauro-Carvalho-Chehab/Address-some-issues-with-PM-runtime-at-media-subsystem/20210428-225742
        git checkout b6dba4aea621c15b0aa6f92e548c74cd6994eb20
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/media/platform/exynos-gsc/gsc-core.c: In function 'gsc_remove':
>> drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: error: 'dev' undeclared (first use in this function); did you mean 'pdev'?
    1220 |  if (!pm_runtime_status_suspended(dev))
         |                                   ^~~
         |                                   pdev
   drivers/media/platform/exynos-gsc/gsc-core.c:1220:35: note: each undeclared identifier is reported only once for each function it appears in


vim +1220 drivers/media/platform/exynos-gsc/gsc-core.c

  1207	
  1208	static int gsc_remove(struct platform_device *pdev)
  1209	{
  1210		struct gsc_dev *gsc = platform_get_drvdata(pdev);
  1211		int i;
  1212	
  1213		gsc_unregister_m2m_device(gsc);
  1214		v4l2_device_unregister(&gsc->v4l2_dev);
  1215	
  1216		vb2_dma_contig_clear_max_seg_size(&pdev->dev);
  1217	
  1218		pm_runtime_disable(&pdev->dev);
  1219	
> 1220		if (!pm_runtime_status_suspended(dev))
  1221			for (i = 0; i < gsc->num_clocks; i++)
  1222				clk_disable_unprepare(gsc->clock[i]);
  1223	
  1224		pm_runtime_set_suspended(dev);
  1225	
  1226		dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
  1227		return 0;
  1228	}
  1229	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 63872 bytes --]

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 79/79] media: hantro: do a PM resume earlier
  2021-04-28 17:17     ` Ezequiel Garcia
  (?)
@ 2021-04-29  7:13       ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29  7:13 UTC (permalink / raw)
  To: Ezequiel Garcia
  Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Philipp Zabel, devel, linux-kernel,
	linux-media, linux-rockchip

Em Wed, 28 Apr 2021 14:17:50 -0300
Ezequiel Garcia <ezequiel@collabora.com> escreveu:

> Hi Mauro,
> 
> Thanks a lot for taking care of this.
> 
> On Wed, 2021-04-28 at 16:52 +0200, Mauro Carvalho Chehab wrote:
> > The device_run() first enables the clock and then
> > tries to resume PM runtime, checking for errors.
> > 
> > Well, if for some reason the pm_runtime can not resume,
> > it would be better to detect it beforehand.
> > 
> > So, change the order inside device_run().
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>  
> 
> Clocks could be behind power-domains, IIRC, so this change
> is fixing that.
> 
> However, this has ever been a problem for this driver,
> so I don't think it makes sense to bother with Fixes tag.

I would prefer to move this patch to the first part of this
series, together with other fixes, rebasing it to apply cleanly
before the pm_runtime_resume_and_get() patch, with:

    Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")

This way, people that could be interested on backporting it will be
capable to apply it as is to stable Kernel releases that came
with this driver.

> 
> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> 
> Thanks,
> Ezequiel
> 
> > ---
> >  drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> > index 25fa36e7e773..67de6b15236d 100644
> > --- a/drivers/staging/media/hantro/hantro_drv.c
> > +++ b/drivers/staging/media/hantro/hantro_drv.c
> > @@ -160,14 +160,14 @@ static void device_run(void *priv)
> >         src = hantro_get_src_buf(ctx);
> >         dst = hantro_get_dst_buf(ctx);
> >  
> > -       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> > -       if (ret)
> > -               goto err_cancel_job;
> > -
> >         ret = pm_runtime_resume_and_get(ctx->dev->dev);
> >         if (ret < 0)
> >                 goto err_cancel_job;
> >  
> > +       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> > +       if (ret)
> > +               goto err_cancel_job;
> > +
> >         v4l2_m2m_buf_copy_metadata(src, dst, true);
> >  
> >         ctx->codec_ops->run(ctx);  
> 
> 



Thanks,
Mauro

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 79/79] media: hantro: do a PM resume earlier
@ 2021-04-29  7:13       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29  7:13 UTC (permalink / raw)
  To: Ezequiel Garcia
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, Philipp Zabel, mauro.chehab,
	Mauro Carvalho Chehab, linux-media

Em Wed, 28 Apr 2021 14:17:50 -0300
Ezequiel Garcia <ezequiel@collabora.com> escreveu:

> Hi Mauro,
> 
> Thanks a lot for taking care of this.
> 
> On Wed, 2021-04-28 at 16:52 +0200, Mauro Carvalho Chehab wrote:
> > The device_run() first enables the clock and then
> > tries to resume PM runtime, checking for errors.
> > 
> > Well, if for some reason the pm_runtime can not resume,
> > it would be better to detect it beforehand.
> > 
> > So, change the order inside device_run().
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>  
> 
> Clocks could be behind power-domains, IIRC, so this change
> is fixing that.
> 
> However, this has ever been a problem for this driver,
> so I don't think it makes sense to bother with Fixes tag.

I would prefer to move this patch to the first part of this
series, together with other fixes, rebasing it to apply cleanly
before the pm_runtime_resume_and_get() patch, with:

    Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")

This way, people that could be interested on backporting it will be
capable to apply it as is to stable Kernel releases that came
with this driver.

> 
> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> 
> Thanks,
> Ezequiel
> 
> > ---
> >  drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> > index 25fa36e7e773..67de6b15236d 100644
> > --- a/drivers/staging/media/hantro/hantro_drv.c
> > +++ b/drivers/staging/media/hantro/hantro_drv.c
> > @@ -160,14 +160,14 @@ static void device_run(void *priv)
> >         src = hantro_get_src_buf(ctx);
> >         dst = hantro_get_dst_buf(ctx);
> >  
> > -       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> > -       if (ret)
> > -               goto err_cancel_job;
> > -
> >         ret = pm_runtime_resume_and_get(ctx->dev->dev);
> >         if (ret < 0)
> >                 goto err_cancel_job;
> >  
> > +       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> > +       if (ret)
> > +               goto err_cancel_job;
> > +
> >         v4l2_m2m_buf_copy_metadata(src, dst, true);
> >  
> >         ctx->codec_ops->run(ctx);  
> 
> 



Thanks,
Mauro
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 79/79] media: hantro: do a PM resume earlier
@ 2021-04-29  7:13       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29  7:13 UTC (permalink / raw)
  To: Ezequiel Garcia
  Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Philipp Zabel, devel, linux-kernel,
	linux-media, linux-rockchip

Em Wed, 28 Apr 2021 14:17:50 -0300
Ezequiel Garcia <ezequiel@collabora.com> escreveu:

> Hi Mauro,
> 
> Thanks a lot for taking care of this.
> 
> On Wed, 2021-04-28 at 16:52 +0200, Mauro Carvalho Chehab wrote:
> > The device_run() first enables the clock and then
> > tries to resume PM runtime, checking for errors.
> > 
> > Well, if for some reason the pm_runtime can not resume,
> > it would be better to detect it beforehand.
> > 
> > So, change the order inside device_run().
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>  
> 
> Clocks could be behind power-domains, IIRC, so this change
> is fixing that.
> 
> However, this has ever been a problem for this driver,
> so I don't think it makes sense to bother with Fixes tag.

I would prefer to move this patch to the first part of this
series, together with other fixes, rebasing it to apply cleanly
before the pm_runtime_resume_and_get() patch, with:

    Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")

This way, people that could be interested on backporting it will be
capable to apply it as is to stable Kernel releases that came
with this driver.

> 
> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> 
> Thanks,
> Ezequiel
> 
> > ---
> >  drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> > index 25fa36e7e773..67de6b15236d 100644
> > --- a/drivers/staging/media/hantro/hantro_drv.c
> > +++ b/drivers/staging/media/hantro/hantro_drv.c
> > @@ -160,14 +160,14 @@ static void device_run(void *priv)
> >         src = hantro_get_src_buf(ctx);
> >         dst = hantro_get_dst_buf(ctx);
> >  
> > -       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> > -       if (ret)
> > -               goto err_cancel_job;
> > -
> >         ret = pm_runtime_resume_and_get(ctx->dev->dev);
> >         if (ret < 0)
> >                 goto err_cancel_job;
> >  
> > +       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> > +       if (ret)
> > +               goto err_cancel_job;
> > +
> >         v4l2_m2m_buf_copy_metadata(src, dst, true);
> >  
> >         ctx->codec_ops->run(ctx);  
> 
> 



Thanks,
Mauro

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
  2021-04-28 15:09     ` Johan Hovold
  (?)
@ 2021-04-29  7:38       ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29  7:38 UTC (permalink / raw)
  To: Johan Hovold
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, mauro.chehab, Mauro Carvalho Chehab,
	Ezequiel Garcia, linux-media

Em Wed, 28 Apr 2021 17:09:57 +0200
Johan Hovold <johan@kernel.org> escreveu:

> On Wed, Apr 28, 2021 at 04:51:41PM +0200, Mauro Carvalho Chehab 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.  
> 
> Again, there is no memory leak here either. Just a potential PM usage
> counter leak.

True. Will fix it at the entire series with:

	FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f --msg-filter "cat|perl -0pe 's/ and avoid memory\n\s*leaks./, avoiding\na potential PM usage counter leak./igs'" BASE..

Regards,
Mauro

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
@ 2021-04-29  7:38       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29  7:38 UTC (permalink / raw)
  To: Johan Hovold
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, mauro.chehab, Mauro Carvalho Chehab,
	Ezequiel Garcia, linux-media

Em Wed, 28 Apr 2021 17:09:57 +0200
Johan Hovold <johan@kernel.org> escreveu:

> On Wed, Apr 28, 2021 at 04:51:41PM +0200, Mauro Carvalho Chehab 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.  
> 
> Again, there is no memory leak here either. Just a potential PM usage
> counter leak.

True. Will fix it at the entire series with:

	FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f --msg-filter "cat|perl -0pe 's/ and avoid memory\n\s*leaks./, avoiding\na potential PM usage counter leak./igs'" BASE..

Regards,
Mauro
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
@ 2021-04-29  7:38       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29  7:38 UTC (permalink / raw)
  To: Johan Hovold
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, mauro.chehab, Mauro Carvalho Chehab,
	Ezequiel Garcia, linux-media

Em Wed, 28 Apr 2021 17:09:57 +0200
Johan Hovold <johan@kernel.org> escreveu:

> On Wed, Apr 28, 2021 at 04:51:41PM +0200, Mauro Carvalho Chehab 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.  
> 
> Again, there is no memory leak here either. Just a potential PM usage
> counter leak.

True. Will fix it at the entire series with:

	FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f --msg-filter "cat|perl -0pe 's/ and avoid memory\n\s*leaks./, avoiding\na potential PM usage counter leak./igs'" BASE..

Regards,
Mauro

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
  2021-04-28 15:50   ` Johan Hovold
  (?)
@ 2021-04-29 10:18     ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29 10:18 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Shawn Tu, Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Pengutronix Kernel Team,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Paul Kocialkowski, Mauro Carvalho Chehab, Dave Stevenson,
	Matt Ranostay, Krzysztof Kozlowski, Jonathan Hunter,
	linux-rockchip, Chen-Yu Tsai, Andy Gross, Matthias Brugger,
	Dongchun Zhu, Sakari Ailus, Bingbu Cao, Marek Szyprowski,
	Shunqian Zheng, Tianshu Qiu, NXP Linux Team, Philipp Zabel,
	devel, Jacopo Mondi, Sylwester Nawrocki, linux-tegra,
	Alexandre Torgue, Wenyou Yang, Manivannan Sadhasivam,
	linux-arm-msm, Sascha Hauer, Steve Longerbeam, linux-media,
	Maxime Ripard, Stanimir Varbanov, Benoit Parrot, Helen Koike,
	linux-samsung-soc, linux-mediatek, Jacek Anaszewski,
	mauro.chehab, Sylwester Nawrocki, Paul J. Murphy,
	Ezequiel Garcia, Daniele Alessandrelli, Chiranjeevi Rapolu,
	linux-arm-kernel, Jacob Chen, Jernej Skrabec, Hyungwoo Yang,
	linux-kernel, Robert Foss, Dan Scally, Sowjanya Komatineni,
	Maxime Coquelin, linux-renesas-soc, Yong Zhi, Shawn Guo

Em Wed, 28 Apr 2021 17:50:08 +0200
Johan Hovold <johan@kernel.org> escreveu:

> On Wed, Apr 28, 2021 at 04:51:21PM +0200, Mauro Carvalho Chehab wrote:

> > 1. despite its name, this is actually a PM runtime resume call,
> >    but some developers didn't seem to realize that, as I got this
> >    pattern on some drivers:
> > 
> >         pm_runtime_get_sync(&client->dev);
> >         pm_runtime_disable(&client->dev);
> >         pm_runtime_set_suspended(&client->dev);
> >         pm_runtime_put_noidle(&client->dev);
> > 
> >    It makes no sense to resume PM just to suspend it again ;-)  
> 
> This is perfectly alright. Take a look at ov7740_remove() for example:
> 
> 	pm_runtime_get_sync(&client->dev);
> 	pm_runtime_disable(&client->dev);
> 	pm_runtime_set_suspended(&client->dev);
> 	pm_runtime_put_noidle(&client->dev);
> 	
> 	ov7740_set_power(ov7740, 0);
> 
> There's an explicit power-off after balancing the PM count and this will
> work regardless of the power state when entering this function.

Ok, but this should equally work:

 	pm_runtime_disable(&client->dev);
 	pm_runtime_set_suspended(&client->dev);
 	
 	ov7740_set_power(ov7740, 0);

as there's no additional cleanup made on this particular driver
between pm_runtime_get_sync() and pm_runtime_put_noidle().

> So this has nothing to do with pm_runtime_get_sync() per se.

Yes, but some patches on this series are cleaning up the driver release
logic.

> 
> > 2. Usual *_get() methods only increment their use count on success,
> >    but pm_runtime_get_sync() increments it unconditionally. Due to
> >    that, several drivers were mistakenly not calling
> >    pm_runtime_put_noidle() when it fails;  
> 
> Sure, but pm_runtime_get_async() also works this way. You just won't be
> notified if the async resume fails.

Granted, it makes sense along the pm_runtime kAPI.

It is inconsistent with the behavior of kobject_get*() and other
*_get*() methods that are based or inspired on it, as, on those, the
operations are atomic: either everything succeeds and it doesn't return
an error, or the usage counter is not incremented and the object
state doesn't change after the call.

> > 3. The name of the new variant is a lot clearer:
> > 	pm_runtime_resume_and_get()
> >     As its same clearly says that this is a PM runtime resume function,
> >     that also increments the usage counter on success;  
> 
> It also introduced an inconsistency in the API and does not pair as well
> with the pm_runtime_put variants.

Agreed. A name that would be more consistent with PM runtime would
probably be:

	pm_runtime_resume_if_get()

as there are already:

	pm_runtime_get_if_in_use()
	pm_runtime_get_if_active()

But any such discussions are out of the scope of this patchset ;-)

> 
> > 4. Consistency: we did similar changes subsystem wide with
> >    for instance strlcpy() and strcpy() that got replaced by
> >    strscpy(). Having all drivers using the same known-to-be-safe
> >    methods is a good thing;  
> 
> It's not known to be safe; there are ways to get also this interface
> wrong as for example this series has shown.

Very true. Yet, it is a lot simpler to use functions that won't change
the state of the objects when returning an error, as this is by far
the most common pattern within the Kernel.

Human brains are trained to identify certain patterns. When there's
something using a similar pattern, but with a different behavior, 
our brains are more subject to fail identifying problems.

> > 5. Prevent newer drivers to copy-and-paste a code that it would
> >    be easier to break if they don't truly understand what's behind
> >    the scenes.  
> 
> Cargo-cult programming always runs that risk.

True.

> > This series replace places  pm_runtime_get_sync(), by calling
> > 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.  
> 
> The only valid point about and use for pm_runtime_resume_and_get() is to
> avoid leaking a PM usage count reference in the unlikely case that
> resume fails (something which hardly any driver implements recovery
> from anyway).
> 
> It's a convenience wrapper that saves you from writing one extra line in
> some cases (depending on how you implement runtime-pm support) and not a
> silver bullet against bugs.
>  
> > compile-tested only.
> > 
> > Patches 1 to 7 fix some issues that already exists at the current
> > PM runtime code;
> > 
> > patches 8 to 20 fix some usage_count problems that still exists
> > at the media subsystem;
> > 
> > patches 21 to 78 repaces pm_runtime_get_sync() by 
> > pm_runtime_resume_and_get();
> > 
> > Patch 79 (and a hunk on patch 78) documents the two exceptions
> > where pm_runtime_get_sync() will still be used for now.
> > 
> > ---
> > 
> > v4:
> >     - Added a couple of additional fixes at existing PM runtime code;
> >     - Some patches are now more conservative in order to avoid causing
> >      regressions.
> > v3:
> >     - fix a compilation error;
> > v2:
> >     - addressed pointed issues and fixed a few other PM issues.  
> 
> This really doesn't say much more than "changed stuff" so kinda hard to
> track if review feedback has been taken into account for example.

I addressed all review feedback I got (as far as I'm aware), and added
all received reviewed-by/acked-by.

Yeah, I could have written a more comprehensive changes description
there.

Thanks,
Mauro

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-29 10:18     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29 10:18 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner, mauro.chehab,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Robert Foss, Sylwester Nawrocki,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Dan Scally, linux-samsung-soc, Dave Stevenson,
	Manivannan Sadhasivam, Chen-Yu Tsai, Krzysztof Kozlowski,
	Jonathan Hunter, linux-rockchip, Matt Ranostay, Andy Gross,
	Dongchun Zhu, Maxime Coquelin, Steve Longerbeam, Bingbu Cao,
	Marek Szyprowski, Shunqian Zheng, Tianshu Qiu, NXP Linux Team,
	Shawn Tu, devel, Jacopo Mondi, linux-tegra, Sakari Ailus,
	Wenyou Yang, Alexandre Torgue, linux-arm-msm, Sascha Hauer,
	linux-renesas-soc, Maxime Ripard, Stanimir Varbanov,
	Benoit Parrot, Helen Koike, Yong Zhi, linux-mediatek,
	Jacek Anaszewski, Matthias Brugger, Sylwester Nawrocki,
	Mauro Carvalho Chehab, Ezequiel Garcia, Daniele Alessandrelli,
	Chiranjeevi Rapolu, linux-arm-kernel, Jacob Chen, Jernej Skrabec,
	Philipp Zabel, Hyungwoo Yang, linux-kernel, Paul J. Murphy,
	Paul Kocialkowski, Sowjanya Komatineni, Pengutronix Kernel Team,
	linux-media, Shawn Guo

Em Wed, 28 Apr 2021 17:50:08 +0200
Johan Hovold <johan@kernel.org> escreveu:

> On Wed, Apr 28, 2021 at 04:51:21PM +0200, Mauro Carvalho Chehab wrote:

> > 1. despite its name, this is actually a PM runtime resume call,
> >    but some developers didn't seem to realize that, as I got this
> >    pattern on some drivers:
> > 
> >         pm_runtime_get_sync(&client->dev);
> >         pm_runtime_disable(&client->dev);
> >         pm_runtime_set_suspended(&client->dev);
> >         pm_runtime_put_noidle(&client->dev);
> > 
> >    It makes no sense to resume PM just to suspend it again ;-)  
> 
> This is perfectly alright. Take a look at ov7740_remove() for example:
> 
> 	pm_runtime_get_sync(&client->dev);
> 	pm_runtime_disable(&client->dev);
> 	pm_runtime_set_suspended(&client->dev);
> 	pm_runtime_put_noidle(&client->dev);
> 	
> 	ov7740_set_power(ov7740, 0);
> 
> There's an explicit power-off after balancing the PM count and this will
> work regardless of the power state when entering this function.

Ok, but this should equally work:

 	pm_runtime_disable(&client->dev);
 	pm_runtime_set_suspended(&client->dev);
 	
 	ov7740_set_power(ov7740, 0);

as there's no additional cleanup made on this particular driver
between pm_runtime_get_sync() and pm_runtime_put_noidle().

> So this has nothing to do with pm_runtime_get_sync() per se.

Yes, but some patches on this series are cleaning up the driver release
logic.

> 
> > 2. Usual *_get() methods only increment their use count on success,
> >    but pm_runtime_get_sync() increments it unconditionally. Due to
> >    that, several drivers were mistakenly not calling
> >    pm_runtime_put_noidle() when it fails;  
> 
> Sure, but pm_runtime_get_async() also works this way. You just won't be
> notified if the async resume fails.

Granted, it makes sense along the pm_runtime kAPI.

It is inconsistent with the behavior of kobject_get*() and other
*_get*() methods that are based or inspired on it, as, on those, the
operations are atomic: either everything succeeds and it doesn't return
an error, or the usage counter is not incremented and the object
state doesn't change after the call.

> > 3. The name of the new variant is a lot clearer:
> > 	pm_runtime_resume_and_get()
> >     As its same clearly says that this is a PM runtime resume function,
> >     that also increments the usage counter on success;  
> 
> It also introduced an inconsistency in the API and does not pair as well
> with the pm_runtime_put variants.

Agreed. A name that would be more consistent with PM runtime would
probably be:

	pm_runtime_resume_if_get()

as there are already:

	pm_runtime_get_if_in_use()
	pm_runtime_get_if_active()

But any such discussions are out of the scope of this patchset ;-)

> 
> > 4. Consistency: we did similar changes subsystem wide with
> >    for instance strlcpy() and strcpy() that got replaced by
> >    strscpy(). Having all drivers using the same known-to-be-safe
> >    methods is a good thing;  
> 
> It's not known to be safe; there are ways to get also this interface
> wrong as for example this series has shown.

Very true. Yet, it is a lot simpler to use functions that won't change
the state of the objects when returning an error, as this is by far
the most common pattern within the Kernel.

Human brains are trained to identify certain patterns. When there's
something using a similar pattern, but with a different behavior, 
our brains are more subject to fail identifying problems.

> > 5. Prevent newer drivers to copy-and-paste a code that it would
> >    be easier to break if they don't truly understand what's behind
> >    the scenes.  
> 
> Cargo-cult programming always runs that risk.

True.

> > This series replace places  pm_runtime_get_sync(), by calling
> > 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.  
> 
> The only valid point about and use for pm_runtime_resume_and_get() is to
> avoid leaking a PM usage count reference in the unlikely case that
> resume fails (something which hardly any driver implements recovery
> from anyway).
> 
> It's a convenience wrapper that saves you from writing one extra line in
> some cases (depending on how you implement runtime-pm support) and not a
> silver bullet against bugs.
>  
> > compile-tested only.
> > 
> > Patches 1 to 7 fix some issues that already exists at the current
> > PM runtime code;
> > 
> > patches 8 to 20 fix some usage_count problems that still exists
> > at the media subsystem;
> > 
> > patches 21 to 78 repaces pm_runtime_get_sync() by 
> > pm_runtime_resume_and_get();
> > 
> > Patch 79 (and a hunk on patch 78) documents the two exceptions
> > where pm_runtime_get_sync() will still be used for now.
> > 
> > ---
> > 
> > v4:
> >     - Added a couple of additional fixes at existing PM runtime code;
> >     - Some patches are now more conservative in order to avoid causing
> >      regressions.
> > v3:
> >     - fix a compilation error;
> > v2:
> >     - addressed pointed issues and fixed a few other PM issues.  
> 
> This really doesn't say much more than "changed stuff" so kinda hard to
> track if review feedback has been taken into account for example.

I addressed all review feedback I got (as far as I'm aware), and added
all received reviewed-by/acked-by.

Yeah, I could have written a more comprehensive changes description
there.

Thanks,
Mauro
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-29 10:18     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29 10:18 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Shawn Tu, Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Pengutronix Kernel Team,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Paul Kocialkowski, Mauro Carvalho Chehab, Dave Stevenson,
	Matt Ranostay, Krzysztof Kozlowski, Jonathan Hunter,
	linux-rockchip, Chen-Yu Tsai, Andy Gross, Matthias Brugger,
	Dongchun Zhu, Sakari Ailus, Bingbu Cao, Marek Szyprowski,
	Shunqian Zheng, Tianshu Qiu, NXP Linux Team, Philipp Zabel,
	devel, Jacopo Mondi, Sylwester Nawrocki, linux-tegra,
	Alexandre Torgue, Wenyou Yang, Manivannan Sadhasivam,
	linux-arm-msm, Sascha Hauer, Steve Longerbeam, linux-media,
	Maxime Ripard, Stanimir Varbanov, Benoit Parrot, Helen Koike,
	linux-samsung-soc, linux-mediatek, Jacek Anaszewski,
	mauro.chehab, Sylwester Nawrocki, Paul J. Murphy,
	Ezequiel Garcia, Daniele Alessandrelli, Chiranjeevi Rapolu,
	linux-arm-kernel, Jacob Chen, Jernej Skrabec, Hyungwoo Yang,
	linux-kernel, Robert Foss, Dan Scally, Sowjanya Komatineni,
	Maxime Coquelin, linux-renesas-soc, Yong Zhi, Shawn Guo

Em Wed, 28 Apr 2021 17:50:08 +0200
Johan Hovold <johan@kernel.org> escreveu:

> On Wed, Apr 28, 2021 at 04:51:21PM +0200, Mauro Carvalho Chehab wrote:

> > 1. despite its name, this is actually a PM runtime resume call,
> >    but some developers didn't seem to realize that, as I got this
> >    pattern on some drivers:
> > 
> >         pm_runtime_get_sync(&client->dev);
> >         pm_runtime_disable(&client->dev);
> >         pm_runtime_set_suspended(&client->dev);
> >         pm_runtime_put_noidle(&client->dev);
> > 
> >    It makes no sense to resume PM just to suspend it again ;-)  
> 
> This is perfectly alright. Take a look at ov7740_remove() for example:
> 
> 	pm_runtime_get_sync(&client->dev);
> 	pm_runtime_disable(&client->dev);
> 	pm_runtime_set_suspended(&client->dev);
> 	pm_runtime_put_noidle(&client->dev);
> 	
> 	ov7740_set_power(ov7740, 0);
> 
> There's an explicit power-off after balancing the PM count and this will
> work regardless of the power state when entering this function.

Ok, but this should equally work:

 	pm_runtime_disable(&client->dev);
 	pm_runtime_set_suspended(&client->dev);
 	
 	ov7740_set_power(ov7740, 0);

as there's no additional cleanup made on this particular driver
between pm_runtime_get_sync() and pm_runtime_put_noidle().

> So this has nothing to do with pm_runtime_get_sync() per se.

Yes, but some patches on this series are cleaning up the driver release
logic.

> 
> > 2. Usual *_get() methods only increment their use count on success,
> >    but pm_runtime_get_sync() increments it unconditionally. Due to
> >    that, several drivers were mistakenly not calling
> >    pm_runtime_put_noidle() when it fails;  
> 
> Sure, but pm_runtime_get_async() also works this way. You just won't be
> notified if the async resume fails.

Granted, it makes sense along the pm_runtime kAPI.

It is inconsistent with the behavior of kobject_get*() and other
*_get*() methods that are based or inspired on it, as, on those, the
operations are atomic: either everything succeeds and it doesn't return
an error, or the usage counter is not incremented and the object
state doesn't change after the call.

> > 3. The name of the new variant is a lot clearer:
> > 	pm_runtime_resume_and_get()
> >     As its same clearly says that this is a PM runtime resume function,
> >     that also increments the usage counter on success;  
> 
> It also introduced an inconsistency in the API and does not pair as well
> with the pm_runtime_put variants.

Agreed. A name that would be more consistent with PM runtime would
probably be:

	pm_runtime_resume_if_get()

as there are already:

	pm_runtime_get_if_in_use()
	pm_runtime_get_if_active()

But any such discussions are out of the scope of this patchset ;-)

> 
> > 4. Consistency: we did similar changes subsystem wide with
> >    for instance strlcpy() and strcpy() that got replaced by
> >    strscpy(). Having all drivers using the same known-to-be-safe
> >    methods is a good thing;  
> 
> It's not known to be safe; there are ways to get also this interface
> wrong as for example this series has shown.

Very true. Yet, it is a lot simpler to use functions that won't change
the state of the objects when returning an error, as this is by far
the most common pattern within the Kernel.

Human brains are trained to identify certain patterns. When there's
something using a similar pattern, but with a different behavior, 
our brains are more subject to fail identifying problems.

> > 5. Prevent newer drivers to copy-and-paste a code that it would
> >    be easier to break if they don't truly understand what's behind
> >    the scenes.  
> 
> Cargo-cult programming always runs that risk.

True.

> > This series replace places  pm_runtime_get_sync(), by calling
> > 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.  
> 
> The only valid point about and use for pm_runtime_resume_and_get() is to
> avoid leaking a PM usage count reference in the unlikely case that
> resume fails (something which hardly any driver implements recovery
> from anyway).
> 
> It's a convenience wrapper that saves you from writing one extra line in
> some cases (depending on how you implement runtime-pm support) and not a
> silver bullet against bugs.
>  
> > compile-tested only.
> > 
> > Patches 1 to 7 fix some issues that already exists at the current
> > PM runtime code;
> > 
> > patches 8 to 20 fix some usage_count problems that still exists
> > at the media subsystem;
> > 
> > patches 21 to 78 repaces pm_runtime_get_sync() by 
> > pm_runtime_resume_and_get();
> > 
> > Patch 79 (and a hunk on patch 78) documents the two exceptions
> > where pm_runtime_get_sync() will still be used for now.
> > 
> > ---
> > 
> > v4:
> >     - Added a couple of additional fixes at existing PM runtime code;
> >     - Some patches are now more conservative in order to avoid causing
> >      regressions.
> > v3:
> >     - fix a compilation error;
> > v2:
> >     - addressed pointed issues and fixed a few other PM issues.  
> 
> This really doesn't say much more than "changed stuff" so kinda hard to
> track if review feedback has been taken into account for example.

I addressed all review feedback I got (as far as I'm aware), and added
all received reviewed-by/acked-by.

Yeah, I could have written a more comprehensive changes description
there.

Thanks,
Mauro

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
  2021-04-29 10:18     ` Mauro Carvalho Chehab
  (?)
@ 2021-04-29 12:33       ` Dmitry Osipenko
  -1 siblings, 0 replies; 208+ messages in thread
From: Dmitry Osipenko @ 2021-04-29 12:33 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Johan Hovold
  Cc: Shawn Tu, Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Pengutronix Kernel Team, linux-stm32,
	Andrzej Pietrasiewicz, Leon Luo, Paul Kocialkowski,
	Mauro Carvalho Chehab, Dave Stevenson, Matt Ranostay,
	Krzysztof Kozlowski, Jonathan Hunter, linux-rockchip,
	Chen-Yu Tsai, Andy Gross, Matthias Brugger, Dongchun Zhu,
	Sakari Ailus, Bingbu Cao, Marek Szyprowski, Shunqian Zheng,
	Tianshu Qiu, NXP Linux Team, Philipp Zabel, devel, Jacopo Mondi,
	Sylwester Nawrocki, linux-tegra, Alexandre Torgue, Wenyou Yang,
	Manivannan Sadhasivam, linux-arm-msm, Sascha Hauer,
	Steve Longerbeam, linux-media, Maxime Ripard, Stanimir Varbanov,
	Benoit Parrot, Helen Koike, linux-samsung-soc, linux-mediatek,
	Jacek Anaszewski, mauro.chehab, Sylwester Nawrocki,
	Paul J. Murphy, Ezequiel Garcia, Daniele Alessandrelli,
	Chiranjeevi Rapolu, linux-arm-kernel, Jacob Chen, Jernej Skrabec,
	Hyungwoo Yang, linux-kernel, Robert Foss, Dan Scally,
	Sowjanya Komatineni, Maxime Coquelin, linux-renesas-soc,
	Yong Zhi, Shawn Guo

29.04.2021 13:18, Mauro Carvalho Chehab пишет:
>> This is perfectly alright. Take a look at ov7740_remove() for example:
>>
>> 	pm_runtime_get_sync(&client->dev);
>> 	pm_runtime_disable(&client->dev);
>> 	pm_runtime_set_suspended(&client->dev);
>> 	pm_runtime_put_noidle(&client->dev);
>> 	
>> 	ov7740_set_power(ov7740, 0);
>>
>> There's an explicit power-off after balancing the PM count and this will
>> work regardless of the power state when entering this function.
> Ok, but this should equally work:
> 
>  	pm_runtime_disable(&client->dev);
>  	pm_runtime_set_suspended(&client->dev);
>  	
>  	ov7740_set_power(ov7740, 0);
> 
> as there's no additional cleanup made on this particular driver
> between pm_runtime_get_sync() and pm_runtime_put_noidle().
> 

The pm_runtime_get_sync() turns hardware ON by invoking
ov7740_set_power(ov7740, 1), and thus, the ON->OFF is kept balanced in
both RPM-available and RPM-unavailable cases. The RPM state of device
should be reset after driver removal.

It doesn't look like any additional cleanups are needed by that ov7740
driver. The driver removal is opposite to the probe, hence it should be
correct as-is.

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-29 12:33       ` Dmitry Osipenko
  0 siblings, 0 replies; 208+ messages in thread
From: Dmitry Osipenko @ 2021-04-29 12:33 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Johan Hovold
  Cc: Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner, mauro.chehab,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Robert Foss, Sylwester Nawrocki,
	linux-stm32, Andrzej Pietrasiewicz, Leon Luo, Dan Scally,
	linux-samsung-soc, Dave Stevenson, Manivannan Sadhasivam,
	Chen-Yu Tsai, Krzysztof Kozlowski, Jonathan Hunter,
	linux-rockchip, Matt Ranostay, Andy Gross, Dongchun Zhu,
	Maxime Coquelin, Steve Longerbeam, Bingbu Cao, Marek Szyprowski,
	Shunqian Zheng, Tianshu Qiu, NXP Linux Team, Shawn Tu, devel,
	Jacopo Mondi, linux-tegra, Sakari Ailus, Wenyou Yang,
	Alexandre Torgue, linux-arm-msm, Sascha Hauer, linux-renesas-soc,
	Maxime Ripard, Stanimir Varbanov, Benoit Parrot, Helen Koike,
	Yong Zhi, linux-mediatek, Jacek Anaszewski, Matthias Brugger,
	Sylwester Nawrocki, Mauro Carvalho Chehab, Ezequiel Garcia,
	Daniele Alessandrelli, Chiranjeevi Rapolu, linux-arm-kernel,
	Jacob Chen, Jernej Skrabec, Philipp Zabel, Hyungwoo Yang,
	linux-kernel, Paul J. Murphy, Paul Kocialkowski,
	Sowjanya Komatineni, Pengutronix Kernel Team, linux-media,
	Shawn Guo

29.04.2021 13:18, Mauro Carvalho Chehab пишет:
>> This is perfectly alright. Take a look at ov7740_remove() for example:
>>
>> 	pm_runtime_get_sync(&client->dev);
>> 	pm_runtime_disable(&client->dev);
>> 	pm_runtime_set_suspended(&client->dev);
>> 	pm_runtime_put_noidle(&client->dev);
>> 	
>> 	ov7740_set_power(ov7740, 0);
>>
>> There's an explicit power-off after balancing the PM count and this will
>> work regardless of the power state when entering this function.
> Ok, but this should equally work:
> 
>  	pm_runtime_disable(&client->dev);
>  	pm_runtime_set_suspended(&client->dev);
>  	
>  	ov7740_set_power(ov7740, 0);
> 
> as there's no additional cleanup made on this particular driver
> between pm_runtime_get_sync() and pm_runtime_put_noidle().
> 

The pm_runtime_get_sync() turns hardware ON by invoking
ov7740_set_power(ov7740, 1), and thus, the ON->OFF is kept balanced in
both RPM-available and RPM-unavailable cases. The RPM state of device
should be reset after driver removal.

It doesn't look like any additional cleanups are needed by that ov7740
driver. The driver removal is opposite to the probe, hence it should be
correct as-is.
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-29 12:33       ` Dmitry Osipenko
  0 siblings, 0 replies; 208+ messages in thread
From: Dmitry Osipenko @ 2021-04-29 12:33 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Johan Hovold
  Cc: Shawn Tu, Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Pengutronix Kernel Team, linux-stm32,
	Andrzej Pietrasiewicz, Leon Luo, Paul Kocialkowski,
	Mauro Carvalho Chehab, Dave Stevenson, Matt Ranostay,
	Krzysztof Kozlowski, Jonathan Hunter, linux-rockchip,
	Chen-Yu Tsai, Andy Gross, Matthias Brugger, Dongchun Zhu,
	Sakari Ailus, Bingbu Cao, Marek Szyprowski, Shunqian Zheng,
	Tianshu Qiu, NXP Linux Team, Philipp Zabel, devel, Jacopo Mondi,
	Sylwester Nawrocki, linux-tegra, Alexandre Torgue, Wenyou Yang,
	Manivannan Sadhasivam, linux-arm-msm, Sascha Hauer,
	Steve Longerbeam, linux-media, Maxime Ripard, Stanimir Varbanov,
	Benoit Parrot, Helen Koike, linux-samsung-soc, linux-mediatek,
	Jacek Anaszewski, mauro.chehab, Sylwester Nawrocki,
	Paul J. Murphy, Ezequiel Garcia, Daniele Alessandrelli,
	Chiranjeevi Rapolu, linux-arm-kernel, Jacob Chen, Jernej Skrabec,
	Hyungwoo Yang, linux-kernel, Robert Foss, Dan Scally,
	Sowjanya Komatineni, Maxime Coquelin, linux-renesas-soc,
	Yong Zhi, Shawn Guo

29.04.2021 13:18, Mauro Carvalho Chehab пишет:
>> This is perfectly alright. Take a look at ov7740_remove() for example:
>>
>> 	pm_runtime_get_sync(&client->dev);
>> 	pm_runtime_disable(&client->dev);
>> 	pm_runtime_set_suspended(&client->dev);
>> 	pm_runtime_put_noidle(&client->dev);
>> 	
>> 	ov7740_set_power(ov7740, 0);
>>
>> There's an explicit power-off after balancing the PM count and this will
>> work regardless of the power state when entering this function.
> Ok, but this should equally work:
> 
>  	pm_runtime_disable(&client->dev);
>  	pm_runtime_set_suspended(&client->dev);
>  	
>  	ov7740_set_power(ov7740, 0);
> 
> as there's no additional cleanup made on this particular driver
> between pm_runtime_get_sync() and pm_runtime_put_noidle().
> 

The pm_runtime_get_sync() turns hardware ON by invoking
ov7740_set_power(ov7740, 1), and thus, the ON->OFF is kept balanced in
both RPM-available and RPM-unavailable cases. The RPM state of device
should be reset after driver removal.

It doesn't look like any additional cleanups are needed by that ov7740
driver. The driver removal is opposite to the probe, hence it should be
correct as-is.

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 25/79] staging: media: tegra-vde: use pm_runtime_resume_and_get()
  2021-04-28 14:51   ` Mauro Carvalho Chehab
@ 2021-04-29 12:38     ` Dmitry Osipenko
  -1 siblings, 0 replies; 208+ messages in thread
From: Dmitry Osipenko @ 2021-04-29 12:38 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman, Jonathan Hunter,
	Mauro Carvalho Chehab, Thierry Reding, devel, linux-kernel,
	linux-media, linux-tegra

28.04.2021 17:51, Mauro Carvalho Chehab пишет:
> @@ -1069,11 +1071,17 @@ static int tegra_vde_probe(struct platform_device *pdev)
>  	 * power-cycle it in order to put hardware into a predictable lower
>  	 * power state.
>  	 */
> -	pm_runtime_get_sync(dev);
> +	if (pm_runtime_resume_and_get(dev) < 0)
> +		goto err_pm_runtime;
> +
>  	pm_runtime_put(dev);
>  
>  	return 0;
>  
> +err_pm_runtime:
> +	pm_runtime_dont_use_autosuspend(dev);
> +	pm_runtime_disable(dev);
> +
>  err_deinit_iommu:
>  	tegra_vde_iommu_deinit(vde);

This is incorrect error unwinding, the miscdev isn't unregistered.

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 25/79] staging: media: tegra-vde: use pm_runtime_resume_and_get()
@ 2021-04-29 12:38     ` Dmitry Osipenko
  0 siblings, 0 replies; 208+ messages in thread
From: Dmitry Osipenko @ 2021-04-29 12:38 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, Jonathan Hunter,
	linux-tegra, Thierry Reding, mauro.chehab, Mauro Carvalho Chehab,
	linux-kernel, linux-media

28.04.2021 17:51, Mauro Carvalho Chehab пишет:
> @@ -1069,11 +1071,17 @@ static int tegra_vde_probe(struct platform_device *pdev)
>  	 * power-cycle it in order to put hardware into a predictable lower
>  	 * power state.
>  	 */
> -	pm_runtime_get_sync(dev);
> +	if (pm_runtime_resume_and_get(dev) < 0)
> +		goto err_pm_runtime;
> +
>  	pm_runtime_put(dev);
>  
>  	return 0;
>  
> +err_pm_runtime:
> +	pm_runtime_dont_use_autosuspend(dev);
> +	pm_runtime_disable(dev);
> +
>  err_deinit_iommu:
>  	tegra_vde_iommu_deinit(vde);

This is incorrect error unwinding, the miscdev isn't unregistered.
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
  2021-04-29 10:18     ` Mauro Carvalho Chehab
  (?)
@ 2021-04-29 15:17       ` Johan Hovold
  -1 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-04-29 15:17 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shawn Tu, Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Pengutronix Kernel Team,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Paul Kocialkowski, Mauro Carvalho Chehab, Dave Stevenson,
	Matt Ranostay, Krzysztof Kozlowski, Jonathan Hunter,
	linux-rockchip, Chen-Yu Tsai, Andy Gross, Matthias Brugger,
	Dongchun Zhu, Sakari Ailus, Bingbu Cao, Marek Szyprowski,
	Shunqian Zheng, Tianshu Qiu, NXP Linux Team, Philipp Zabel,
	devel, Jacopo Mondi, Sylwester Nawrocki, linux-tegra,
	Alexandre Torgue, Wenyou Yang, Manivannan Sadhasivam,
	linux-arm-msm, Sascha Hauer, Steve Longerbeam, linux-media,
	Maxime Ripard, Stanimir Varbanov, Benoit Parrot, Helen Koike,
	linux-samsung-soc, linux-mediatek, Jacek Anaszewski,
	mauro.chehab, Sylwester Nawrocki, Paul J. Murphy,
	Ezequiel Garcia, Daniele Alessandrelli, Chiranjeevi Rapolu,
	linux-arm-kernel, Jacob Chen, Jernej Skrabec, Hyungwoo Yang,
	linux-kernel, Robert Foss, Dan Scally, Sowjanya Komatineni,
	Maxime Coquelin, linux-renesas-soc, Yong Zhi, Shawn Guo

On Thu, Apr 29, 2021 at 12:18:16PM +0200, Mauro Carvalho Chehab wrote:
> Em Wed, 28 Apr 2021 17:50:08 +0200
> Johan Hovold <johan@kernel.org> escreveu:
> 
> > On Wed, Apr 28, 2021 at 04:51:21PM +0200, Mauro Carvalho Chehab wrote:
> 
> > > 1. despite its name, this is actually a PM runtime resume call,
> > >    but some developers didn't seem to realize that, as I got this
> > >    pattern on some drivers:
> > > 
> > >         pm_runtime_get_sync(&client->dev);
> > >         pm_runtime_disable(&client->dev);
> > >         pm_runtime_set_suspended(&client->dev);
> > >         pm_runtime_put_noidle(&client->dev);
> > > 
> > >    It makes no sense to resume PM just to suspend it again ;-)  
> > 
> > This is perfectly alright. Take a look at ov7740_remove() for example:
> > 
> > 	pm_runtime_get_sync(&client->dev);
> > 	pm_runtime_disable(&client->dev);
> > 	pm_runtime_set_suspended(&client->dev);
> > 	pm_runtime_put_noidle(&client->dev);
> > 	
> > 	ov7740_set_power(ov7740, 0);
> > 
> > There's an explicit power-off after balancing the PM count and this will
> > work regardless of the power state when entering this function.
> 
> Ok, but this should equally work:
> 
>  	pm_runtime_disable(&client->dev);
>  	pm_runtime_set_suspended(&client->dev);
>  	
>  	ov7740_set_power(ov7740, 0);
> 
> as there's no additional cleanup made on this particular driver
> between pm_runtime_get_sync() and pm_runtime_put_noidle().

No, that would break the driver as I pointed out to you yesterday:

	https://lore.kernel.org/r/YImG1klSPkFSaS3a@hovoldconsulting.com

If the device is already suspended when remove is called then you'll
end up with an unbalanced call to ov7740_set_power() that will try to
disable an already disabled clock.

> > So this has nothing to do with pm_runtime_get_sync() per se.
> 
> Yes, but some patches on this series are cleaning up the driver release
> logic.

You mentioned this example as an argument against using
pm_runtime_get_sync(), which I don't think makes sense.

> > > 2. Usual *_get() methods only increment their use count on success,
> > >    but pm_runtime_get_sync() increments it unconditionally. Due to
> > >    that, several drivers were mistakenly not calling
> > >    pm_runtime_put_noidle() when it fails;  
> > 
> > Sure, but pm_runtime_get_async() also works this way. You just won't be
> > notified if the async resume fails.
> 
> Granted, it makes sense along the pm_runtime kAPI.
> 
> It is inconsistent with the behavior of kobject_get*() and other
> *_get*() methods that are based or inspired on it, as, on those, the
> operations are atomic: either everything succeeds and it doesn't return
> an error, or the usage counter is not incremented and the object
> state doesn't change after the call.

Right, and I'm aware that some people have overlooked this. But its not
the end of the world since hardly any driver can handle resume failures
properly anyway. 

This is mostly just an exercise to shut up static checkers.

> > > 3. The name of the new variant is a lot clearer:
> > > 	pm_runtime_resume_and_get()
> > >     As its same clearly says that this is a PM runtime resume function,
> > >     that also increments the usage counter on success;  
> > 
> > It also introduced an inconsistency in the API and does not pair as well
> > with the pm_runtime_put variants.
> 
> Agreed. A name that would be more consistent with PM runtime would
> probably be:
> 
> 	pm_runtime_resume_if_get()

Naw, since the get part always succeeds.

It should start with pm_runtime_get, but pm_runtime_get_sync() is
unfortunately taken.

> as there are already:
> 
> 	pm_runtime_get_if_in_use()
> 	pm_runtime_get_if_active()
> 
> But any such discussions are out of the scope of this patchset ;-)

Right.

> > > 4. Consistency: we did similar changes subsystem wide with
> > >    for instance strlcpy() and strcpy() that got replaced by
> > >    strscpy(). Having all drivers using the same known-to-be-safe
> > >    methods is a good thing;  
> > 
> > It's not known to be safe; there are ways to get also this interface
> > wrong as for example this series has shown.
> 
> Very true. Yet, it is a lot simpler to use functions that won't change
> the state of the objects when returning an error, as this is by far
> the most common pattern within the Kernel.

A resume failure does change the state (and needs to be recovered from),
but I get what you're saying.

> Human brains are trained to identify certain patterns. When there's
> something using a similar pattern, but with a different behavior, 
> our brains are more subject to fail identifying problems.

Sure. But I'm not sure that having two interfaces with different
semantics to do the job is doing us any favours here. But again, that
discussion has already been had.

And I realise that this is partly also your motive here (even if the old
interface isn't going to go away).

> > > compile-tested only.
> > > Patches 1 to 7 fix some issues that already exists at the current
> > > PM runtime code;
> > > 
> > > patches 8 to 20 fix some usage_count problems that still exists
> > > at the media subsystem;
> > > 
> > > patches 21 to 78 repaces pm_runtime_get_sync() by 
> > > pm_runtime_resume_and_get();
> > > 
> > > Patch 79 (and a hunk on patch 78) documents the two exceptions
> > > where pm_runtime_get_sync() will still be used for now.

80 patches in one series (posted to lkml) is a bit excessive. Perhaps
you can break it up in a fixes part and one or more cleanups parts?

Johan

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-29 15:17       ` Johan Hovold
  0 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-04-29 15:17 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner, mauro.chehab,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Robert Foss, Sylwester Nawrocki,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Dan Scally, linux-samsung-soc, Dave Stevenson,
	Manivannan Sadhasivam, Chen-Yu Tsai, Krzysztof Kozlowski,
	Jonathan Hunter, linux-rockchip, Matt Ranostay, Andy Gross,
	Dongchun Zhu, Maxime Coquelin, Steve Longerbeam, Bingbu Cao,
	Marek Szyprowski, Shunqian Zheng, Tianshu Qiu, NXP Linux Team,
	Shawn Tu, devel, Jacopo Mondi, linux-tegra, Sakari Ailus,
	Wenyou Yang, Alexandre Torgue, linux-arm-msm, Sascha Hauer,
	linux-renesas-soc, Maxime Ripard, Stanimir Varbanov,
	Benoit Parrot, Helen Koike, Yong Zhi, linux-mediatek,
	Jacek Anaszewski, Matthias Brugger, Sylwester Nawrocki,
	Mauro Carvalho Chehab, Ezequiel Garcia, Daniele Alessandrelli,
	Chiranjeevi Rapolu, linux-arm-kernel, Jacob Chen, Jernej Skrabec,
	Philipp Zabel, Hyungwoo Yang, linux-kernel, Paul J. Murphy,
	Paul Kocialkowski, Sowjanya Komatineni, Pengutronix Kernel Team,
	linux-media, Shawn Guo

On Thu, Apr 29, 2021 at 12:18:16PM +0200, Mauro Carvalho Chehab wrote:
> Em Wed, 28 Apr 2021 17:50:08 +0200
> Johan Hovold <johan@kernel.org> escreveu:
> 
> > On Wed, Apr 28, 2021 at 04:51:21PM +0200, Mauro Carvalho Chehab wrote:
> 
> > > 1. despite its name, this is actually a PM runtime resume call,
> > >    but some developers didn't seem to realize that, as I got this
> > >    pattern on some drivers:
> > > 
> > >         pm_runtime_get_sync(&client->dev);
> > >         pm_runtime_disable(&client->dev);
> > >         pm_runtime_set_suspended(&client->dev);
> > >         pm_runtime_put_noidle(&client->dev);
> > > 
> > >    It makes no sense to resume PM just to suspend it again ;-)  
> > 
> > This is perfectly alright. Take a look at ov7740_remove() for example:
> > 
> > 	pm_runtime_get_sync(&client->dev);
> > 	pm_runtime_disable(&client->dev);
> > 	pm_runtime_set_suspended(&client->dev);
> > 	pm_runtime_put_noidle(&client->dev);
> > 	
> > 	ov7740_set_power(ov7740, 0);
> > 
> > There's an explicit power-off after balancing the PM count and this will
> > work regardless of the power state when entering this function.
> 
> Ok, but this should equally work:
> 
>  	pm_runtime_disable(&client->dev);
>  	pm_runtime_set_suspended(&client->dev);
>  	
>  	ov7740_set_power(ov7740, 0);
> 
> as there's no additional cleanup made on this particular driver
> between pm_runtime_get_sync() and pm_runtime_put_noidle().

No, that would break the driver as I pointed out to you yesterday:

	https://lore.kernel.org/r/YImG1klSPkFSaS3a@hovoldconsulting.com

If the device is already suspended when remove is called then you'll
end up with an unbalanced call to ov7740_set_power() that will try to
disable an already disabled clock.

> > So this has nothing to do with pm_runtime_get_sync() per se.
> 
> Yes, but some patches on this series are cleaning up the driver release
> logic.

You mentioned this example as an argument against using
pm_runtime_get_sync(), which I don't think makes sense.

> > > 2. Usual *_get() methods only increment their use count on success,
> > >    but pm_runtime_get_sync() increments it unconditionally. Due to
> > >    that, several drivers were mistakenly not calling
> > >    pm_runtime_put_noidle() when it fails;  
> > 
> > Sure, but pm_runtime_get_async() also works this way. You just won't be
> > notified if the async resume fails.
> 
> Granted, it makes sense along the pm_runtime kAPI.
> 
> It is inconsistent with the behavior of kobject_get*() and other
> *_get*() methods that are based or inspired on it, as, on those, the
> operations are atomic: either everything succeeds and it doesn't return
> an error, or the usage counter is not incremented and the object
> state doesn't change after the call.

Right, and I'm aware that some people have overlooked this. But its not
the end of the world since hardly any driver can handle resume failures
properly anyway. 

This is mostly just an exercise to shut up static checkers.

> > > 3. The name of the new variant is a lot clearer:
> > > 	pm_runtime_resume_and_get()
> > >     As its same clearly says that this is a PM runtime resume function,
> > >     that also increments the usage counter on success;  
> > 
> > It also introduced an inconsistency in the API and does not pair as well
> > with the pm_runtime_put variants.
> 
> Agreed. A name that would be more consistent with PM runtime would
> probably be:
> 
> 	pm_runtime_resume_if_get()

Naw, since the get part always succeeds.

It should start with pm_runtime_get, but pm_runtime_get_sync() is
unfortunately taken.

> as there are already:
> 
> 	pm_runtime_get_if_in_use()
> 	pm_runtime_get_if_active()
> 
> But any such discussions are out of the scope of this patchset ;-)

Right.

> > > 4. Consistency: we did similar changes subsystem wide with
> > >    for instance strlcpy() and strcpy() that got replaced by
> > >    strscpy(). Having all drivers using the same known-to-be-safe
> > >    methods is a good thing;  
> > 
> > It's not known to be safe; there are ways to get also this interface
> > wrong as for example this series has shown.
> 
> Very true. Yet, it is a lot simpler to use functions that won't change
> the state of the objects when returning an error, as this is by far
> the most common pattern within the Kernel.

A resume failure does change the state (and needs to be recovered from),
but I get what you're saying.

> Human brains are trained to identify certain patterns. When there's
> something using a similar pattern, but with a different behavior, 
> our brains are more subject to fail identifying problems.

Sure. But I'm not sure that having two interfaces with different
semantics to do the job is doing us any favours here. But again, that
discussion has already been had.

And I realise that this is partly also your motive here (even if the old
interface isn't going to go away).

> > > compile-tested only.
> > > Patches 1 to 7 fix some issues that already exists at the current
> > > PM runtime code;
> > > 
> > > patches 8 to 20 fix some usage_count problems that still exists
> > > at the media subsystem;
> > > 
> > > patches 21 to 78 repaces pm_runtime_get_sync() by 
> > > pm_runtime_resume_and_get();
> > > 
> > > Patch 79 (and a hunk on patch 78) documents the two exceptions
> > > where pm_runtime_get_sync() will still be used for now.

80 patches in one series (posted to lkml) is a bit excessive. Perhaps
you can break it up in a fixes part and one or more cleanups parts?

Johan
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 00/79] Address some issues with PM runtime at media subsystem
@ 2021-04-29 15:17       ` Johan Hovold
  0 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-04-29 15:17 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shawn Tu, Ricardo Ribalda, Dafna Hirschfeld, Heiko Stuebner,
	linuxarm, Todor Tomov, Bjorn Andersson, Andrzej Hajda, Lad,
	Prabhakar, Thierry Reding, Pengutronix Kernel Team,
	Dmitry Osipenko, linux-stm32, Andrzej Pietrasiewicz, Leon Luo,
	Paul Kocialkowski, Mauro Carvalho Chehab, Dave Stevenson,
	Matt Ranostay, Krzysztof Kozlowski, Jonathan Hunter,
	linux-rockchip, Chen-Yu Tsai, Andy Gross, Matthias Brugger,
	Dongchun Zhu, Sakari Ailus, Bingbu Cao, Marek Szyprowski,
	Shunqian Zheng, Tianshu Qiu, NXP Linux Team, Philipp Zabel,
	devel, Jacopo Mondi, Sylwester Nawrocki, linux-tegra,
	Alexandre Torgue, Wenyou Yang, Manivannan Sadhasivam,
	linux-arm-msm, Sascha Hauer, Steve Longerbeam, linux-media,
	Maxime Ripard, Stanimir Varbanov, Benoit Parrot, Helen Koike,
	linux-samsung-soc, linux-mediatek, Jacek Anaszewski,
	mauro.chehab, Sylwester Nawrocki, Paul J. Murphy,
	Ezequiel Garcia, Daniele Alessandrelli, Chiranjeevi Rapolu,
	linux-arm-kernel, Jacob Chen, Jernej Skrabec, Hyungwoo Yang,
	linux-kernel, Robert Foss, Dan Scally, Sowjanya Komatineni,
	Maxime Coquelin, linux-renesas-soc, Yong Zhi, Shawn Guo

On Thu, Apr 29, 2021 at 12:18:16PM +0200, Mauro Carvalho Chehab wrote:
> Em Wed, 28 Apr 2021 17:50:08 +0200
> Johan Hovold <johan@kernel.org> escreveu:
> 
> > On Wed, Apr 28, 2021 at 04:51:21PM +0200, Mauro Carvalho Chehab wrote:
> 
> > > 1. despite its name, this is actually a PM runtime resume call,
> > >    but some developers didn't seem to realize that, as I got this
> > >    pattern on some drivers:
> > > 
> > >         pm_runtime_get_sync(&client->dev);
> > >         pm_runtime_disable(&client->dev);
> > >         pm_runtime_set_suspended(&client->dev);
> > >         pm_runtime_put_noidle(&client->dev);
> > > 
> > >    It makes no sense to resume PM just to suspend it again ;-)  
> > 
> > This is perfectly alright. Take a look at ov7740_remove() for example:
> > 
> > 	pm_runtime_get_sync(&client->dev);
> > 	pm_runtime_disable(&client->dev);
> > 	pm_runtime_set_suspended(&client->dev);
> > 	pm_runtime_put_noidle(&client->dev);
> > 	
> > 	ov7740_set_power(ov7740, 0);
> > 
> > There's an explicit power-off after balancing the PM count and this will
> > work regardless of the power state when entering this function.
> 
> Ok, but this should equally work:
> 
>  	pm_runtime_disable(&client->dev);
>  	pm_runtime_set_suspended(&client->dev);
>  	
>  	ov7740_set_power(ov7740, 0);
> 
> as there's no additional cleanup made on this particular driver
> between pm_runtime_get_sync() and pm_runtime_put_noidle().

No, that would break the driver as I pointed out to you yesterday:

	https://lore.kernel.org/r/YImG1klSPkFSaS3a@hovoldconsulting.com

If the device is already suspended when remove is called then you'll
end up with an unbalanced call to ov7740_set_power() that will try to
disable an already disabled clock.

> > So this has nothing to do with pm_runtime_get_sync() per se.
> 
> Yes, but some patches on this series are cleaning up the driver release
> logic.

You mentioned this example as an argument against using
pm_runtime_get_sync(), which I don't think makes sense.

> > > 2. Usual *_get() methods only increment their use count on success,
> > >    but pm_runtime_get_sync() increments it unconditionally. Due to
> > >    that, several drivers were mistakenly not calling
> > >    pm_runtime_put_noidle() when it fails;  
> > 
> > Sure, but pm_runtime_get_async() also works this way. You just won't be
> > notified if the async resume fails.
> 
> Granted, it makes sense along the pm_runtime kAPI.
> 
> It is inconsistent with the behavior of kobject_get*() and other
> *_get*() methods that are based or inspired on it, as, on those, the
> operations are atomic: either everything succeeds and it doesn't return
> an error, or the usage counter is not incremented and the object
> state doesn't change after the call.

Right, and I'm aware that some people have overlooked this. But its not
the end of the world since hardly any driver can handle resume failures
properly anyway. 

This is mostly just an exercise to shut up static checkers.

> > > 3. The name of the new variant is a lot clearer:
> > > 	pm_runtime_resume_and_get()
> > >     As its same clearly says that this is a PM runtime resume function,
> > >     that also increments the usage counter on success;  
> > 
> > It also introduced an inconsistency in the API and does not pair as well
> > with the pm_runtime_put variants.
> 
> Agreed. A name that would be more consistent with PM runtime would
> probably be:
> 
> 	pm_runtime_resume_if_get()

Naw, since the get part always succeeds.

It should start with pm_runtime_get, but pm_runtime_get_sync() is
unfortunately taken.

> as there are already:
> 
> 	pm_runtime_get_if_in_use()
> 	pm_runtime_get_if_active()
> 
> But any such discussions are out of the scope of this patchset ;-)

Right.

> > > 4. Consistency: we did similar changes subsystem wide with
> > >    for instance strlcpy() and strcpy() that got replaced by
> > >    strscpy(). Having all drivers using the same known-to-be-safe
> > >    methods is a good thing;  
> > 
> > It's not known to be safe; there are ways to get also this interface
> > wrong as for example this series has shown.
> 
> Very true. Yet, it is a lot simpler to use functions that won't change
> the state of the objects when returning an error, as this is by far
> the most common pattern within the Kernel.

A resume failure does change the state (and needs to be recovered from),
but I get what you're saying.

> Human brains are trained to identify certain patterns. When there's
> something using a similar pattern, but with a different behavior, 
> our brains are more subject to fail identifying problems.

Sure. But I'm not sure that having two interfaces with different
semantics to do the job is doing us any favours here. But again, that
discussion has already been had.

And I realise that this is partly also your motive here (even if the old
interface isn't going to go away).

> > > compile-tested only.
> > > Patches 1 to 7 fix some issues that already exists at the current
> > > PM runtime code;
> > > 
> > > patches 8 to 20 fix some usage_count problems that still exists
> > > at the media subsystem;
> > > 
> > > patches 21 to 78 repaces pm_runtime_get_sync() by 
> > > pm_runtime_resume_and_get();
> > > 
> > > Patch 79 (and a hunk on patch 78) documents the two exceptions
> > > where pm_runtime_get_sync() will still be used for now.

80 patches in one series (posted to lkml) is a bit excessive. Perhaps
you can break it up in a fixes part and one or more cleanups parts?

Johan

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 01/79] media: venus: fix PM runtime logic at venus_sys_error_handler()
  2021-04-28 14:51 ` [PATCH v4 01/79] media: venus: fix PM runtime logic at venus_sys_error_handler() Mauro Carvalho Chehab
@ 2021-04-30 15:21   ` Jonathan Cameron
  2021-05-03  9:00     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 15:21 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andy Gross, Bjorn Andersson,
	Hans Verkuil, Mauro Carvalho Chehab, Stanimir Varbanov,
	linux-arm-msm, linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:22 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> The venus_sys_error_handler() assumes that pm_runtime was
> able to resume, as it does things like:
> 
> 	while (pm_runtime_active(core->dev_dec) || pm_runtime_active(core->dev_enc))
> 		msleep(10);
> 
> Well, if, for whatever reason, this won't happen, the routine
> won't do what's expected. So, check for the returned error
> condition, warning if it returns an error.
> 
> Fixes: af2c3834c8ca ("[media] media: venus: adding core part and helper functions")
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/media/platform/qcom/venus/core.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c
> index 54bac7ec14c5..c80c27c87ccc 100644
> --- a/drivers/media/platform/qcom/venus/core.c
> +++ b/drivers/media/platform/qcom/venus/core.c
> @@ -84,7 +84,11 @@ static void venus_sys_error_handler(struct work_struct *work)
>  			container_of(work, struct venus_core, work.work);
>  	int ret = 0;
>  
> -	pm_runtime_get_sync(core->dev);
> +	ret = pm_runtime_get_sync(core->dev);
> +	if (WARN_ON(ret < 0)) {
> +		pm_runtime_put_noidle(core->dev);
> +		return;
> +	}
>  
>  	hfi_core_deinit(core, true);
>  
> @@ -106,9 +110,13 @@ static void venus_sys_error_handler(struct work_struct *work)
>  
>  	hfi_reinit(core);
>  
> -	pm_runtime_get_sync(core->dev);
> +	ret = pm_runtime_get_sync(core->dev);
> +	if (WARN_ON(ret < 0)) {
> +		pm_runtime_put_noidle(core->dev);

mutex_unlock(&core->lock);
(the unlock is currently just below the enable_irq() in 5.12)


> +		return;
> +	}
>  
> -	ret |= venus_boot(core);
> +	ret = venus_boot(core);
>  	ret |= hfi_core_resume(core, true);
>  
>  	enable_irq(core->irq);


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 06/79] media: i2c: imx334: fix the pm runtime get logic
  2021-04-28 14:51 ` [PATCH v4 06/79] media: i2c: imx334: fix the pm runtime get logic Mauro Carvalho Chehab
@ 2021-04-30 15:54   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 15:54 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Paul J. Murphy, Daniele Alessandrelli,
	Mauro Carvalho Chehab, linux-kernel, linux-media, Dan Carpenter

On Wed, 28 Apr 2021 16:51:27 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> The PM runtime get logic is currently broken, as it checks if
> ret is zero instead of checking if it is an error code,
> as reported by Dan Carpenter.
> 
> While here, use the pm_runtime_resume_and_get() as added by:
> 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.

Perhaps also call out that a fail of pm_runtime_get_sync in current
code would potentially result in a spurious runtime_suspend() call
whereas using pm_runtime_resume_and_get() will call
pm_runtime_put_noidle()

> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Reviewed-by: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/media/i2c/imx334.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c
> index 047aa7658d21..23f28606e570 100644
> --- a/drivers/media/i2c/imx334.c
> +++ b/drivers/media/i2c/imx334.c
> @@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
>  	}
>  
>  	if (enable) {
> -		ret = pm_runtime_get_sync(imx334->dev);
> -		if (ret)
> -			goto error_power_off;
> +		ret = pm_runtime_resume_and_get(imx334->dev);
> +		if (ret < 0)
> +			goto error_unlock;
>  
>  		ret = imx334_start_streaming(imx334);
>  		if (ret)
> @@ -737,6 +737,7 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
>  
>  error_power_off:
>  	pm_runtime_put(imx334->dev);
> +error_unlock:
>  	mutex_unlock(&imx334->mutex);
>  
>  	return ret;


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 08/79] media: atmel: properly get pm_runtime
  2021-04-28 14:51   ` Mauro Carvalho Chehab
@ 2021-04-30 16:13     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:13 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Alexandre Belloni, linux-kernel, linuxarm, Ludovic Desroches,
	mauro.chehab, Eugen Hristev, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-media

On Wed, 28 Apr 2021 16:51:29 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> There are several issues in the way the atmel driver handles
> pm_runtime_get_sync():
> 
> - it doesn't check return codes;
> - it doesn't properly decrement the usage_count on all places;
> - it starts streaming even if pm_runtime_get_sync() fails.
> - while it tries to get pm_runtime at the clock enable logic,
>   it doesn't check if the operation was suceeded.
> 
> Replace all occurrences of it to use the new kAPI:
> pm_runtime_resume_and_get(), which ensures that, if the
> return code is not negative, the usage_count was incremented.
> 
> With that, add additional checks when this is called, in order
> to ensure that errors will be properly addressed.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/media/platform/atmel/atmel-isc-base.c | 27 ++++++++++++++-----
>  drivers/media/platform/atmel/atmel-isi.c      | 19 ++++++++++---
>  2 files changed, 35 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
> index fe3ec8d0eaee..02543fe42e9d 100644
> --- a/drivers/media/platform/atmel/atmel-isc-base.c
> +++ b/drivers/media/platform/atmel/atmel-isc-base.c
> @@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
>  static int isc_clk_prepare(struct clk_hw *hw)
>  {
>  	struct isc_clk *isc_clk = to_isc_clk(hw);
> +	int ret;
>  
> -	if (isc_clk->id == ISC_ISPCK)
> -		pm_runtime_get_sync(isc_clk->dev);
> +	if (isc_clk->id == ISC_ISPCK) {
> +		ret = pm_runtime_resume_and_get(isc_clk->dev);
> +		if (ret < 0)
> +			return 0;

Why not the error?  isc_wait_clk_stable() is happy to return -ETIMEDOUT so I
assume the callers should fine with errors.

> +	}
>  
>  	return isc_wait_clk_stable(hw);
>  }
> @@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk_hw *hw)
>  {
>  	struct isc_clk *isc_clk = to_isc_clk(hw);
>  	u32 status;
> +	int ret;
>  
> -	if (isc_clk->id == ISC_ISPCK)
> -		pm_runtime_get_sync(isc_clk->dev);
> +	if (isc_clk->id == ISC_ISPCK) {
> +		ret = pm_runtime_resume_and_get(isc_clk->dev);
> +		if (ret < 0)
> +			return 0;
> +	}
>  
>  	regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
>  
> @@ -807,7 +815,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
>  		goto err_start_stream;
>  	}
>  
> -	pm_runtime_get_sync(isc->dev);
> +	ret = pm_runtime_resume_and_get(isc->dev);
> +	if (ret < 0)
> +		goto err_pm_get;
>  
>  	ret = isc_configure(isc);
>  	if (unlikely(ret))
> @@ -838,7 +848,7 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
>  
>  err_configure:
>  	pm_runtime_put_sync(isc->dev);
> -
> +err_pm_get:
>  	v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
>  
>  err_start_stream:
> @@ -1809,6 +1819,7 @@ static void isc_awb_work(struct work_struct *w)
>  	u32 baysel;
>  	unsigned long flags;
>  	u32 min, max;
> +	int ret;
>  
>  	/* streaming is not active anymore */
>  	if (isc->stop)
> @@ -1831,7 +1842,9 @@ static void isc_awb_work(struct work_struct *w)
>  	ctrls->hist_id = hist_id;
>  	baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
>  
> -	pm_runtime_get_sync(isc->dev);
> +	ret = pm_runtime_resume_and_get(isc->dev);
> +	if (ret < 0)

Maybe warn or similar?

> +		return;
>  
>  	/*
>  	 * only update if we have all the required histograms and controls
> diff --git a/drivers/media/platform/atmel/atmel-isi.c b/drivers/media/platform/atmel/atmel-isi.c
> index 0514be6153df..6a433926726d 100644
> --- a/drivers/media/platform/atmel/atmel-isi.c
> +++ b/drivers/media/platform/atmel/atmel-isi.c
> @@ -422,7 +422,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
>  	struct frame_buffer *buf, *node;
>  	int ret;
>  
> -	pm_runtime_get_sync(isi->dev);
> +	ret = pm_runtime_resume_and_get(isi->dev);
> +	if (ret < 0)
> +		return ret;
>  
>  	/* Enable stream on the sub device */
>  	ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
> @@ -782,9 +784,10 @@ static int isi_enum_frameintervals(struct file *file, void *fh,
>  	return 0;
>  }
>  
> -static void isi_camera_set_bus_param(struct atmel_isi *isi)
> +static int isi_camera_set_bus_param(struct atmel_isi *isi)
>  {
>  	u32 cfg1 = 0;
> +	int ret;
>  
>  	/* set bus param for ISI */
>  	if (isi->pdata.hsync_act_low)
> @@ -801,12 +804,16 @@ static void isi_camera_set_bus_param(struct atmel_isi *isi)
>  	cfg1 |= ISI_CFG1_THMASK_BEATS_16;
>  
>  	/* Enable PM and peripheral clock before operate isi registers */
> -	pm_runtime_get_sync(isi->dev);
> +	ret = pm_runtime_resume_and_get(isi->dev);
> +	if (ret < 0)
> +		return ret;
>  
>  	isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
>  	isi_writel(isi, ISI_CFG1, cfg1);
>  
>  	pm_runtime_put(isi->dev);
> +
> +	return 0;
>  }
>  
>  /* -----------------------------------------------------------------------*/
> @@ -1085,7 +1092,11 @@ static int isi_graph_notify_complete(struct v4l2_async_notifier *notifier)
>  		dev_err(isi->dev, "No supported mediabus format found\n");
>  		return ret;
>  	}
> -	isi_camera_set_bus_param(isi);
> +	ret = isi_camera_set_bus_param(isi);
> +	if (ret) {
> +		dev_err(isi->dev, "Can't wake up device\n");
> +		return ret;
> +	}
>  
>  	ret = isi_set_default_fmt(isi);
>  	if (ret) {


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 08/79] media: atmel: properly get pm_runtime
@ 2021-04-30 16:13     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:13 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Alexandre Belloni, linux-kernel, linuxarm, Ludovic Desroches,
	mauro.chehab, Eugen Hristev, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-media

On Wed, 28 Apr 2021 16:51:29 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> There are several issues in the way the atmel driver handles
> pm_runtime_get_sync():
> 
> - it doesn't check return codes;
> - it doesn't properly decrement the usage_count on all places;
> - it starts streaming even if pm_runtime_get_sync() fails.
> - while it tries to get pm_runtime at the clock enable logic,
>   it doesn't check if the operation was suceeded.
> 
> Replace all occurrences of it to use the new kAPI:
> pm_runtime_resume_and_get(), which ensures that, if the
> return code is not negative, the usage_count was incremented.
> 
> With that, add additional checks when this is called, in order
> to ensure that errors will be properly addressed.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/media/platform/atmel/atmel-isc-base.c | 27 ++++++++++++++-----
>  drivers/media/platform/atmel/atmel-isi.c      | 19 ++++++++++---
>  2 files changed, 35 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
> index fe3ec8d0eaee..02543fe42e9d 100644
> --- a/drivers/media/platform/atmel/atmel-isc-base.c
> +++ b/drivers/media/platform/atmel/atmel-isc-base.c
> @@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
>  static int isc_clk_prepare(struct clk_hw *hw)
>  {
>  	struct isc_clk *isc_clk = to_isc_clk(hw);
> +	int ret;
>  
> -	if (isc_clk->id == ISC_ISPCK)
> -		pm_runtime_get_sync(isc_clk->dev);
> +	if (isc_clk->id == ISC_ISPCK) {
> +		ret = pm_runtime_resume_and_get(isc_clk->dev);
> +		if (ret < 0)
> +			return 0;

Why not the error?  isc_wait_clk_stable() is happy to return -ETIMEDOUT so I
assume the callers should fine with errors.

> +	}
>  
>  	return isc_wait_clk_stable(hw);
>  }
> @@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk_hw *hw)
>  {
>  	struct isc_clk *isc_clk = to_isc_clk(hw);
>  	u32 status;
> +	int ret;
>  
> -	if (isc_clk->id == ISC_ISPCK)
> -		pm_runtime_get_sync(isc_clk->dev);
> +	if (isc_clk->id == ISC_ISPCK) {
> +		ret = pm_runtime_resume_and_get(isc_clk->dev);
> +		if (ret < 0)
> +			return 0;
> +	}
>  
>  	regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
>  
> @@ -807,7 +815,9 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
>  		goto err_start_stream;
>  	}
>  
> -	pm_runtime_get_sync(isc->dev);
> +	ret = pm_runtime_resume_and_get(isc->dev);
> +	if (ret < 0)
> +		goto err_pm_get;
>  
>  	ret = isc_configure(isc);
>  	if (unlikely(ret))
> @@ -838,7 +848,7 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
>  
>  err_configure:
>  	pm_runtime_put_sync(isc->dev);
> -
> +err_pm_get:
>  	v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
>  
>  err_start_stream:
> @@ -1809,6 +1819,7 @@ static void isc_awb_work(struct work_struct *w)
>  	u32 baysel;
>  	unsigned long flags;
>  	u32 min, max;
> +	int ret;
>  
>  	/* streaming is not active anymore */
>  	if (isc->stop)
> @@ -1831,7 +1842,9 @@ static void isc_awb_work(struct work_struct *w)
>  	ctrls->hist_id = hist_id;
>  	baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
>  
> -	pm_runtime_get_sync(isc->dev);
> +	ret = pm_runtime_resume_and_get(isc->dev);
> +	if (ret < 0)

Maybe warn or similar?

> +		return;
>  
>  	/*
>  	 * only update if we have all the required histograms and controls
> diff --git a/drivers/media/platform/atmel/atmel-isi.c b/drivers/media/platform/atmel/atmel-isi.c
> index 0514be6153df..6a433926726d 100644
> --- a/drivers/media/platform/atmel/atmel-isi.c
> +++ b/drivers/media/platform/atmel/atmel-isi.c
> @@ -422,7 +422,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
>  	struct frame_buffer *buf, *node;
>  	int ret;
>  
> -	pm_runtime_get_sync(isi->dev);
> +	ret = pm_runtime_resume_and_get(isi->dev);
> +	if (ret < 0)
> +		return ret;
>  
>  	/* Enable stream on the sub device */
>  	ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
> @@ -782,9 +784,10 @@ static int isi_enum_frameintervals(struct file *file, void *fh,
>  	return 0;
>  }
>  
> -static void isi_camera_set_bus_param(struct atmel_isi *isi)
> +static int isi_camera_set_bus_param(struct atmel_isi *isi)
>  {
>  	u32 cfg1 = 0;
> +	int ret;
>  
>  	/* set bus param for ISI */
>  	if (isi->pdata.hsync_act_low)
> @@ -801,12 +804,16 @@ static void isi_camera_set_bus_param(struct atmel_isi *isi)
>  	cfg1 |= ISI_CFG1_THMASK_BEATS_16;
>  
>  	/* Enable PM and peripheral clock before operate isi registers */
> -	pm_runtime_get_sync(isi->dev);
> +	ret = pm_runtime_resume_and_get(isi->dev);
> +	if (ret < 0)
> +		return ret;
>  
>  	isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
>  	isi_writel(isi, ISI_CFG1, cfg1);
>  
>  	pm_runtime_put(isi->dev);
> +
> +	return 0;
>  }
>  
>  /* -----------------------------------------------------------------------*/
> @@ -1085,7 +1092,11 @@ static int isi_graph_notify_complete(struct v4l2_async_notifier *notifier)
>  		dev_err(isi->dev, "No supported mediabus format found\n");
>  		return ret;
>  	}
> -	isi_camera_set_bus_param(isi);
> +	ret = isi_camera_set_bus_param(isi);
> +	if (ret) {
> +		dev_err(isi->dev, "Can't wake up device\n");
> +		return ret;
> +	}
>  
>  	ret = isi_set_default_fmt(isi);
>  	if (ret) {


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 11/79] media: rcar_fdp1: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` [PATCH v4 11/79] media: rcar_fdp1: " Mauro Carvalho Chehab
@ 2021-04-30 16:26   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:26 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Kieran Bingham, Mauro Carvalho Chehab,
	linux-kernel, linux-media, linux-renesas-soc

On Wed, 28 Apr 2021 16:51:32 +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.
> 
> Also, right now, the driver is ignoring any troubles when
> trying to do PM resume. So, add the proper error handling
> for the code.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Refactor to move the error handling block to one place perhaps?

Also, I thin more cleanup is needed int he 
> ---
>  drivers/media/platform/rcar_fdp1.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/rcar_fdp1.c b/drivers/media/platform/rcar_fdp1.c
> index 01c1fbb97bf6..c32d237af618 100644
> --- a/drivers/media/platform/rcar_fdp1.c
> +++ b/drivers/media/platform/rcar_fdp1.c
> @@ -2140,7 +2140,13 @@ static int fdp1_open(struct file *file)
>  	}
>  
>  	/* Perform any power management required */
> -	pm_runtime_get_sync(fdp1->dev);
> +	ret = pm_runtime_resume_and_get(fdp1->dev);
> +	if (ret < 0) {
> +		v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);

Next few lines repeated enough times that I'd suggest just pulling error handling out
to it's own path.

> +		v4l2_ctrl_handler_free(&ctx->hdl);
> +		kfree(ctx);
> +		goto done;
> +	}
>  
>  	v4l2_fh_add(&ctx->fh);
>  
> @@ -2351,7 +2357,9 @@ static int fdp1_probe(struct platform_device *pdev)
>  
>  	/* Power up the cells to read HW */
>  	pm_runtime_enable(&pdev->dev);
> -	pm_runtime_get_sync(fdp1->dev);
> +	ret = pm_runtime_resume_and_get(fdp1->dev);

From a balance point of view, do you want to all pm_runtime_disable()
if this happens and also I'd guess you need to unregister the device
as done in other error paths in probe

The lack of balance between ordering in probe and remove before
your patch bothers me but I don't know the code well enough to tell
if there are any actual bugs there.


> +	if (ret < 0)
> +		return ret;
>  
>  	hw_version = fdp1_read(fdp1, FD1_IP_INTDATA);
>  	switch (hw_version) {


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 12/79] media: renesas-ceu: Properly check for PM errors
  2021-04-28 14:51 ` [PATCH v4 12/79] media: renesas-ceu: Properly check for PM errors Mauro Carvalho Chehab
@ 2021-04-30 16:28   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:28 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Jacopo Mondi, Mauro Carvalho Chehab,
	linux-kernel, linux-media, linux-renesas-soc

On Wed, 28 Apr 2021 16:51:33 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> Right now, the driver just assumes that PM runtime resume
> worked, but it may fail.
> 
> Well, the pm_runtime_get_sync() internally increments the
> dev->power.usage_count without decrementing it, even on errors.
> 
> So, using it is tricky. Let's 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")
> and return an error if something bad happens.
> 
> This should ensure that the PM runtime usage_count will be
> properly decremented if an error happens at open time.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/media/platform/renesas-ceu.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas-ceu.c b/drivers/media/platform/renesas-ceu.c
> index cd137101d41e..17f01b6e3fe0 100644
> --- a/drivers/media/platform/renesas-ceu.c
> +++ b/drivers/media/platform/renesas-ceu.c
> @@ -1099,10 +1099,10 @@ static int ceu_open(struct file *file)
>  
>  	mutex_lock(&ceudev->mlock);
>  	/* Causes soft-reset and sensor power on on first open */
> -	pm_runtime_get_sync(ceudev->dev);
> +	ret = pm_runtime_resume_and_get(ceudev->dev);
>  	mutex_unlock(&ceudev->mlock);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static int ceu_release(struct file *file)


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 09/79] media: marvel-ccic: fix some issues when getting pm_runtime
  2021-04-28 14:51 ` [PATCH v4 09/79] media: marvel-ccic: fix some issues when getting pm_runtime Mauro Carvalho Chehab
@ 2021-04-30 16:29   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:29 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Gustavo A. R. Silva, Allen Pais,
	Chuhong Yuan, Ezequiel Garcia, Hans Verkuil, Helen Koike,
	Lubomir Rintel, Mauro Carvalho Chehab, Sakari Ailus,
	Vaibhav Gupta, linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:30 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> Calling pm_runtime_get_sync() is bad, since even when it
> returns an error, pm_runtime_put*() should be called.
> So, use instead pm_runtime_resume_and_get().
> 
> While here, ensure that the error condition will be checked
> during clock enable an media open() calls.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/media/platform/marvell-ccic/mcam-core.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
> index 141bf5d97a04..ea87110d9073 100644
> --- a/drivers/media/platform/marvell-ccic/mcam-core.c
> +++ b/drivers/media/platform/marvell-ccic/mcam-core.c
> @@ -918,6 +918,7 @@ static int mclk_enable(struct clk_hw *hw)
>  	struct mcam_camera *cam = container_of(hw, struct mcam_camera, mclk_hw);
>  	int mclk_src;
>  	int mclk_div;
> +	int ret;
>  
>  	/*
>  	 * Clock the sensor appropriately.  Controller clock should
> @@ -931,7 +932,9 @@ static int mclk_enable(struct clk_hw *hw)
>  		mclk_div = 2;
>  	}
>  
> -	pm_runtime_get_sync(cam->dev);
> +	ret = pm_runtime_resume_and_get(cam->dev);
> +	if (ret < 0)
> +		return ret;
>  	clk_enable(cam->clk[0]);
>  	mcam_reg_write(cam, REG_CLKCTRL, (mclk_src << 29) | mclk_div);
>  	mcam_ctlr_power_up(cam);
> @@ -1611,7 +1614,9 @@ static int mcam_v4l_open(struct file *filp)
>  		ret = sensor_call(cam, core, s_power, 1);
>  		if (ret)
>  			goto out;
> -		pm_runtime_get_sync(cam->dev);
> +		ret = pm_runtime_resume_and_get(cam->dev);
> +		if (ret < 0)
> +			goto out;
>  		__mcam_cam_reset(cam);
>  		mcam_set_config_needed(cam, 1);
>  	}


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 10/79] media: mdk-mdp: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-30 16:30     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:30 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andrew-CT Chen, Houlong Wei,
	Matthias Brugger, Mauro Carvalho Chehab, Minghsiu Tsai,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

On Wed, 28 Apr 2021 16:51:31 +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, fix the return contition of mtk_mdp_m2m_start_streaming(),
> as it doesn't make any sense to return 0 if the PM runtime failed
> to resume.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> index ace4528cdc5e..f14779e7596e 100644
> --- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> @@ -391,12 +391,12 @@ static int mtk_mdp_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
>  	struct mtk_mdp_ctx *ctx = q->drv_priv;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(&ctx->mdp_dev->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&ctx->mdp_dev->pdev->dev);
>  	if (ret < 0)
> -		mtk_mdp_dbg(1, "[%d] pm_runtime_get_sync failed:%d",
> +		mtk_mdp_dbg(1, "[%d] pm_runtime_resume_and_get failed:%d",
>  			    ctx->id, ret);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static void *mtk_mdp_m2m_buf_remove(struct mtk_mdp_ctx *ctx,


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 10/79] media: mdk-mdp: fix pm_runtime_get_sync() usage count
@ 2021-04-30 16:30     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:30 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andrew-CT Chen, Houlong Wei,
	Matthias Brugger, Mauro Carvalho Chehab, Minghsiu Tsai,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

On Wed, 28 Apr 2021 16:51:31 +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, fix the return contition of mtk_mdp_m2m_start_streaming(),
> as it doesn't make any sense to return 0 if the PM runtime failed
> to resume.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> index ace4528cdc5e..f14779e7596e 100644
> --- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> @@ -391,12 +391,12 @@ static int mtk_mdp_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
>  	struct mtk_mdp_ctx *ctx = q->drv_priv;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(&ctx->mdp_dev->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&ctx->mdp_dev->pdev->dev);
>  	if (ret < 0)
> -		mtk_mdp_dbg(1, "[%d] pm_runtime_get_sync failed:%d",
> +		mtk_mdp_dbg(1, "[%d] pm_runtime_resume_and_get failed:%d",
>  			    ctx->id, ret);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static void *mtk_mdp_m2m_buf_remove(struct mtk_mdp_ctx *ctx,


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 10/79] media: mdk-mdp: fix pm_runtime_get_sync() usage count
@ 2021-04-30 16:30     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:30 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andrew-CT Chen, Houlong Wei,
	Matthias Brugger, Mauro Carvalho Chehab, Minghsiu Tsai,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

On Wed, 28 Apr 2021 16:51:31 +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, fix the return contition of mtk_mdp_m2m_start_streaming(),
> as it doesn't make any sense to return 0 if the PM runtime failed
> to resume.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> index ace4528cdc5e..f14779e7596e 100644
> --- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> @@ -391,12 +391,12 @@ static int mtk_mdp_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
>  	struct mtk_mdp_ctx *ctx = q->drv_priv;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(&ctx->mdp_dev->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&ctx->mdp_dev->pdev->dev);
>  	if (ret < 0)
> -		mtk_mdp_dbg(1, "[%d] pm_runtime_get_sync failed:%d",
> +		mtk_mdp_dbg(1, "[%d] pm_runtime_resume_and_get failed:%d",
>  			    ctx->id, ret);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static void *mtk_mdp_m2m_buf_remove(struct mtk_mdp_ctx *ctx,


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 14/79] media: am437x: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` [PATCH v4 14/79] media: am437x: " Mauro Carvalho Chehab
@ 2021-04-30 16:36   ` Jonathan Cameron
  2021-05-04  7:19     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:36 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Lad, Prabhakar, Mauro Carvalho Chehab,
	linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:35 +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, ensure that the driver will check if PM runtime
> resumed at vpfe_initialize_device().
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

resume and suspend carrying regardless needs a comment I think.
(see below)
> ---
>  drivers/media/platform/am437x/am437x-vpfe.c | 22 +++++++++++++++------
>  1 file changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
> index 6cdc77dda0e4..bced526f30f2 100644
> --- a/drivers/media/platform/am437x/am437x-vpfe.c
> +++ b/drivers/media/platform/am437x/am437x-vpfe.c
> @@ -1021,7 +1021,9 @@ static int vpfe_initialize_device(struct vpfe_device *vpfe)
>  	if (ret)
>  		return ret;
>  
> -	pm_runtime_get_sync(vpfe->pdev);
> +	ret = pm_runtime_resume_and_get(vpfe->pdev);
> +	if (ret < 0)
> +		return ret;
>  
>  	vpfe_config_enable(&vpfe->ccdc, 1);
>  
> @@ -2443,7 +2445,11 @@ static int vpfe_probe(struct platform_device *pdev)
>  	pm_runtime_enable(&pdev->dev);
>  
>  	/* for now just enable it here instead of waiting for the open */
> -	pm_runtime_get_sync(&pdev->dev);
> +	ret = pm_runtime_resume_and_get(&pdev->dev);
> +	if (ret < 0) {
> +		vpfe_err(vpfe, "Unable to resume device.\n");
> +		goto probe_out_v4l2_unregister;
> +	}
>  
>  	vpfe_ccdc_config_defaults(ccdc);
>  
> @@ -2527,10 +2533,11 @@ static int vpfe_suspend(struct device *dev)
>  {
>  	struct vpfe_device *vpfe = dev_get_drvdata(dev);
>  	struct vpfe_ccdc *ccdc = &vpfe->ccdc;
> +	int ret;
>  
>  	/* only do full suspend if streaming has started */
>  	if (vb2_start_streaming_called(&vpfe->buffer_queue)) {
> -		pm_runtime_get_sync(dev);
> +		ret = pm_runtime_resume_and_get(dev);

Carrying on when you know the resume failed, seems interesting enough to
deserve a comment in the code.  Not sure you can usefully do anything
but it seems likely a lot of the calls that follow will fail.


>  		vpfe_config_enable(ccdc, 1);
>  
>  		/* Save VPFE context */
> @@ -2541,7 +2548,8 @@ static int vpfe_suspend(struct device *dev)
>  		vpfe_config_enable(ccdc, 0);
>  
>  		/* Disable both master and slave clock */
> -		pm_runtime_put_sync(dev);
> +		if (ret >= 0)
> +			pm_runtime_put_sync(dev);
>  	}
>  
>  	/* Select sleep pin state */
> @@ -2583,18 +2591,20 @@ static int vpfe_resume(struct device *dev)
>  {
>  	struct vpfe_device *vpfe = dev_get_drvdata(dev);
>  	struct vpfe_ccdc *ccdc = &vpfe->ccdc;
> +	int ret;
>  
>  	/* only do full resume if streaming has started */
>  	if (vb2_start_streaming_called(&vpfe->buffer_queue)) {
>  		/* Enable both master and slave clock */
> -		pm_runtime_get_sync(dev);
> +		ret = pm_runtime_resume_and_get(dev);
>  		vpfe_config_enable(ccdc, 1);
>  
>  		/* Restore VPFE context */
>  		vpfe_restore_context(ccdc);
>  
>  		vpfe_config_enable(ccdc, 0);
> -		pm_runtime_put_sync(dev);
> +		if (ret >= 0)
> +			pm_runtime_put_sync(dev);
>  	}
>  
>  	/* Select default pin state */


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 15/79] media: sh_vou: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` [PATCH v4 15/79] media: sh_vou: " Mauro Carvalho Chehab
@ 2021-04-30 16:40   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:40 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Gustavo A. R. Silva, Geert Uytterhoeven,
	Hans Verkuil, Mauro Carvalho Chehab, linux-kernel, linux-media

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);


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 16/79] media: mtk-vcodec: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-30 16:44     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andrew-CT Chen, Matthias Brugger,
	Mauro Carvalho Chehab, Tiffany Lin, linux-arm-kernel,
	linux-kernel, linux-media, linux-mediatek

On Wed, 28 Apr 2021 16:51:37 +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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Without a return value, this seems like it's not complete as driver
will carry on and eventually call mtk_vcode_dec_pw_off() which will assume
it needs to decrement the count.


> ---
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> index ddee7046ce42..fe096fe61c9d 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> @@ -92,9 +92,9 @@ void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
>  {
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(pm->dev);
> +	ret = pm_runtime_resume_and_get(pm->dev);
>  	if (ret)
> -		mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
> +		mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
>  }
>  
>  void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 16/79] media: mtk-vcodec: fix pm_runtime_get_sync() usage count
@ 2021-04-30 16:44     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andrew-CT Chen, Matthias Brugger,
	Mauro Carvalho Chehab, Tiffany Lin, linux-arm-kernel,
	linux-kernel, linux-media, linux-mediatek

On Wed, 28 Apr 2021 16:51:37 +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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Without a return value, this seems like it's not complete as driver
will carry on and eventually call mtk_vcode_dec_pw_off() which will assume
it needs to decrement the count.


> ---
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> index ddee7046ce42..fe096fe61c9d 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> @@ -92,9 +92,9 @@ void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
>  {
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(pm->dev);
> +	ret = pm_runtime_resume_and_get(pm->dev);
>  	if (ret)
> -		mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
> +		mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
>  }
>  
>  void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 16/79] media: mtk-vcodec: fix pm_runtime_get_sync() usage count
@ 2021-04-30 16:44     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andrew-CT Chen, Matthias Brugger,
	Mauro Carvalho Chehab, Tiffany Lin, linux-arm-kernel,
	linux-kernel, linux-media, linux-mediatek

On Wed, 28 Apr 2021 16:51:37 +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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Without a return value, this seems like it's not complete as driver
will carry on and eventually call mtk_vcode_dec_pw_off() which will assume
it needs to decrement the count.


> ---
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> index ddee7046ce42..fe096fe61c9d 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
> @@ -92,9 +92,9 @@ void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
>  {
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(pm->dev);
> +	ret = pm_runtime_resume_and_get(pm->dev);
>  	if (ret)
> -		mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
> +		mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
>  }
>  
>  void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 18/79] media: sti/delta: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51 ` [PATCH v4 18/79] media: sti/delta: " Mauro Carvalho Chehab
@ 2021-04-30 16:47   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:47 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Hugues Fruchet, Mauro Carvalho Chehab,
	linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:39 +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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This looks wrong.    The caller of this calls delta_put_autosuspend()
on error which calls pm_runtime_put_autosuspend() on something where
we never incremented the count after your change.

> ---
>  drivers/media/platform/sti/delta/delta-v4l2.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/sti/delta/delta-v4l2.c b/drivers/media/platform/sti/delta/delta-v4l2.c
> index c691b3d81549..9928b7c46a41 100644
> --- a/drivers/media/platform/sti/delta/delta-v4l2.c
> +++ b/drivers/media/platform/sti/delta/delta-v4l2.c
> @@ -1277,9 +1277,9 @@ int delta_get_sync(struct delta_ctx *ctx)
>  	int ret = 0;
>  
>  	/* enable the hardware */
> -	ret = pm_runtime_get_sync(delta->dev);
> +	ret = pm_runtime_resume_and_get(delta->dev);
>  	if (ret < 0) {
> -		dev_err(delta->dev, "%s pm_runtime_get_sync failed (%d)\n",
> +		dev_err(delta->dev, "%s pm_runtime_resume_and_get failed (%d)\n",
>  			__func__, ret);
>  		return ret;
>  	}


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 19/79] media: sunxi: fix pm_runtime_get_sync() usage count
  2021-04-28 14:51   ` Mauro Carvalho Chehab
@ 2021-04-30 16:48     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:48 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Chen-Yu Tsai, Jernej Skrabec,
	Mauro Carvalho Chehab, Maxime Ripard, linux-arm-kernel,
	linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:40 +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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
> index 3f81dd17755c..fbcca59a0517 100644
> --- a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
> +++ b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
> @@ -494,7 +494,7 @@ static int rotate_start_streaming(struct vb2_queue *vq, unsigned int count)
>  		struct device *dev = ctx->dev->dev;
>  		int ret;
>  
> -		ret = pm_runtime_get_sync(dev);
> +		ret = pm_runtime_resume_and_get(dev);
>  		if (ret < 0) {
>  			dev_err(dev, "Failed to enable module\n");
>  


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 19/79] media: sunxi: fix pm_runtime_get_sync() usage count
@ 2021-04-30 16:48     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:48 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Chen-Yu Tsai, Jernej Skrabec,
	Mauro Carvalho Chehab, Maxime Ripard, linux-arm-kernel,
	linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:40 +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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
> index 3f81dd17755c..fbcca59a0517 100644
> --- a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
> +++ b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
> @@ -494,7 +494,7 @@ static int rotate_start_streaming(struct vb2_queue *vq, unsigned int count)
>  		struct device *dev = ctx->dev->dev;
>  		int ret;
>  
> -		ret = pm_runtime_get_sync(dev);
> +		ret = pm_runtime_resume_and_get(dev);
>  		if (ret < 0) {
>  			dev_err(dev, "Failed to enable module\n");
>  


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 21/79] staging: media: atomisp: use pm_runtime_resume_and_get()
  2021-04-28 14:51   ` Mauro Carvalho Chehab
@ 2021-04-30 16:59     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:59 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Sakari Ailus, devel, linux-kernel,
	linux-media

On Wed, 28 Apr 2021 16:51:42 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.

I'd mention that the origin error handling order was wrong and you've
also fixed that by moving hm_pool_unregister() later.

> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/staging/media/atomisp/pci/atomisp_fops.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp_fops.c
> index f1e6b2597853..26d05474a035 100644
> --- a/drivers/staging/media/atomisp/pci/atomisp_fops.c
> +++ b/drivers/staging/media/atomisp/pci/atomisp_fops.c
> @@ -837,7 +837,7 @@ static int atomisp_open(struct file *file)
>  	}
>  
>  	/* runtime power management, turn on ISP */
> -	ret = pm_runtime_get_sync(vdev->v4l2_dev->dev);
> +	ret = pm_runtime_resume_and_get(vdev->v4l2_dev->dev);
>  	if (ret < 0) {
>  		dev_err(isp->dev, "Failed to power on device\n");
>  		goto error;
> @@ -881,9 +881,9 @@ static int atomisp_open(struct file *file)
>  

>  css_error:
>  	atomisp_css_uninit(isp);
> -error:
> -	hmm_pool_unregister(HMM_POOL_TYPE_DYNAMIC);
>  	pm_runtime_put(vdev->v4l2_dev->dev);
> +error:
> +	hmm_pool_unregister(HMM_POOL_TYPE_DYNAMIC);
>  	rt_mutex_unlock(&isp->mutex);
>  	return ret;
>  }


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 21/79] staging: media: atomisp: use pm_runtime_resume_and_get()
@ 2021-04-30 16:59     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 16:59 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel, Sakari Ailus,
	mauro.chehab, Mauro Carvalho Chehab, linux-media

On Wed, 28 Apr 2021 16:51:42 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.

I'd mention that the origin error handling order was wrong and you've
also fixed that by moving hm_pool_unregister() later.

> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/staging/media/atomisp/pci/atomisp_fops.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp_fops.c
> index f1e6b2597853..26d05474a035 100644
> --- a/drivers/staging/media/atomisp/pci/atomisp_fops.c
> +++ b/drivers/staging/media/atomisp/pci/atomisp_fops.c
> @@ -837,7 +837,7 @@ static int atomisp_open(struct file *file)
>  	}
>  
>  	/* runtime power management, turn on ISP */
> -	ret = pm_runtime_get_sync(vdev->v4l2_dev->dev);
> +	ret = pm_runtime_resume_and_get(vdev->v4l2_dev->dev);
>  	if (ret < 0) {
>  		dev_err(isp->dev, "Failed to power on device\n");
>  		goto error;
> @@ -881,9 +881,9 @@ static int atomisp_open(struct file *file)
>  

>  css_error:
>  	atomisp_css_uninit(isp);
> -error:
> -	hmm_pool_unregister(HMM_POOL_TYPE_DYNAMIC);
>  	pm_runtime_put(vdev->v4l2_dev->dev);
> +error:
> +	hmm_pool_unregister(HMM_POOL_TYPE_DYNAMIC);
>  	rt_mutex_unlock(&isp->mutex);
>  	return ret;
>  }

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 23/79] staging: media: ipu3: use pm_runtime_resume_and_get()
  2021-04-28 14:51   ` Mauro Carvalho Chehab
@ 2021-04-30 17:03     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:03 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Bingbu Cao, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Sakari Ailus, Tianshu Qiu, devel,
	linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:44 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
Could add that pm_runtime_put() should have been pm_runtime_put_noidle()
inorder to not potentially result in a call to runtime suspend when
we never resumed in the first place.

Otherwise reasonable cleanup.

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

> ---
>  drivers/staging/media/ipu3/ipu3.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c
> index ee1bba6bdcac..8e1e9e46e604 100644
> --- a/drivers/staging/media/ipu3/ipu3.c
> +++ b/drivers/staging/media/ipu3/ipu3.c
> @@ -392,10 +392,9 @@ int imgu_s_stream(struct imgu_device *imgu, int enable)
>  	}
>  
>  	/* Set Power */
> -	r = pm_runtime_get_sync(dev);
> +	r = pm_runtime_resume_and_get(dev);
>  	if (r < 0) {
>  		dev_err(dev, "failed to set imgu power\n");
> -		pm_runtime_put(dev);
>  		return r;
>  	}
>  


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 23/79] staging: media: ipu3: use pm_runtime_resume_and_get()
@ 2021-04-30 17:03     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:03 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel, Sakari Ailus,
	mauro.chehab, Bingbu Cao, Mauro Carvalho Chehab, Tianshu Qiu,
	linux-media

On Wed, 28 Apr 2021 16:51:44 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
Could add that pm_runtime_put() should have been pm_runtime_put_noidle()
inorder to not potentially result in a call to runtime suspend when
we never resumed in the first place.

Otherwise reasonable cleanup.

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

> ---
>  drivers/staging/media/ipu3/ipu3.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c
> index ee1bba6bdcac..8e1e9e46e604 100644
> --- a/drivers/staging/media/ipu3/ipu3.c
> +++ b/drivers/staging/media/ipu3/ipu3.c
> @@ -392,10 +392,9 @@ int imgu_s_stream(struct imgu_device *imgu, int enable)
>  	}
>  
>  	/* Set Power */
> -	r = pm_runtime_get_sync(dev);
> +	r = pm_runtime_resume_and_get(dev);
>  	if (r < 0) {
>  		dev_err(dev, "failed to set imgu power\n");
> -		pm_runtime_put(dev);
>  		return r;
>  	}
>  

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 24/79] staging: media: cedrus_video: use pm_runtime_resume_and_get()
  2021-04-28 14:51   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-30 17:05     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:05 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Chen-Yu Tsai, Greg Kroah-Hartman,
	Jernej Skrabec, Mauro Carvalho Chehab, Maxime Ripard,
	Paul Kocialkowski, devel, linux-arm-kernel, linux-kernel,
	linux-media

On Wed, 28 Apr 2021 16:51:45 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/staging/media/sunxi/cedrus/cedrus_video.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> index b62eb8e84057..9ddd789d0b1f 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> @@ -490,11 +490,9 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	}
>  
>  	if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
> -		ret = pm_runtime_get_sync(dev->dev);
> -		if (ret < 0) {
> -			pm_runtime_put_noidle(dev->dev);
> +		ret = pm_runtime_resume_and_get(dev->dev);
> +		if (ret < 0)
>  			goto err_cleanup;
> -		}
>  
>  		if (dev->dec_ops[ctx->current_codec]->start) {
>  			ret = dev->dec_ops[ctx->current_codec]->start(ctx);


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 24/79] staging: media: cedrus_video: use pm_runtime_resume_and_get()
@ 2021-04-30 17:05     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:05 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Jernej Skrabec, Greg Kroah-Hartman, linuxarm,
	Maxime Ripard, linux-kernel, Paul Kocialkowski, Chen-Yu Tsai,
	mauro.chehab, Mauro Carvalho Chehab, linux-arm-kernel,
	linux-media

On Wed, 28 Apr 2021 16:51:45 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/staging/media/sunxi/cedrus/cedrus_video.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> index b62eb8e84057..9ddd789d0b1f 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> @@ -490,11 +490,9 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	}
>  
>  	if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
> -		ret = pm_runtime_get_sync(dev->dev);
> -		if (ret < 0) {
> -			pm_runtime_put_noidle(dev->dev);
> +		ret = pm_runtime_resume_and_get(dev->dev);
> +		if (ret < 0)
>  			goto err_cleanup;
> -		}
>  
>  		if (dev->dec_ops[ctx->current_codec]->start) {
>  			ret = dev->dec_ops[ctx->current_codec]->start(ctx);

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 24/79] staging: media: cedrus_video: use pm_runtime_resume_and_get()
@ 2021-04-30 17:05     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:05 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Chen-Yu Tsai, Greg Kroah-Hartman,
	Jernej Skrabec, Mauro Carvalho Chehab, Maxime Ripard,
	Paul Kocialkowski, devel, linux-arm-kernel, linux-kernel,
	linux-media

On Wed, 28 Apr 2021 16:51:45 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/staging/media/sunxi/cedrus/cedrus_video.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> index b62eb8e84057..9ddd789d0b1f 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
> @@ -490,11 +490,9 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	}
>  
>  	if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
> -		ret = pm_runtime_get_sync(dev->dev);
> -		if (ret < 0) {
> -			pm_runtime_put_noidle(dev->dev);
> +		ret = pm_runtime_resume_and_get(dev->dev);
> +		if (ret < 0)
>  			goto err_cleanup;
> -		}
>  
>  		if (dev->dec_ops[ctx->current_codec]->start) {
>  			ret = dev->dec_ops[ctx->current_codec]->start(ctx);


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 25/79] staging: media: tegra-vde: use pm_runtime_resume_and_get()
  2021-04-28 14:51   ` Mauro Carvalho Chehab
@ 2021-04-30 17:08     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:08 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Dmitry Osipenko, Greg Kroah-Hartman,
	Jonathan Hunter, Mauro Carvalho Chehab, Thierry Reding, devel,
	linux-kernel, linux-media, linux-tegra

On Wed, 28 Apr 2021 16:51:46 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
LGTM

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

> ---
>  drivers/staging/media/tegra-vde/vde.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
> index 28845b5bafaf..1cdacb3f781c 100644
> --- a/drivers/staging/media/tegra-vde/vde.c
> +++ b/drivers/staging/media/tegra-vde/vde.c
> @@ -775,9 +775,9 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
>  	if (ret)
>  		goto release_dpb_frames;
>  
> -	ret = pm_runtime_get_sync(dev);
> +	ret = pm_runtime_resume_and_get(dev);
>  	if (ret < 0)
> -		goto put_runtime_pm;
> +		goto unlock;
>  
>  	/*
>  	 * We rely on the VDE registers reset value, otherwise VDE
> @@ -843,6 +843,8 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
>  put_runtime_pm:
>  	pm_runtime_mark_last_busy(dev);
>  	pm_runtime_put_autosuspend(dev);
> +
> +unlock:
>  	mutex_unlock(&vde->lock);
>  
>  release_dpb_frames:
> @@ -1069,11 +1071,17 @@ static int tegra_vde_probe(struct platform_device *pdev)
>  	 * power-cycle it in order to put hardware into a predictable lower
>  	 * power state.
>  	 */
> -	pm_runtime_get_sync(dev);
> +	if (pm_runtime_resume_and_get(dev) < 0)
> +		goto err_pm_runtime;
> +
>  	pm_runtime_put(dev);
>  
>  	return 0;
>  
> +err_pm_runtime:
> +	pm_runtime_dont_use_autosuspend(dev);
> +	pm_runtime_disable(dev);
> +
>  err_deinit_iommu:
>  	tegra_vde_iommu_deinit(vde);
>  
> @@ -1089,7 +1097,12 @@ static int tegra_vde_remove(struct platform_device *pdev)
>  	struct tegra_vde *vde = platform_get_drvdata(pdev);
>  	struct device *dev = &pdev->dev;
>  
> +	/*
> +	 * As it increments RPM usage_count even on errors, we don't need to
> +	 * check the returned code here.
> +	 */
>  	pm_runtime_get_sync(dev);
> +
>  	pm_runtime_dont_use_autosuspend(dev);
>  	pm_runtime_disable(dev);
>  


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 25/79] staging: media: tegra-vde: use pm_runtime_resume_and_get()
@ 2021-04-30 17:08     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:08 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, Jonathan Hunter,
	linux-tegra, Thierry Reding, mauro.chehab, Dmitry Osipenko,
	Mauro Carvalho Chehab, linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:46 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
LGTM

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

> ---
>  drivers/staging/media/tegra-vde/vde.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
> index 28845b5bafaf..1cdacb3f781c 100644
> --- a/drivers/staging/media/tegra-vde/vde.c
> +++ b/drivers/staging/media/tegra-vde/vde.c
> @@ -775,9 +775,9 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
>  	if (ret)
>  		goto release_dpb_frames;
>  
> -	ret = pm_runtime_get_sync(dev);
> +	ret = pm_runtime_resume_and_get(dev);
>  	if (ret < 0)
> -		goto put_runtime_pm;
> +		goto unlock;
>  
>  	/*
>  	 * We rely on the VDE registers reset value, otherwise VDE
> @@ -843,6 +843,8 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
>  put_runtime_pm:
>  	pm_runtime_mark_last_busy(dev);
>  	pm_runtime_put_autosuspend(dev);
> +
> +unlock:
>  	mutex_unlock(&vde->lock);
>  
>  release_dpb_frames:
> @@ -1069,11 +1071,17 @@ static int tegra_vde_probe(struct platform_device *pdev)
>  	 * power-cycle it in order to put hardware into a predictable lower
>  	 * power state.
>  	 */
> -	pm_runtime_get_sync(dev);
> +	if (pm_runtime_resume_and_get(dev) < 0)
> +		goto err_pm_runtime;
> +
>  	pm_runtime_put(dev);
>  
>  	return 0;
>  
> +err_pm_runtime:
> +	pm_runtime_dont_use_autosuspend(dev);
> +	pm_runtime_disable(dev);
> +
>  err_deinit_iommu:
>  	tegra_vde_iommu_deinit(vde);
>  
> @@ -1089,7 +1097,12 @@ static int tegra_vde_remove(struct platform_device *pdev)
>  	struct tegra_vde *vde = platform_get_drvdata(pdev);
>  	struct device *dev = &pdev->dev;
>  
> +	/*
> +	 * As it increments RPM usage_count even on errors, we don't need to
> +	 * check the returned code here.
> +	 */
>  	pm_runtime_get_sync(dev);
> +
>  	pm_runtime_dont_use_autosuspend(dev);
>  	pm_runtime_disable(dev);
>  

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 25/79] staging: media: tegra-vde: use pm_runtime_resume_and_get()
  2021-04-30 17:08     ` Jonathan Cameron
@ 2021-04-30 17:11       ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Dmitry Osipenko, Greg Kroah-Hartman,
	Jonathan Hunter, Mauro Carvalho Chehab, Thierry Reding, devel,
	linux-kernel, linux-media, linux-tegra

On Fri, 30 Apr 2021 18:08:36 +0100
Jonathan Cameron <Jonathan.Cameron@Huawei.com> wrote:

> On Wed, 28 Apr 2021 16:51:46 +0200
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
> LGTM
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drop that.  I missed the misc unwind thing caught in the other review.
Too many patches without a break :(
> 
> > ---
> >  drivers/staging/media/tegra-vde/vde.c | 19 ++++++++++++++++---
> >  1 file changed, 16 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
> > index 28845b5bafaf..1cdacb3f781c 100644
> > --- a/drivers/staging/media/tegra-vde/vde.c
> > +++ b/drivers/staging/media/tegra-vde/vde.c
> > @@ -775,9 +775,9 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
> >  	if (ret)
> >  		goto release_dpb_frames;
> >  
> > -	ret = pm_runtime_get_sync(dev);
> > +	ret = pm_runtime_resume_and_get(dev);
> >  	if (ret < 0)
> > -		goto put_runtime_pm;
> > +		goto unlock;
> >  
> >  	/*
> >  	 * We rely on the VDE registers reset value, otherwise VDE
> > @@ -843,6 +843,8 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
> >  put_runtime_pm:
> >  	pm_runtime_mark_last_busy(dev);
> >  	pm_runtime_put_autosuspend(dev);
> > +
> > +unlock:
> >  	mutex_unlock(&vde->lock);
> >  
> >  release_dpb_frames:
> > @@ -1069,11 +1071,17 @@ static int tegra_vde_probe(struct platform_device *pdev)
> >  	 * power-cycle it in order to put hardware into a predictable lower
> >  	 * power state.
> >  	 */
> > -	pm_runtime_get_sync(dev);
> > +	if (pm_runtime_resume_and_get(dev) < 0)
> > +		goto err_pm_runtime;
> > +
> >  	pm_runtime_put(dev);
> >  
> >  	return 0;
> >  
> > +err_pm_runtime:
> > +	pm_runtime_dont_use_autosuspend(dev);
> > +	pm_runtime_disable(dev);
> > +
> >  err_deinit_iommu:
> >  	tegra_vde_iommu_deinit(vde);
> >  
> > @@ -1089,7 +1097,12 @@ static int tegra_vde_remove(struct platform_device *pdev)
> >  	struct tegra_vde *vde = platform_get_drvdata(pdev);
> >  	struct device *dev = &pdev->dev;
> >  
> > +	/*
> > +	 * As it increments RPM usage_count even on errors, we don't need to
> > +	 * check the returned code here.
> > +	 */
> >  	pm_runtime_get_sync(dev);
> > +
> >  	pm_runtime_dont_use_autosuspend(dev);
> >  	pm_runtime_disable(dev);
> >  
> 


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 25/79] staging: media: tegra-vde: use pm_runtime_resume_and_get()
@ 2021-04-30 17:11       ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, Jonathan Hunter,
	linux-tegra, Thierry Reding, mauro.chehab, Dmitry Osipenko,
	Mauro Carvalho Chehab, linux-kernel, linux-media

On Fri, 30 Apr 2021 18:08:36 +0100
Jonathan Cameron <Jonathan.Cameron@Huawei.com> wrote:

> On Wed, 28 Apr 2021 16:51:46 +0200
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
> LGTM
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drop that.  I missed the misc unwind thing caught in the other review.
Too many patches without a break :(
> 
> > ---
> >  drivers/staging/media/tegra-vde/vde.c | 19 ++++++++++++++++---
> >  1 file changed, 16 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
> > index 28845b5bafaf..1cdacb3f781c 100644
> > --- a/drivers/staging/media/tegra-vde/vde.c
> > +++ b/drivers/staging/media/tegra-vde/vde.c
> > @@ -775,9 +775,9 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
> >  	if (ret)
> >  		goto release_dpb_frames;
> >  
> > -	ret = pm_runtime_get_sync(dev);
> > +	ret = pm_runtime_resume_and_get(dev);
> >  	if (ret < 0)
> > -		goto put_runtime_pm;
> > +		goto unlock;
> >  
> >  	/*
> >  	 * We rely on the VDE registers reset value, otherwise VDE
> > @@ -843,6 +843,8 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
> >  put_runtime_pm:
> >  	pm_runtime_mark_last_busy(dev);
> >  	pm_runtime_put_autosuspend(dev);
> > +
> > +unlock:
> >  	mutex_unlock(&vde->lock);
> >  
> >  release_dpb_frames:
> > @@ -1069,11 +1071,17 @@ static int tegra_vde_probe(struct platform_device *pdev)
> >  	 * power-cycle it in order to put hardware into a predictable lower
> >  	 * power state.
> >  	 */
> > -	pm_runtime_get_sync(dev);
> > +	if (pm_runtime_resume_and_get(dev) < 0)
> > +		goto err_pm_runtime;
> > +
> >  	pm_runtime_put(dev);
> >  
> >  	return 0;
> >  
> > +err_pm_runtime:
> > +	pm_runtime_dont_use_autosuspend(dev);
> > +	pm_runtime_disable(dev);
> > +
> >  err_deinit_iommu:
> >  	tegra_vde_iommu_deinit(vde);
> >  
> > @@ -1089,7 +1097,12 @@ static int tegra_vde_remove(struct platform_device *pdev)
> >  	struct tegra_vde *vde = platform_get_drvdata(pdev);
> >  	struct device *dev = &pdev->dev;
> >  
> > +	/*
> > +	 * As it increments RPM usage_count even on errors, we don't need to
> > +	 * check the returned code here.
> > +	 */
> >  	pm_runtime_get_sync(dev);
> > +
> >  	pm_runtime_dont_use_autosuspend(dev);
> >  	pm_runtime_disable(dev);
> >  
> 

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 26/79] staging: media: tegra-video: use pm_runtime_resume_and_get()
  2021-04-28 14:51   ` Mauro Carvalho Chehab
@ 2021-04-30 17:13     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:13 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman, Jonathan Hunter,
	Mauro Carvalho Chehab, Sowjanya Komatineni, Thierry Reding,
	devel, linux-kernel, linux-media, linux-tegra

On Wed, 28 Apr 2021 16:51:47 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
NOP patch so 
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/staging/media/tegra-video/csi.c | 3 +--
>  drivers/staging/media/tegra-video/vi.c  | 3 +--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
> index 033a6935c26d..e938bf4c48b6 100644
> --- a/drivers/staging/media/tegra-video/csi.c
> +++ b/drivers/staging/media/tegra-video/csi.c
> @@ -298,10 +298,9 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)
>  	struct tegra_csi *csi = csi_chan->csi;
>  	int ret, err;
>  
> -	ret = pm_runtime_get_sync(csi->dev);
> +	ret = pm_runtime_resume_and_get(csi->dev);
>  	if (ret < 0) {
>  		dev_err(csi->dev, "failed to get runtime PM: %d\n", ret);
> -		pm_runtime_put_noidle(csi->dev);
>  		return ret;
>  	}
>  
> diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
> index 7a09061cda57..1298740a9c6c 100644
> --- a/drivers/staging/media/tegra-video/vi.c
> +++ b/drivers/staging/media/tegra-video/vi.c
> @@ -297,10 +297,9 @@ static int tegra_channel_start_streaming(struct vb2_queue *vq, u32 count)
>  	struct tegra_vi_channel *chan = vb2_get_drv_priv(vq);
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(chan->vi->dev);
> +	ret = pm_runtime_resume_and_get(chan->vi->dev);
>  	if (ret < 0) {
>  		dev_err(chan->vi->dev, "failed to get runtime PM: %d\n", ret);
> -		pm_runtime_put_noidle(chan->vi->dev);
>  		return ret;
>  	}
>  


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 26/79] staging: media: tegra-video: use pm_runtime_resume_and_get()
@ 2021-04-30 17:13     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:13 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, Jonathan Hunter,
	linux-tegra, Thierry Reding, Sowjanya Komatineni, mauro.chehab,
	Mauro Carvalho Chehab, linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:47 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
NOP patch so 
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/staging/media/tegra-video/csi.c | 3 +--
>  drivers/staging/media/tegra-video/vi.c  | 3 +--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
> index 033a6935c26d..e938bf4c48b6 100644
> --- a/drivers/staging/media/tegra-video/csi.c
> +++ b/drivers/staging/media/tegra-video/csi.c
> @@ -298,10 +298,9 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)
>  	struct tegra_csi *csi = csi_chan->csi;
>  	int ret, err;
>  
> -	ret = pm_runtime_get_sync(csi->dev);
> +	ret = pm_runtime_resume_and_get(csi->dev);
>  	if (ret < 0) {
>  		dev_err(csi->dev, "failed to get runtime PM: %d\n", ret);
> -		pm_runtime_put_noidle(csi->dev);
>  		return ret;
>  	}
>  
> diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
> index 7a09061cda57..1298740a9c6c 100644
> --- a/drivers/staging/media/tegra-video/vi.c
> +++ b/drivers/staging/media/tegra-video/vi.c
> @@ -297,10 +297,9 @@ static int tegra_channel_start_streaming(struct vb2_queue *vq, u32 count)
>  	struct tegra_vi_channel *chan = vb2_get_drv_priv(vq);
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(chan->vi->dev);
> +	ret = pm_runtime_resume_and_get(chan->vi->dev);
>  	if (ret < 0) {
>  		dev_err(chan->vi->dev, "failed to get runtime PM: %d\n", ret);
> -		pm_runtime_put_noidle(chan->vi->dev);
>  		return ret;
>  	}
>  

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 27/79] media: i2c: ak7375: use pm_runtime_resume_and_get()
  2021-04-28 14:51 ` [PATCH v4 27/79] media: i2c: ak7375: " Mauro Carvalho Chehab
@ 2021-04-30 17:14   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:14 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Tianshu Qiu,
	linux-kernel, linux-media

On Wed, 28 Apr 2021 16:51:48 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/media/i2c/ak7375.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c
> index e1f94ee0f48f..40b1a4aa846c 100644
> --- a/drivers/media/i2c/ak7375.c
> +++ b/drivers/media/i2c/ak7375.c
> @@ -87,15 +87,7 @@ static const struct v4l2_ctrl_ops ak7375_vcm_ctrl_ops = {
>  
>  static int ak7375_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
>  {
> -	int ret;
> -
> -	ret = pm_runtime_get_sync(sd->dev);
> -	if (ret < 0) {
> -		pm_runtime_put_noidle(sd->dev);
> -		return ret;
> -	}
> -
> -	return 0;
> +	return pm_runtime_resume_and_get(sd->dev);
>  }
>  
>  static int ak7375_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 45/79] media: i2c: ov2740: use pm_runtime_resume_and_get()
  2021-04-28 14:52 ` [PATCH v4 45/79] media: i2c: ov2740: " Mauro Carvalho Chehab
@ 2021-04-30 17:20   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Bingbu Cao, Mauro Carvalho Chehab,
	Shawn Tu, Tianshu Qiu, linux-kernel, linux-media

On Wed, 28 Apr 2021 16:52:06 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
Trivial inline.  Otherwise
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


> ---
>  drivers/media/i2c/ov2740.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
> index 0f3f17f3c426..54779f720f9d 100644
> --- a/drivers/media/i2c/ov2740.c
> +++ b/drivers/media/i2c/ov2740.c
> @@ -751,9 +751,8 @@ static int ov2740_set_stream(struct v4l2_subdev *sd, int enable)
>  
>  	mutex_lock(&ov2740->mutex);
>  	if (enable) {
> -		ret = pm_runtime_get_sync(&client->dev);
> +		ret = pm_runtime_resume_and_get(&client->dev);
>  		if (ret < 0) {
> -			pm_runtime_put_noidle(&client->dev);
>  			mutex_unlock(&ov2740->mutex);
>  			return ret;
>  		}
> @@ -1049,9 +1048,8 @@ static int ov2740_nvmem_read(void *priv, unsigned int off, void *val,
>  		goto exit;
>  	}
>  
> -	ret = pm_runtime_get_sync(dev);
> +	ret = pm_runtime_resume_and_get(dev);
>  	if (ret < 0) {

Drop the brackets?

> -		pm_runtime_put_noidle(dev);
>  		goto exit;
>  	}
>  


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 58/79] media: sti/hva: use pm_runtime_resume_and_get()
  2021-04-28 14:52 ` [PATCH v4 58/79] media: sti/hva: " Mauro Carvalho Chehab
@ 2021-04-30 17:35   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:35 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Jean-Christophe Trotin,
	Mauro Carvalho Chehab, linux-kernel, linux-media

On Wed, 28 Apr 2021 16:52:19 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
> 
> While the hva driver does it right, there are lots of errors
> on other drivers due to its misusage. So, let's change
> this driver to also use pm_runtime_resume_and_get(), as we're
> doing similar changes all over the media subsystem.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Bit of a fiddly one, but looks right to me.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/media/platform/sti/hva/hva-hw.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/platform/sti/hva/hva-hw.c b/drivers/media/platform/sti/hva/hva-hw.c
> index f59811e27f51..77b8bfa5e0c5 100644
> --- a/drivers/media/platform/sti/hva/hva-hw.c
> +++ b/drivers/media/platform/sti/hva/hva-hw.c
> @@ -270,9 +270,8 @@ static unsigned long int hva_hw_get_ip_version(struct hva_dev *hva)
>  	struct device *dev = hva_to_dev(hva);
>  	unsigned long int version;
>  
> -	if (pm_runtime_get_sync(dev) < 0) {
> +	if (pm_runtime_resume_and_get(dev) < 0) {
>  		dev_err(dev, "%s     failed to get pm_runtime\n", HVA_PREFIX);
> -		pm_runtime_put_noidle(dev);
>  		mutex_unlock(&hva->protect_mutex);
>  		return -EFAULT;
>  	}
> @@ -386,10 +385,10 @@ int hva_hw_probe(struct platform_device *pdev, struct hva_dev *hva)
>  	pm_runtime_set_suspended(dev);
>  	pm_runtime_enable(dev);
>  
> -	ret = pm_runtime_get_sync(dev);
> +	ret = pm_runtime_resume_and_get(dev);
>  	if (ret < 0) {
>  		dev_err(dev, "%s     failed to set PM\n", HVA_PREFIX);
> -		goto err_pm;
> +		goto err_clk;
>  	}
>  
>  	/* check IP hardware version */
> @@ -462,6 +461,7 @@ int hva_hw_execute_task(struct hva_ctx *ctx, enum hva_hw_cmd_type cmd,
>  	u8 client_id = ctx->id;
>  	int ret;
>  	u32 reg = 0;
> +	bool got_pm = false;
>  
>  	mutex_lock(&hva->protect_mutex);
>  
> @@ -469,12 +469,13 @@ int hva_hw_execute_task(struct hva_ctx *ctx, enum hva_hw_cmd_type cmd,
>  	enable_irq(hva->irq_its);
>  	enable_irq(hva->irq_err);
>  
> -	if (pm_runtime_get_sync(dev) < 0) {
> +	if (pm_runtime_resume_and_get(dev) < 0) {
>  		dev_err(dev, "%s     failed to get pm_runtime\n", ctx->name);
>  		ctx->sys_errors++;
>  		ret = -EFAULT;
>  		goto out;
>  	}
> +	got_pm = true;
>  
>  	reg = readl_relaxed(hva->regs + HVA_HIF_REG_CLK_GATING);
>  	switch (cmd) {
> @@ -537,7 +538,8 @@ int hva_hw_execute_task(struct hva_ctx *ctx, enum hva_hw_cmd_type cmd,
>  		dev_dbg(dev, "%s     unknown command 0x%x\n", ctx->name, cmd);
>  	}
>  
> -	pm_runtime_put_autosuspend(dev);
> +	if (got_pm)
> +		pm_runtime_put_autosuspend(dev);
>  	mutex_unlock(&hva->protect_mutex);
>  
>  	return ret;
> @@ -553,9 +555,8 @@ void hva_hw_dump_regs(struct hva_dev *hva, struct seq_file *s)
>  
>  	mutex_lock(&hva->protect_mutex);
>  
> -	if (pm_runtime_get_sync(dev) < 0) {
> +	if (pm_runtime_resume_and_get(dev) < 0) {
>  		seq_puts(s, "Cannot wake up IP\n");
> -		pm_runtime_put_noidle(dev);
>  		mutex_unlock(&hva->protect_mutex);
>  		return;
>  	}


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 62/79] media: exynos4-is: use pm_runtime_resume_and_get()
  2021-04-28 14:52   ` Mauro Carvalho Chehab
@ 2021-04-30 17:49     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:49 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Krzysztof Kozlowski,
	Mauro Carvalho Chehab, Sylwester Nawrocki, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

On Wed, 28 Apr 2021 16:52:23 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
> 
> Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
> 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        | 4 ++--
>  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      | 8 +++-----
>  8 files changed, 18 insertions(+), 25 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..1b24f5bfc4af 100644
> --- a/drivers/media/platform/exynos4-is/fimc-is.c
> +++ b/drivers/media/platform/exynos4-is/fimc-is.c
> @@ -828,9 +828,9 @@ 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;
> +		goto err_irq;
>  

I think the pm_runtime_put_noidle() below err_pm: should become
a pm_runtime_put() because otherwise we won't call fimc_is_runtime_suspend()
if runtime pm is enabled (either directly or via runtime pm count becoming zero.

(not I'm not 100% sure of my argument here...)

>  	vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));
>  
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> index 612b9872afc8..8d9dc597deaa 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -275,7 +275,7 @@ static int isp_video_open(struct file *file)
>  	if (ret < 0)
>  		goto unlock;
>  
> -	ret = pm_runtime_get_sync(&isp->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&isp->pdev->dev);
>  	if (ret < 0)
>  		goto rel_fh;
>  
> @@ -293,7 +293,6 @@ static int isp_video_open(struct file *file)
>  	if (!ret)
>  		goto unlock;

So the good path is to jump over the block.  I'd just unlock and return here
to make it more readable but unrelated to this patch.

>  rel_fh:
> -	pm_runtime_put_noidle(&isp->pdev->dev);

Logic flow here isn't very standard, but with this change, you'll not
call anything to unwind a successful call to pm_runtime_resume_and_get if
fmic_pipeline_call() returns and error.
My guess is pm_runtime_put_sync() is needed before rel_fh; to balance this.
 
>  	v4l2_fh_release(file);
>  unlock:
>  	mutex_unlock(&isp->video_lock);
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c
> index a77c49b18511..74b49d30901e 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp.c
> @@ -304,11 +304,10 @@ static int fimc_isp_subdev_s_power(struct v4l2_subdev *sd, int on)
>  	pr_debug("on: %d\n", on);
>  
>  	if (on) {
> -		ret = pm_runtime_get_sync(&is->pdev->dev);
> -		if (ret < 0) {
> -			pm_runtime_put(&is->pdev->dev);
> +		ret = pm_runtime_resume_and_get(&is->pdev->dev);
> +		if (ret < 0)
>  			return ret;
> -		}
> +
>  		set_bit(IS_ST_PWR_ON, &is->state);
>  
>  		ret = fimc_is_start_firmware(is);
> diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> index fe20af3a7178..4d8b18078ff3 100644
> --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> @@ -469,9 +469,9 @@ static int fimc_lite_open(struct file *file)
>  	}
>  
>  	set_bit(ST_FLITE_IN_USE, &fimc->state);
> -	ret = pm_runtime_get_sync(&fimc->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
>  	if (ret < 0)
> -		goto err_pm;
> +		goto err_in_use;
>  
>  	ret = v4l2_fh_open(file);
>  	if (ret < 0)
> @@ -499,6 +499,7 @@ static int fimc_lite_open(struct file *file)
>  	v4l2_fh_release(file);
>  err_pm:
>  	pm_runtime_put_sync(&fimc->pdev->dev);
> +err_in_use:
>  	clear_bit(ST_FLITE_IN_USE, &fimc->state);
>  unlock:
>  	mutex_unlock(&fimc->lock);
> diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
> index c9704a147e5c..7c1eb05c508f 100644
> --- a/drivers/media/platform/exynos4-is/fimc-m2m.c
> +++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
> @@ -75,7 +75,7 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
>  	struct fimc_ctx *ctx = q->drv_priv;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(&ctx->fimc_dev->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&ctx->fimc_dev->pdev->dev);
Use the fact pm_runtime_resume_and_get only returns 0 or < 0 to
make this
return pm_runtime_resume_and_get()

>  	return ret > 0 ? 0 : ret;
>  }
>  
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> index 13d192ba4aa6..9346d44a06c2 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -512,11 +512,9 @@ static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
>  	if (!fmd->pmf)
>  		return -ENXIO;
>  
> -	ret = pm_runtime_get_sync(fmd->pmf);
> -	if (ret < 0) {
> -		pm_runtime_put(fmd->pmf);
> +	ret = pm_runtime_resume_and_get(fmd->pmf);
> +	if (ret < 0)
>  		return ret;
> -	}
>  
>  	fmd->num_sensors = 0;
>  
> @@ -1291,7 +1289,7 @@ static int cam_clk_prepare(struct clk_hw *hw)
>  	if (camclk->fmd->pmf == NULL)
>  		return -ENODEV;
>  
> -	ret = pm_runtime_get_sync(camclk->fmd->pmf);
> +	ret = pm_runtime_resume_and_get(camclk->fmd->pmf);
return pm_...

>  	return ret < 0 ? ret : 0;
>  }
>  
> diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
> index 1aac167abb17..2a6afb78a049 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,11 +509,9 @@ 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);
> -		if (ret && ret != 1) {
> -			pm_runtime_put_noidle(&state->pdev->dev);
> +		ret = pm_runtime_resume_and_get(&state->pdev->dev);
> +		if (ret && ret != 1)

It won't be equal to 1 as pm_runtime_resume_and_get only returns <= 0

>  			return ret;
> -		}
>  	}
>  
>  	mutex_lock(&state->lock);


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 62/79] media: exynos4-is: use pm_runtime_resume_and_get()
@ 2021-04-30 17:49     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:49 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Krzysztof Kozlowski,
	Mauro Carvalho Chehab, Sylwester Nawrocki, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

On Wed, 28 Apr 2021 16:52:23 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
> 
> Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
> 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        | 4 ++--
>  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      | 8 +++-----
>  8 files changed, 18 insertions(+), 25 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..1b24f5bfc4af 100644
> --- a/drivers/media/platform/exynos4-is/fimc-is.c
> +++ b/drivers/media/platform/exynos4-is/fimc-is.c
> @@ -828,9 +828,9 @@ 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;
> +		goto err_irq;
>  

I think the pm_runtime_put_noidle() below err_pm: should become
a pm_runtime_put() because otherwise we won't call fimc_is_runtime_suspend()
if runtime pm is enabled (either directly or via runtime pm count becoming zero.

(not I'm not 100% sure of my argument here...)

>  	vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));
>  
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> index 612b9872afc8..8d9dc597deaa 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
> @@ -275,7 +275,7 @@ static int isp_video_open(struct file *file)
>  	if (ret < 0)
>  		goto unlock;
>  
> -	ret = pm_runtime_get_sync(&isp->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&isp->pdev->dev);
>  	if (ret < 0)
>  		goto rel_fh;
>  
> @@ -293,7 +293,6 @@ static int isp_video_open(struct file *file)
>  	if (!ret)
>  		goto unlock;

So the good path is to jump over the block.  I'd just unlock and return here
to make it more readable but unrelated to this patch.

>  rel_fh:
> -	pm_runtime_put_noidle(&isp->pdev->dev);

Logic flow here isn't very standard, but with this change, you'll not
call anything to unwind a successful call to pm_runtime_resume_and_get if
fmic_pipeline_call() returns and error.
My guess is pm_runtime_put_sync() is needed before rel_fh; to balance this.
 
>  	v4l2_fh_release(file);
>  unlock:
>  	mutex_unlock(&isp->video_lock);
> diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c
> index a77c49b18511..74b49d30901e 100644
> --- a/drivers/media/platform/exynos4-is/fimc-isp.c
> +++ b/drivers/media/platform/exynos4-is/fimc-isp.c
> @@ -304,11 +304,10 @@ static int fimc_isp_subdev_s_power(struct v4l2_subdev *sd, int on)
>  	pr_debug("on: %d\n", on);
>  
>  	if (on) {
> -		ret = pm_runtime_get_sync(&is->pdev->dev);
> -		if (ret < 0) {
> -			pm_runtime_put(&is->pdev->dev);
> +		ret = pm_runtime_resume_and_get(&is->pdev->dev);
> +		if (ret < 0)
>  			return ret;
> -		}
> +
>  		set_bit(IS_ST_PWR_ON, &is->state);
>  
>  		ret = fimc_is_start_firmware(is);
> diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
> index fe20af3a7178..4d8b18078ff3 100644
> --- a/drivers/media/platform/exynos4-is/fimc-lite.c
> +++ b/drivers/media/platform/exynos4-is/fimc-lite.c
> @@ -469,9 +469,9 @@ static int fimc_lite_open(struct file *file)
>  	}
>  
>  	set_bit(ST_FLITE_IN_USE, &fimc->state);
> -	ret = pm_runtime_get_sync(&fimc->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
>  	if (ret < 0)
> -		goto err_pm;
> +		goto err_in_use;
>  
>  	ret = v4l2_fh_open(file);
>  	if (ret < 0)
> @@ -499,6 +499,7 @@ static int fimc_lite_open(struct file *file)
>  	v4l2_fh_release(file);
>  err_pm:
>  	pm_runtime_put_sync(&fimc->pdev->dev);
> +err_in_use:
>  	clear_bit(ST_FLITE_IN_USE, &fimc->state);
>  unlock:
>  	mutex_unlock(&fimc->lock);
> diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
> index c9704a147e5c..7c1eb05c508f 100644
> --- a/drivers/media/platform/exynos4-is/fimc-m2m.c
> +++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
> @@ -75,7 +75,7 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
>  	struct fimc_ctx *ctx = q->drv_priv;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(&ctx->fimc_dev->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&ctx->fimc_dev->pdev->dev);
Use the fact pm_runtime_resume_and_get only returns 0 or < 0 to
make this
return pm_runtime_resume_and_get()

>  	return ret > 0 ? 0 : ret;
>  }
>  
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> index 13d192ba4aa6..9346d44a06c2 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -512,11 +512,9 @@ static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
>  	if (!fmd->pmf)
>  		return -ENXIO;
>  
> -	ret = pm_runtime_get_sync(fmd->pmf);
> -	if (ret < 0) {
> -		pm_runtime_put(fmd->pmf);
> +	ret = pm_runtime_resume_and_get(fmd->pmf);
> +	if (ret < 0)
>  		return ret;
> -	}
>  
>  	fmd->num_sensors = 0;
>  
> @@ -1291,7 +1289,7 @@ static int cam_clk_prepare(struct clk_hw *hw)
>  	if (camclk->fmd->pmf == NULL)
>  		return -ENODEV;
>  
> -	ret = pm_runtime_get_sync(camclk->fmd->pmf);
> +	ret = pm_runtime_resume_and_get(camclk->fmd->pmf);
return pm_...

>  	return ret < 0 ? ret : 0;
>  }
>  
> diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
> index 1aac167abb17..2a6afb78a049 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,11 +509,9 @@ 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);
> -		if (ret && ret != 1) {
> -			pm_runtime_put_noidle(&state->pdev->dev);
> +		ret = pm_runtime_resume_and_get(&state->pdev->dev);
> +		if (ret && ret != 1)

It won't be equal to 1 as pm_runtime_resume_and_get only returns <= 0

>  			return ret;
> -		}
>  	}
>  
>  	mutex_lock(&state->lock);


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 63/79] media: exynos-gsc: use pm_runtime_resume_and_get()
  2021-04-28 14:52   ` Mauro Carvalho Chehab
@ 2021-04-30 17:50     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, Sylwester Nawrocki,
	linux-arm-kernel, linux-kernel, linux-media, linux-samsung-soc

On Wed, 28 Apr 2021 16:52:24 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
> 
> Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
> index 27a3c92c73bc..09551e96ac15 100644
> --- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
> +++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
> @@ -58,7 +58,7 @@ static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
>  	struct gsc_ctx *ctx = q->drv_priv;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(&ctx->gsc_dev->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&ctx->gsc_dev->pdev->dev);
>  	return ret > 0 ? 0 : ret;
return pm_runtime_resume_and_get()

as
static inline int pm_runtime_resume_and_get(struct device *dev)
{
	int ret;

	ret = __pm_runtime_resume(dev, RPM_GET_PUT);
	if (ret < 0) {
		pm_runtime_put_noidle(dev);
		return ret;
	}

	return 0;
}

Can't return >= 0

>  }
>  


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 63/79] media: exynos-gsc: use pm_runtime_resume_and_get()
@ 2021-04-30 17:50     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, Sylwester Nawrocki,
	linux-arm-kernel, linux-kernel, linux-media, linux-samsung-soc

On Wed, 28 Apr 2021 16:52:24 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
> 
> Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
> index 27a3c92c73bc..09551e96ac15 100644
> --- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
> +++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
> @@ -58,7 +58,7 @@ static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
>  	struct gsc_ctx *ctx = q->drv_priv;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(&ctx->gsc_dev->pdev->dev);
> +	ret = pm_runtime_resume_and_get(&ctx->gsc_dev->pdev->dev);
>  	return ret > 0 ? 0 : ret;
return pm_runtime_resume_and_get()

as
static inline int pm_runtime_resume_and_get(struct device *dev)
{
	int ret;

	ret = __pm_runtime_resume(dev, RPM_GET_PUT);
	if (ret < 0) {
		pm_runtime_put_noidle(dev);
		return ret;
	}

	return 0;
}

Can't return >= 0

>  }
>  


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 67/79] media: venus: vdec: use pm_runtime_resume_and_get()
  2021-04-28 14:52 ` [PATCH v4 67/79] media: venus: vdec: " Mauro Carvalho Chehab
@ 2021-04-30 17:53   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:53 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andy Gross, Bjorn Andersson,
	Mauro Carvalho Chehab, Stanimir Varbanov, linux-arm-msm,
	linux-kernel, linux-media

On Wed, 28 Apr 2021 16:52:28 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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/qcom/venus/vdec.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
> index ddb7cd39424e..347e533ea673 100644
> --- a/drivers/media/platform/qcom/venus/vdec.c
> +++ b/drivers/media/platform/qcom/venus/vdec.c
> @@ -568,7 +568,7 @@ static int vdec_pm_get(struct venus_inst *inst)
>  	int ret;
>  
>  	mutex_lock(&core->pm_lock);
> -	ret = pm_runtime_get_sync(dev);
> +	ret = pm_runtime_resume_and_get(dev);
>  	mutex_unlock(&core->pm_lock);
>  
>  	return ret < 0 ? ret : 0;
Don't need this dance any more due to " Return 0 if the runtime PM usage counter of @dev has been
 * incremented or a negative error code otherwise."
return ret;

> @@ -601,7 +601,7 @@ static int vdec_pm_get_put(struct venus_inst *inst)
>  	mutex_lock(&core->pm_lock);
>  
>  	if (pm_runtime_suspended(dev)) {
> -		ret = pm_runtime_get_sync(dev);
> +		ret = pm_runtime_resume_and_get(dev);
>  		if (ret < 0)
>  			goto error;
>  


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 73/79] media: stm32: use pm_runtime_resume_and_get()
  2021-04-28 14:52   ` Mauro Carvalho Chehab
@ 2021-04-30 17:58     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:58 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Alexandre Torgue, Hugues Fruchet,
	Mauro Carvalho Chehab, Maxime Coquelin, linux-arm-kernel,
	linux-kernel, linux-media, linux-stm32

On Wed, 28 Apr 2021 16:52:34 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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/stm32/stm32-dcmi.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
> index bbcc2254fa2e..5f4e1db8cfcd 100644
> --- a/drivers/media/platform/stm32/stm32-dcmi.c
> +++ b/drivers/media/platform/stm32/stm32-dcmi.c
> @@ -723,11 +723,11 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	u32 val = 0;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(dcmi->dev);
> +	ret = pm_runtime_resume_and_get(dcmi->dev);
>  	if (ret < 0) {
>  		dev_err(dcmi->dev, "%s: Failed to start streaming, cannot get sync (%d)\n",
>  			__func__, ret);
> -		goto err_pm_put;
> +		goto err_unlock;

maybe err_unlocked; to indicate the lock isn't held.  This briefly confused me.

>  	}
>  
>  	ret = media_pipeline_start(&dcmi->vdev->entity, &dcmi->pipeline);
> @@ -848,6 +848,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
>  
>  err_pm_put:
>  	pm_runtime_put(dcmi->dev);
> +err_unlock:
>  	spin_lock_irq(&dcmi->irqlock);
>  	/*
>  	 * Return all buffers to vb2 in QUEUED state.


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 73/79] media: stm32: use pm_runtime_resume_and_get()
@ 2021-04-30 17:58     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 17:58 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Alexandre Torgue, Hugues Fruchet,
	Mauro Carvalho Chehab, Maxime Coquelin, linux-arm-kernel,
	linux-kernel, linux-media, linux-stm32

On Wed, 28 Apr 2021 16:52:34 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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/stm32/stm32-dcmi.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
> index bbcc2254fa2e..5f4e1db8cfcd 100644
> --- a/drivers/media/platform/stm32/stm32-dcmi.c
> +++ b/drivers/media/platform/stm32/stm32-dcmi.c
> @@ -723,11 +723,11 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	u32 val = 0;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(dcmi->dev);
> +	ret = pm_runtime_resume_and_get(dcmi->dev);
>  	if (ret < 0) {
>  		dev_err(dcmi->dev, "%s: Failed to start streaming, cannot get sync (%d)\n",
>  			__func__, ret);
> -		goto err_pm_put;
> +		goto err_unlock;

maybe err_unlocked; to indicate the lock isn't held.  This briefly confused me.

>  	}
>  
>  	ret = media_pipeline_start(&dcmi->vdev->entity, &dcmi->pipeline);
> @@ -848,6 +848,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
>  
>  err_pm_put:
>  	pm_runtime_put(dcmi->dev);
> +err_unlock:
>  	spin_lock_irq(&dcmi->irqlock);
>  	/*
>  	 * Return all buffers to vb2 in QUEUED state.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 75/79] media: ti-vpe: use pm_runtime_resume_and_get()
  2021-04-28 14:52 ` [PATCH v4 75/79] media: ti-vpe: " Mauro Carvalho Chehab
@ 2021-04-30 18:03   ` Jonathan Cameron
  2021-05-03 12:49     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 18:03 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Benoit Parrot, Mauro Carvalho Chehab,
	linux-kernel, linux-media

On Wed, 28 Apr 2021 16:52:36 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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/ti-vpe/cal-video.c | 4 +++-
>  drivers/media/platform/ti-vpe/cal.c       | 8 +++++---
>  drivers/media/platform/ti-vpe/vpe.c       | 4 +---
>  3 files changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal-video.c b/drivers/media/platform/ti-vpe/cal-video.c
> index 7b7436a355ee..15fb5360cf13 100644
> --- a/drivers/media/platform/ti-vpe/cal-video.c
> +++ b/drivers/media/platform/ti-vpe/cal-video.c
> @@ -700,7 +700,9 @@ static int cal_start_streaming(struct vb2_queue *vq, unsigned int count)
>  
>  	addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
>  
> -	pm_runtime_get_sync(ctx->cal->dev);
> +	ret = pm_runtime_resume_and_get(ctx->cal->dev);
> +	if (ret < 0)
> +		goto error_pipeline;
>  
>  	cal_ctx_set_dma_addr(ctx, addr);
>  	cal_ctx_start(ctx);
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index 2e2bef91b2b0..76fe7a8b33f6 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -1024,7 +1024,7 @@ static int cal_probe(struct platform_device *pdev)
>  
>  	/* Read the revision and hardware info to verify hardware access. */
>  	pm_runtime_enable(&pdev->dev);
> -	ret = pm_runtime_get_sync(&pdev->dev);
> +	ret = pm_runtime_resume_and_get(&pdev->dev);
>  	if (ret)
>  		goto error_pm_runtime;
>  
> @@ -1098,10 +1098,11 @@ static int cal_remove(struct platform_device *pdev)
>  {
>  	struct cal_dev *cal = platform_get_drvdata(pdev);
>  	unsigned int i;
> +	int ret;
>  
>  	cal_dbg(1, cal, "Removing %s\n", CAL_MODULE_NAME);
>  
> -	pm_runtime_get_sync(&pdev->dev);
> +	ret = pm_runtime_resume_and_get(&pdev->dev);
>  
>  	cal_media_unregister(cal);
>  
> @@ -1115,7 +1116,8 @@ static int cal_remove(struct platform_device *pdev)
>  	for (i = 0; i < cal->data->num_csi2_phy; i++)
>  		cal_camerarx_destroy(cal->phy[i]);
>  
> -	pm_runtime_put_sync(&pdev->dev);
> +	if (ret >= 0)
> +		pm_runtime_put_sync(&pdev->dev);
>  	pm_runtime_disable(&pdev->dev);
>  
>  	return 0;
> diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
> index 10251b787674..07cb2c140295 100644
> --- a/drivers/media/platform/ti-vpe/vpe.c
> +++ b/drivers/media/platform/ti-vpe/vpe.c
> @@ -2471,10 +2471,8 @@ static int vpe_runtime_get(struct platform_device *pdev)
>  
>  	dev_dbg(&pdev->dev, "vpe_runtime_get\n");
>  
> -	r = pm_runtime_get_sync(&pdev->dev);
> +	r = pm_runtime_resume_and_get(&pdev->dev);
>  	WARN_ON(r < 0);
> -	if (r)
> -		pm_runtime_put_noidle(&pdev->dev);
>  	return r < 0 ? r : 0;
r is <= 0 to zero so this isn't doing anything useful.

>  }
>  


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 77/79] media: rcar-vin: use pm_runtime_resume_and_get()
  2021-04-28 14:52 ` [PATCH v4 77/79] media: rcar-vin: " Mauro Carvalho Chehab
@ 2021-04-30 18:05   ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 18:05 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Niklas Söderlund,
	Mauro Carvalho Chehab, linux-kernel, linux-media,
	linux-renesas-soc, Niklas Söderlund

On Wed, 28 Apr 2021 16:52:38 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
> 
> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Trivial thing inline.  Doesn't matter though if you prefer it as is.

> ---
>  drivers/media/platform/rcar-vin/rcar-csi2.c | 15 ++++++++++++---
>  drivers/media/platform/rcar-vin/rcar-dma.c  |  6 ++----
>  drivers/media/platform/rcar-vin/rcar-v4l2.c |  6 ++----
>  3 files changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> index e06cd512aba2..436fb17f73ea 100644
> --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -406,10 +406,17 @@ static void rcsi2_enter_standby(struct rcar_csi2 *priv)
>  	pm_runtime_put(priv->dev);
>  }
>  
> -static void rcsi2_exit_standby(struct rcar_csi2 *priv)
> +static int rcsi2_exit_standby(struct rcar_csi2 *priv)
>  {
> -	pm_runtime_get_sync(priv->dev);
> +	int ret;
> +
> +	ret = pm_runtime_resume_and_get(priv->dev);
> +	if (ret < 0)
> +		return ret;
> +
>  	reset_control_deassert(priv->rstc);
> +
> +	return ret;

Maybe return 0; to make it easy to see this returns <= 0;
ret will always be 0 here anyway.

>  }
>  
>  static int rcsi2_wait_phy_start(struct rcar_csi2 *priv,
> @@ -657,7 +664,9 @@ static int rcsi2_start(struct rcar_csi2 *priv)
>  {
>  	int ret;
>  
> -	rcsi2_exit_standby(priv);
> +	ret = rcsi2_exit_standby(priv);
> +	if (ret < 0)
> +		return ret;
>  
>  	ret = rcsi2_start_receiver(priv);
>  	if (ret) {
> diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
> index f30dafbdf61c..f5f722ab1d4e 100644
> --- a/drivers/media/platform/rcar-vin/rcar-dma.c
> +++ b/drivers/media/platform/rcar-vin/rcar-dma.c
> @@ -1458,11 +1458,9 @@ int rvin_set_channel_routing(struct rvin_dev *vin, u8 chsel)
>  	u32 vnmc;
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(vin->dev);
> -	if (ret < 0) {
> -		pm_runtime_put_noidle(vin->dev);
> +	ret = pm_runtime_resume_and_get(vin->dev);
> +	if (ret < 0)
>  		return ret;
> -	}
>  
>  	/* Make register writes take effect immediately. */
>  	vnmc = rvin_read(vin, VNMC_REG);
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> index 457a65bf6b66..b1e9f86caa5c 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -870,11 +870,9 @@ static int rvin_open(struct file *file)
>  	struct rvin_dev *vin = video_drvdata(file);
>  	int ret;
>  
> -	ret = pm_runtime_get_sync(vin->dev);
> -	if (ret < 0) {
> -		pm_runtime_put_noidle(vin->dev);
> +	ret = pm_runtime_resume_and_get(vin->dev);
> +	if (ret < 0)
>  		return ret;
> -	}
>  
>  	ret = mutex_lock_interruptible(&vin->lock);
>  	if (ret)


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
  2021-04-28 14:52   ` Mauro Carvalho Chehab
  (?)
@ 2021-04-30 18:09     ` Jonathan Cameron
  -1 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 18:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Philipp Zabel, devel, linux-kernel,
	linux-media, linux-rockchip

On Wed, 28 Apr 2021 16:52:39 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
> 
> While there's nothing wrong with the current usage on this driver,
> as we're getting rid of the pm_runtime_get_sync() call all over
> the media subsystem, let's remove the last occurrence on this
> driver.

Not sure there is nothing wrong in here before your patch...


> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 595e82a82728..25fa36e7e773 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
>  	return hantro_get_dec_buf_addr(ctx, buf);
>  }
>  
> -static void hantro_job_finish(struct hantro_dev *vpu,
> -			      struct hantro_ctx *ctx,
> -			      enum vb2_buffer_state result)
> +static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
> +				    struct hantro_ctx *ctx,
> +				    enum vb2_buffer_state result)
>  {
>  	struct vb2_v4l2_buffer *src, *dst;
>  
> -	pm_runtime_mark_last_busy(vpu->dev);
> -	pm_runtime_put_autosuspend(vpu->dev);
>  	clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
>  
>  	src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
>  					 result);
>  }
>  
> +static void hantro_job_finish(struct hantro_dev *vpu,
> +			      struct hantro_ctx *ctx,
> +			      enum vb2_buffer_state result)
> +{
> +	pm_runtime_mark_last_busy(vpu->dev);
> +	pm_runtime_put_autosuspend(vpu->dev);
> +
> +	hantro_job_finish_no_pm(vpu, ctx, result);
> +}
> +
>  void hantro_irq_done(struct hantro_dev *vpu,
>  		     enum vb2_buffer_state result)
>  {
> @@ -155,7 +163,8 @@ static void device_run(void *priv)
>  	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
>  	if (ret)
>  		goto err_cancel_job;

Before your patch, if this error condition happened, we'd call runtime_put
before the related runtime_get...  You fixed that, but the patch description
doesn't call it out.


> -	ret = pm_runtime_get_sync(ctx->dev->dev);
> +
> +	ret = pm_runtime_resume_and_get(ctx->dev->dev);
>  	if (ret < 0)
>  		goto err_cancel_job;
>  
> @@ -165,7 +174,7 @@ static void device_run(void *priv)
>  	return;
>  
>  err_cancel_job:
> -	hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> +	hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
>  }
>  
>  static struct v4l2_m2m_ops vpu_m2m_ops = {


^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
@ 2021-04-30 18:09     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 18:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel,
	linux-rockchip, Philipp Zabel, mauro.chehab,
	Mauro Carvalho Chehab, Ezequiel Garcia, linux-media

On Wed, 28 Apr 2021 16:52:39 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
> 
> While there's nothing wrong with the current usage on this driver,
> as we're getting rid of the pm_runtime_get_sync() call all over
> the media subsystem, let's remove the last occurrence on this
> driver.

Not sure there is nothing wrong in here before your patch...


> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 595e82a82728..25fa36e7e773 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
>  	return hantro_get_dec_buf_addr(ctx, buf);
>  }
>  
> -static void hantro_job_finish(struct hantro_dev *vpu,
> -			      struct hantro_ctx *ctx,
> -			      enum vb2_buffer_state result)
> +static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
> +				    struct hantro_ctx *ctx,
> +				    enum vb2_buffer_state result)
>  {
>  	struct vb2_v4l2_buffer *src, *dst;
>  
> -	pm_runtime_mark_last_busy(vpu->dev);
> -	pm_runtime_put_autosuspend(vpu->dev);
>  	clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
>  
>  	src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
>  					 result);
>  }
>  
> +static void hantro_job_finish(struct hantro_dev *vpu,
> +			      struct hantro_ctx *ctx,
> +			      enum vb2_buffer_state result)
> +{
> +	pm_runtime_mark_last_busy(vpu->dev);
> +	pm_runtime_put_autosuspend(vpu->dev);
> +
> +	hantro_job_finish_no_pm(vpu, ctx, result);
> +}
> +
>  void hantro_irq_done(struct hantro_dev *vpu,
>  		     enum vb2_buffer_state result)
>  {
> @@ -155,7 +163,8 @@ static void device_run(void *priv)
>  	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
>  	if (ret)
>  		goto err_cancel_job;

Before your patch, if this error condition happened, we'd call runtime_put
before the related runtime_get...  You fixed that, but the patch description
doesn't call it out.


> -	ret = pm_runtime_get_sync(ctx->dev->dev);
> +
> +	ret = pm_runtime_resume_and_get(ctx->dev->dev);
>  	if (ret < 0)
>  		goto err_cancel_job;
>  
> @@ -165,7 +174,7 @@ static void device_run(void *priv)
>  	return;
>  
>  err_cancel_job:
> -	hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> +	hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
>  }
>  
>  static struct v4l2_m2m_ops vpu_m2m_ops = {

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
@ 2021-04-30 18:09     ` Jonathan Cameron
  0 siblings, 0 replies; 208+ messages in thread
From: Jonathan Cameron @ 2021-04-30 18:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, Philipp Zabel, devel, linux-kernel,
	linux-media, linux-rockchip

On Wed, 28 Apr 2021 16:52:39 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
> 
> While there's nothing wrong with the current usage on this driver,
> as we're getting rid of the pm_runtime_get_sync() call all over
> the media subsystem, let's remove the last occurrence on this
> driver.

Not sure there is nothing wrong in here before your patch...


> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 595e82a82728..25fa36e7e773 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
>  	return hantro_get_dec_buf_addr(ctx, buf);
>  }
>  
> -static void hantro_job_finish(struct hantro_dev *vpu,
> -			      struct hantro_ctx *ctx,
> -			      enum vb2_buffer_state result)
> +static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
> +				    struct hantro_ctx *ctx,
> +				    enum vb2_buffer_state result)
>  {
>  	struct vb2_v4l2_buffer *src, *dst;
>  
> -	pm_runtime_mark_last_busy(vpu->dev);
> -	pm_runtime_put_autosuspend(vpu->dev);
>  	clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
>  
>  	src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
>  					 result);
>  }
>  
> +static void hantro_job_finish(struct hantro_dev *vpu,
> +			      struct hantro_ctx *ctx,
> +			      enum vb2_buffer_state result)
> +{
> +	pm_runtime_mark_last_busy(vpu->dev);
> +	pm_runtime_put_autosuspend(vpu->dev);
> +
> +	hantro_job_finish_no_pm(vpu, ctx, result);
> +}
> +
>  void hantro_irq_done(struct hantro_dev *vpu,
>  		     enum vb2_buffer_state result)
>  {
> @@ -155,7 +163,8 @@ static void device_run(void *priv)
>  	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
>  	if (ret)
>  		goto err_cancel_job;

Before your patch, if this error condition happened, we'd call runtime_put
before the related runtime_get...  You fixed that, but the patch description
doesn't call it out.


> -	ret = pm_runtime_get_sync(ctx->dev->dev);
> +
> +	ret = pm_runtime_resume_and_get(ctx->dev->dev);
>  	if (ret < 0)
>  		goto err_cancel_job;
>  
> @@ -165,7 +174,7 @@ static void device_run(void *priv)
>  	return;
>  
>  err_cancel_job:
> -	hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> +	hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
>  }
>  
>  static struct v4l2_m2m_ops vpu_m2m_ops = {


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 01/79] media: venus: fix PM runtime logic at venus_sys_error_handler()
  2021-04-30 15:21   ` Jonathan Cameron
@ 2021-05-03  9:00     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-05-03  9:00 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linuxarm, mauro.chehab, Andy Gross, Bjorn Andersson,
	Hans Verkuil, Mauro Carvalho Chehab, Stanimir Varbanov,
	linux-arm-msm, linux-kernel, linux-media

Em Fri, 30 Apr 2021 16:21:10 +0100
Jonathan Cameron <Jonathan.Cameron@Huawei.com> escreveu:

> On Wed, 28 Apr 2021 16:51:22 +0200
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:
> 
> > The venus_sys_error_handler() assumes that pm_runtime was
> > able to resume, as it does things like:
> > 
> > 	while (pm_runtime_active(core->dev_dec) || pm_runtime_active(core->dev_enc))
> > 		msleep(10);
> > 
> > Well, if, for whatever reason, this won't happen, the routine
> > won't do what's expected. So, check for the returned error
> > condition, warning if it returns an error.
> > 
> > Fixes: af2c3834c8ca ("[media] media: venus: adding core part and helper functions")
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> > ---
> >  drivers/media/platform/qcom/venus/core.c | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c
> > index 54bac7ec14c5..c80c27c87ccc 100644
> > --- a/drivers/media/platform/qcom/venus/core.c
> > +++ b/drivers/media/platform/qcom/venus/core.c
> > @@ -84,7 +84,11 @@ static void venus_sys_error_handler(struct work_struct *work)
> >  			container_of(work, struct venus_core, work.work);
> >  	int ret = 0;
> >  
> > -	pm_runtime_get_sync(core->dev);
> > +	ret = pm_runtime_get_sync(core->dev);
> > +	if (WARN_ON(ret < 0)) {
> > +		pm_runtime_put_noidle(core->dev);
> > +		return;
> > +	}
> >  
> >  	hfi_core_deinit(core, true);
> >  
> > @@ -106,9 +110,13 @@ static void venus_sys_error_handler(struct work_struct *work)
> >  
> >  	hfi_reinit(core);
> >  
> > -	pm_runtime_get_sync(core->dev);
> > +	ret = pm_runtime_get_sync(core->dev);
> > +	if (WARN_ON(ret < 0)) {
> > +		pm_runtime_put_noidle(core->dev);  

Thanks for review!

> mutex_unlock(&core->lock);
> (the unlock is currently just below the enable_irq() in 5.12)

Basically, this function assumes that the core->lock is not locked
and that IRQs are disabled, as can be seen at the function which
starts such work:

    static void venus_event_notify(struct venus_core *core, u32 event)
    {
	struct venus_inst *inst;

	switch (event) {
	case EVT_SYS_WATCHDOG_TIMEOUT:
	case EVT_SYS_ERROR:
		break;
	default:
		return;
	}

	mutex_lock(&core->lock);
	core->sys_error = true;
	list_for_each_entry(inst, &core->instances, list)
		inst->ops->event_notify(inst, EVT_SESSION_ERROR, NULL);
	mutex_unlock(&core->lock);

	disable_irq_nosync(core->irq);
	schedule_delayed_work(&core->work, msecs_to_jiffies(10));
    }

The code inside it actually locks/unlocks two times the core->lock. 
See, this is the original code:

    static void venus_sys_error_handler(struct work_struct *work)
    {
	<not locked>

        pm_runtime_get_sync(core->dev);

        hfi_core_deinit(core, true);

        dev_warn(core->dev, "system error has occurred, starting recovery!\n");

        mutex_lock(&core->lock);
	while (pm_runtime_active(core->dev_dec) || pm_runtime_active(core->dev_enc))
                msleep(10);
...
        enable_irq(core->irq);
        mutex_unlock(&core->lock);
...
	if (ret) {
                disable_irq_nosync(core->irq);
                dev_warn(core->dev, "recovery failed (%d)\n", ret);
                schedule_delayed_work(&core->work, msecs_to_jiffies(10));
                return;
        }

	mutex_lock(&core->lock);
        core->sys_error = false;
        mutex_unlock(&core->lock);
    }

It should be noticed that, once started, this delayed work re-starts
itself, with IRQs disabled, trying to reboot the Venus IP hardware,
until it stops failing [1].

[1] IMHO, it seems a very bad idea to keep running the work forever,
flooding syslog with error messages on every 10ms or so.

That's said, my patch doesn't seem to fix all potential issues that
could happen there.

I'll propose a separate fix, outside this patch series, as the issues
here are not only due to RPM, but the main issue is that both
while loops inside this code can run forever with the core->lock
hold.

Thanks,
Mauro

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 23/79] staging: media: ipu3: use pm_runtime_resume_and_get()
  2021-04-30 17:03     ` Jonathan Cameron
@ 2021-05-03  9:57       ` Johan Hovold
  -1 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-05-03  9:57 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Mauro Carvalho Chehab, devel, Greg Kroah-Hartman, linuxarm,
	linux-kernel, Sakari Ailus, mauro.chehab, Bingbu Cao,
	Mauro Carvalho Chehab, Tianshu Qiu, linux-media

On Fri, Apr 30, 2021 at 06:03:38PM +0100, Jonathan Cameron wrote:
> On Wed, 28 Apr 2021 16:51:44 +0200
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
> Could add that pm_runtime_put() should have been pm_runtime_put_noidle()
> inorder to not potentially result in a call to runtime suspend when
> we never resumed in the first place.

No, that would never happen anyway and any pm_runtime_put() will do
even if pm_runtime_put_noidle() is the natural choice in this case to
balance the counter.

> Otherwise reasonable cleanup.
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> > ---
> >  drivers/staging/media/ipu3/ipu3.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c
> > index ee1bba6bdcac..8e1e9e46e604 100644
> > --- a/drivers/staging/media/ipu3/ipu3.c
> > +++ b/drivers/staging/media/ipu3/ipu3.c
> > @@ -392,10 +392,9 @@ int imgu_s_stream(struct imgu_device *imgu, int enable)
> >  	}
> >  
> >  	/* Set Power */
> > -	r = pm_runtime_get_sync(dev);
> > +	r = pm_runtime_resume_and_get(dev);
> >  	if (r < 0) {
> >  		dev_err(dev, "failed to set imgu power\n");
> > -		pm_runtime_put(dev);
> >  		return r;
> >  	}

Johan

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 23/79] staging: media: ipu3: use pm_runtime_resume_and_get()
@ 2021-05-03  9:57       ` Johan Hovold
  0 siblings, 0 replies; 208+ messages in thread
From: Johan Hovold @ 2021-05-03  9:57 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: devel, Mauro Carvalho Chehab, Greg Kroah-Hartman, linuxarm,
	linux-kernel, Sakari Ailus, mauro.chehab, Bingbu Cao,
	Mauro Carvalho Chehab, Tianshu Qiu, linux-media

On Fri, Apr 30, 2021 at 06:03:38PM +0100, Jonathan Cameron wrote:
> On Wed, 28 Apr 2021 16:51:44 +0200
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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>
> Could add that pm_runtime_put() should have been pm_runtime_put_noidle()
> inorder to not potentially result in a call to runtime suspend when
> we never resumed in the first place.

No, that would never happen anyway and any pm_runtime_put() will do
even if pm_runtime_put_noidle() is the natural choice in this case to
balance the counter.

> Otherwise reasonable cleanup.
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> > ---
> >  drivers/staging/media/ipu3/ipu3.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/media/ipu3/ipu3.c b/drivers/staging/media/ipu3/ipu3.c
> > index ee1bba6bdcac..8e1e9e46e604 100644
> > --- a/drivers/staging/media/ipu3/ipu3.c
> > +++ b/drivers/staging/media/ipu3/ipu3.c
> > @@ -392,10 +392,9 @@ int imgu_s_stream(struct imgu_device *imgu, int enable)
> >  	}
> >  
> >  	/* Set Power */
> > -	r = pm_runtime_get_sync(dev);
> > +	r = pm_runtime_resume_and_get(dev);
> >  	if (r < 0) {
> >  		dev_err(dev, "failed to set imgu power\n");
> > -		pm_runtime_put(dev);
> >  		return r;
> >  	}

Johan
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 43/79] media: i2c: ov2659: use pm_runtime_resume_and_get()
  2021-04-28 14:52 ` [PATCH v4 43/79] media: i2c: ov2659: " Mauro Carvalho Chehab
@ 2021-05-03 12:30   ` Lad, Prabhakar
  0 siblings, 0 replies; 208+ messages in thread
From: Lad, Prabhakar @ 2021-05-03 12:30 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, LKML, linux-media

Hi Mauro,

Thank you for the patch.

On Wed, Apr 28, 2021 at 3:52 PM Mauro Carvalho Chehab
<mchehab+huawei@kernel.org> 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/i2c/ov2659.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
Acked-by: Lad Prabhakar <prabhakar.csengg@gmail.com>

Cheers,
Prabhakar

> diff --git a/drivers/media/i2c/ov2659.c b/drivers/media/i2c/ov2659.c
> index 42f64175a6df..a3c8eae68486 100644
> --- a/drivers/media/i2c/ov2659.c
> +++ b/drivers/media/i2c/ov2659.c
> @@ -1186,11 +1186,9 @@ static int ov2659_s_stream(struct v4l2_subdev *sd, int on)
>                 goto unlock;
>         }
>
> -       ret = pm_runtime_get_sync(&client->dev);
> -       if (ret < 0) {
> -               pm_runtime_put_noidle(&client->dev);
> +       ret = pm_runtime_resume_and_get(&client->dev);
> +       if (ret < 0)
>                 goto unlock;
> -       }
>
>         ret = ov2659_init(sd, 0);
>         if (!ret)
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 75/79] media: ti-vpe: use pm_runtime_resume_and_get()
  2021-04-30 18:03   ` Jonathan Cameron
@ 2021-05-03 12:49     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-05-03 12:49 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linuxarm, mauro.chehab, Benoit Parrot, Mauro Carvalho Chehab,
	linux-kernel, linux-media

Em Fri, 30 Apr 2021 19:03:11 +0100
Jonathan Cameron <Jonathan.Cameron@Huawei.com> escreveu:

> On Wed, 28 Apr 2021 16:52:36 +0200
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> > diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
> > index 10251b787674..07cb2c140295 100644
> > --- a/drivers/media/platform/ti-vpe/vpe.c
> > +++ b/drivers/media/platform/ti-vpe/vpe.c
> > @@ -2471,10 +2471,8 @@ static int vpe_runtime_get(struct platform_device *pdev)
> >  
> >  	dev_dbg(&pdev->dev, "vpe_runtime_get\n");
> >  
> > -	r = pm_runtime_get_sync(&pdev->dev);
> > +	r = pm_runtime_resume_and_get(&pdev->dev);
> >  	WARN_ON(r < 0);
> > -	if (r)
> > -		pm_runtime_put_noidle(&pdev->dev);
> >  	return r < 0 ? r : 0;  
> r is <= 0 to zero so this isn't doing anything useful.

Not really. pm_runtime*get* routines may return positive values
as well. From Documentation/power/runtime_pm.rst:

  `int pm_runtime_resume(struct device *dev);`
    - execute the subsystem-level resume callback for the device; returns 0 on
      success, 1 if the device's runtime PM status was already 'active' or
      error code on failure, where -EAGAIN means it may be safe to attempt to
      resume the device again in future, but 'power.runtime_error' should be
      checked additionally, and -EACCES means that 'power.disable_depth' is
      different from 0

  `int pm_runtime_resume_and_get(struct device *dev);`
    - run pm_runtime_resume(dev) and if successful, increment the device's
      usage counter; return the result of pm_runtime_resume

  `int pm_runtime_get_sync(struct device *dev);`
    - increment the device's usage counter, run pm_runtime_resume(dev) and
      return its result

So, basically, if the device was already active, it would return 1.

Now, this is called as:

        ret = vpe_runtime_get(pdev);
        if (ret)
                goto rel_m2m;

So the logic could be simplified if the caller would be
doing, instead:

        ret = vpe_runtime_get(pdev);
        if (ret < 0)
                goto rel_m2m;

I'll do such change for the next version.

Thanks,
Mauro

^ permalink raw reply	[flat|nested] 208+ messages in thread

* Re: [PATCH v4 14/79] media: am437x: fix pm_runtime_get_sync() usage count
  2021-04-30 16:36   ` Jonathan Cameron
@ 2021-05-04  7:19     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 208+ messages in thread
From: Mauro Carvalho Chehab @ 2021-05-04  7:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linuxarm, mauro.chehab, Lad, Prabhakar, Mauro Carvalho Chehab,
	linux-kernel, linux-media

Em Fri, 30 Apr 2021 17:36:46 +0100
Jonathan Cameron <Jonathan.Cameron@Huawei.com> escreveu:

> On Wed, 28 Apr 2021 16:51:35 +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, ensure that the driver will check if PM runtime
> > resumed at vpfe_initialize_device().
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>  
> 
> resume and suspend carrying regardless needs a comment I think.
> (see below)
> > ---
> >  drivers/media/platform/am437x/am437x-vpfe.c | 22 +++++++++++++++------
> >  1 file changed, 16 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
> > index 6cdc77dda0e4..bced526f30f2 100644
> > --- a/drivers/media/platform/am437x/am437x-vpfe.c
> > +++ b/drivers/media/platform/am437x/am437x-vpfe.c
> > @@ -1021,7 +1021,9 @@ static int vpfe_initialize_device(struct vpfe_device *vpfe)
> >  	if (ret)
> >  		return ret;
> >  
> > -	pm_runtime_get_sync(vpfe->pdev);
> > +	ret = pm_runtime_resume_and_get(vpfe->pdev);
> > +	if (ret < 0)
> > +		return ret;
> >  
> >  	vpfe_config_enable(&vpfe->ccdc, 1);
> >  
> > @@ -2443,7 +2445,11 @@ static int vpfe_probe(struct platform_device *pdev)
> >  	pm_runtime_enable(&pdev->dev);
> >  
> >  	/* for now just enable it here instead of waiting for the open */
> > -	pm_runtime_get_sync(&pdev->dev);
> > +	ret = pm_runtime_resume_and_get(&pdev->dev);
> > +	if (ret < 0) {
> > +		vpfe_err(vpfe, "Unable to resume device.\n");
> > +		goto probe_out_v4l2_unregister;
> > +	}
> >  
> >  	vpfe_ccdc_config_defaults(ccdc);
> >  
> > @@ -2527,10 +2533,11 @@ static int vpfe_suspend(struct device *dev)
> >  {
> >  	struct vpfe_device *vpfe = dev_get_drvdata(dev);
> >  	struct vpfe_ccdc *ccdc = &vpfe->ccdc;
> > +	int ret;
> >  
> >  	/* only do full suspend if streaming has started */
> >  	if (vb2_start_streaming_called(&vpfe->buffer_queue)) {
> > -		pm_runtime_get_sync(dev);
> > +		ret = pm_runtime_resume_and_get(dev);  
> 
> Carrying on when you know the resume failed, seems interesting enough to
> deserve a comment in the code.  Not sure you can usefully do anything
> but it seems likely a lot of the calls that follow will fail.

This driver indeed has a different behavior. What most drivers do is to
either resume RPM when a V4L2 devnode is opened, or when the device
starts to stream. This one does, instead, at probing time. 

It even has a comment there which implies that this is something that may
require changes in the future:

    static int vpfe_probe(struct platform_device *pdev)
    {
...
	/* for now just enable it here instead of waiting for the open */
	ret = pm_runtime_resume_and_get(&pdev->dev);

After probe, the driver just assumes that RPM is not suspended during its 
entire lifetime (except suspend/resuume).

I can't even see a check at vpfe_open() or at vpfe_start_streaming()
that would cause the functions to fail if, for whatever reason, RPM is
suspended there[1], or if a command sent to the hardware failed.

[1] The only place where there's a check is at v4l2_subdev_call(),
    asking sensors to start streaming. If those are on a different
    power domain, a valid sensor answer call won't ensure that 
    am437x VPFE is operational.

Yet, suspend/resume only checks if videobuf2 started its streaming
logic. if streaming was started, suspend/resume logic tries ensure
that the hardware will be ready to be suspended, restoring it to
the previous state before at resume time, but neither one of those
has a check to see if the commands were succeeded, just like the
logic at vpfe_start_streaming().

-

In summary, I'll add a comment there, but fixing it would require 
adding error checks on several places (open, start_streaming,
resume and suspend).

Thanks,
Mauro

^ permalink raw reply	[flat|nested] 208+ messages in thread

end of thread, other threads:[~2021-05-04  7:19 UTC | newest]

Thread overview: 208+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 14:51 [PATCH v4 00/79] Address some issues with PM runtime at media subsystem Mauro Carvalho Chehab
2021-04-28 14:51 ` Mauro Carvalho Chehab
2021-04-28 14:51 ` Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 01/79] media: venus: fix PM runtime logic at venus_sys_error_handler() Mauro Carvalho Chehab
2021-04-30 15:21   ` Jonathan Cameron
2021-05-03  9:00     ` Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 02/79] media: s6p_cec: decrement usage count if disabled Mauro Carvalho Chehab
2021-04-28 15:31   ` Sylwester Nawrocki
2021-04-28 14:51 ` [PATCH v4 03/79] media: i2c: ccs-core: return the right error code at suspend Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 04/79] media: i2c: ov7740: don't resume at remove time Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 05/79] media: i2c: video-i2c: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 06/79] media: i2c: imx334: fix the pm runtime get logic Mauro Carvalho Chehab
2021-04-30 15:54   ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 07/79] media: exynos-gsc: don't resume at remove time Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-28 15:25   ` Sylwester Nawrocki
2021-04-28 15:25     ` Sylwester Nawrocki
2021-04-28 19:44   ` kernel test robot
2021-04-28 19:44     ` kernel test robot
2021-04-28 19:44     ` kernel test robot
2021-04-28 19:56   ` kernel test robot
2021-04-28 19:56     ` kernel test robot
2021-04-28 19:56     ` kernel test robot
2021-04-28 14:51 ` [PATCH v4 08/79] media: atmel: properly get pm_runtime Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-30 16:13   ` Jonathan Cameron
2021-04-30 16:13     ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 09/79] media: marvel-ccic: fix some issues when getting pm_runtime Mauro Carvalho Chehab
2021-04-30 16:29   ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 10/79] media: mdk-mdp: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-30 16:30   ` Jonathan Cameron
2021-04-30 16:30     ` Jonathan Cameron
2021-04-30 16:30     ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 11/79] media: rcar_fdp1: " Mauro Carvalho Chehab
2021-04-30 16:26   ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 12/79] media: renesas-ceu: Properly check for PM errors Mauro Carvalho Chehab
2021-04-30 16:28   ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 13/79] media: s5p: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 14/79] media: am437x: " Mauro Carvalho Chehab
2021-04-30 16:36   ` Jonathan Cameron
2021-05-04  7:19     ` Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 15/79] media: sh_vou: " Mauro Carvalho Chehab
2021-04-30 16:40   ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 16/79] media: mtk-vcodec: " Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-30 16:44   ` Jonathan Cameron
2021-04-30 16:44     ` Jonathan Cameron
2021-04-30 16:44     ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 17/79] media: s5p-jpeg: " Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 18/79] media: sti/delta: " Mauro Carvalho Chehab
2021-04-30 16:47   ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 19/79] media: sunxi: " Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-30 16:48   ` Jonathan Cameron
2021-04-30 16:48     ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 20/79] staging: media: rkvdec: " Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-28 15:09   ` Johan Hovold
2021-04-28 15:09     ` Johan Hovold
2021-04-28 15:09     ` Johan Hovold
2021-04-29  7:38     ` Mauro Carvalho Chehab
2021-04-29  7:38       ` Mauro Carvalho Chehab
2021-04-29  7:38       ` Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 21/79] staging: media: atomisp: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-30 16:59   ` Jonathan Cameron
2021-04-30 16:59     ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 22/79] staging: media: imx7-mipi-csis: " Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 23/79] staging: media: ipu3: " Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-30 17:03   ` Jonathan Cameron
2021-04-30 17:03     ` Jonathan Cameron
2021-05-03  9:57     ` Johan Hovold
2021-05-03  9:57       ` Johan Hovold
2021-04-28 14:51 ` [PATCH v4 24/79] staging: media: cedrus_video: " Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-30 17:05   ` Jonathan Cameron
2021-04-30 17:05     ` Jonathan Cameron
2021-04-30 17:05     ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 25/79] staging: media: tegra-vde: " Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-29 12:38   ` Dmitry Osipenko
2021-04-29 12:38     ` Dmitry Osipenko
2021-04-30 17:08   ` Jonathan Cameron
2021-04-30 17:08     ` Jonathan Cameron
2021-04-30 17:11     ` Jonathan Cameron
2021-04-30 17:11       ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 26/79] staging: media: tegra-video: " Mauro Carvalho Chehab
2021-04-28 14:51   ` Mauro Carvalho Chehab
2021-04-30 17:13   ` Jonathan Cameron
2021-04-30 17:13     ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 27/79] media: i2c: ak7375: " Mauro Carvalho Chehab
2021-04-30 17:14   ` Jonathan Cameron
2021-04-28 14:51 ` [PATCH v4 28/79] media: i2c: ccs-core: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 29/79] media: i2c: dw9714: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 30/79] media: i2c: dw9768: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 31/79] media: i2c: dw9807-vcm: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 32/79] media: i2c: hi556: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 33/79] media: i2c: imx214: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 34/79] media: i2c: imx219: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 35/79] media: i2c: imx258: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 36/79] media: i2c: imx274: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 37/79] media: i2c: imx290: " Mauro Carvalho Chehab
2021-04-28 14:51 ` [PATCH v4 38/79] media: i2c: imx319: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 39/79] media: i2c: imx355: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 40/79] media: i2c: mt9m001: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 41/79] media: i2c: ov02a10: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 42/79] media: i2c: ov13858: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 43/79] media: i2c: ov2659: " Mauro Carvalho Chehab
2021-05-03 12:30   ` Lad, Prabhakar
2021-04-28 14:52 ` [PATCH v4 44/79] media: i2c: ov2685: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 45/79] media: i2c: ov2740: " Mauro Carvalho Chehab
2021-04-30 17:20   ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 46/79] media: i2c: ov5647: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 47/79] media: i2c: ov5648: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 48/79] media: i2c: ov5670: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 49/79] media: i2c: ov5675: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 50/79] media: i2c: ov5695: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 51/79] media: i2c: ov7740: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 52/79] media: i2c: ov8856: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 53/79] media: i2c: ov8865: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 54/79] media: i2c: ov9734: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 55/79] media: i2c: tvp5150: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 56/79] media: i2c: video-i2c: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 57/79] media: rockchip/rga: " Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 17:11   ` Ezequiel Garcia
2021-04-28 17:11     ` Ezequiel Garcia
2021-04-28 17:11     ` Ezequiel Garcia
2021-04-28 14:52 ` [PATCH v4 58/79] media: sti/hva: " Mauro Carvalho Chehab
2021-04-30 17:35   ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 59/79] media: sti/bdisp: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 60/79] media: ipu3: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 61/79] media: coda: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 62/79] media: exynos4-is: " Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-30 17:49   ` Jonathan Cameron
2021-04-30 17:49     ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 63/79] media: exynos-gsc: " Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-30 17:50   ` Jonathan Cameron
2021-04-30 17:50     ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 64/79] media: mtk-jpeg: " Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 65/79] media: camss: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 66/79] media: venus: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 67/79] media: venus: vdec: " Mauro Carvalho Chehab
2021-04-30 17:53   ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 68/79] media: venus: venc: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 69/79] media: rcar-fcp: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 70/79] media: rkisp1: " Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 71/79] media: s3c-camif: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 72/79] media: s5p-mfc: " Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 73/79] media: stm32: " Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-30 17:58   ` Jonathan Cameron
2021-04-30 17:58     ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 74/79] media: sunxi: " Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 75/79] media: ti-vpe: " Mauro Carvalho Chehab
2021-04-30 18:03   ` Jonathan Cameron
2021-05-03 12:49     ` Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 76/79] media: vsp1: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 77/79] media: rcar-vin: " Mauro Carvalho Chehab
2021-04-30 18:05   ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 78/79] media: hantro: " Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 17:14   ` Ezequiel Garcia
2021-04-28 17:14     ` Ezequiel Garcia
2021-04-28 17:14     ` Ezequiel Garcia
2021-04-30 18:09   ` Jonathan Cameron
2021-04-30 18:09     ` Jonathan Cameron
2021-04-30 18:09     ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 79/79] media: hantro: do a PM resume earlier Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 14:52   ` Mauro Carvalho Chehab
2021-04-28 17:17   ` Ezequiel Garcia
2021-04-28 17:17     ` Ezequiel Garcia
2021-04-28 17:17     ` Ezequiel Garcia
2021-04-29  7:13     ` Mauro Carvalho Chehab
2021-04-29  7:13       ` Mauro Carvalho Chehab
2021-04-29  7:13       ` Mauro Carvalho Chehab
2021-04-28 15:50 ` [PATCH v4 00/79] Address some issues with PM runtime at media subsystem Johan Hovold
2021-04-28 15:50   ` Johan Hovold
2021-04-28 15:50   ` Johan Hovold
2021-04-29 10:18   ` Mauro Carvalho Chehab
2021-04-29 10:18     ` Mauro Carvalho Chehab
2021-04-29 10:18     ` Mauro Carvalho Chehab
2021-04-29 12:33     ` Dmitry Osipenko
2021-04-29 12:33       ` Dmitry Osipenko
2021-04-29 12:33       ` Dmitry Osipenko
2021-04-29 15:17     ` Johan Hovold
2021-04-29 15:17       ` Johan Hovold
2021-04-29 15:17       ` Johan Hovold

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.