media: use pm_runtime_resume_and_get() instead of pm_runtime_get_sync()
Subsystems (58)
cover media: use pm_runtime_resume_and_get() instead of pm_runtime_get_sync()
During the review of the patches from unm.edu, one of the patterns I noticed is the amount of patches trying to fix pm_runtime_get_sync() calls.
On contrary of the common sense that a foo_get() function will only increment the usage on success, pm_runtime_get_sync() increments it unconditionally.
Due to that, there are bugs on lots of places, that ended being gradually fixed, but, still there are a few places on media where this is still broken.
Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added a new method to does a pm_runtime get, which increments
the usage count only on success.
This series replace all places where the old pm_runtime_get_sync() is called, using pm_runtime_resume_and_get() instead.
This should help to avoid future mistakes like that, as people tend to use the existing drivers as examples for newer ones.
compile-tested only.
Mauro Carvalho Chehab (78):
media: atmel: properly get pm_runtime
media: marvel-ccic: fix some issues when getting pm_runtime
media: mdk-mdp: fix pm_runtime_get_sync() usage count
media: rcar_fdp1: fix usage count
media: mdk-mdp: fix pm_runtime_get_sync() usage count
media: renesas-ceu: fix pm_runtime_get_sync() usage count
media: s5p: fix pm_runtime_get_sync() usage count
media: am437x:: fix pm_runtime_get_sync() usage count
media: sh_vou: fix pm_runtime_get_sync() usage count
media: sti/hva: use pm_runtime_resume_and_get()
staging: media: rkvdec: fix pm_runtime_get_sync() usage count
staging: media: atomisp_fops: use pm_runtime_resume_and_get()
staging: media: hantro_drv: use pm_runtime_resume_and_get()
staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get()
staging: media: ipu3: use pm_runtime_resume_and_get()
staging: media: cedrus_video: use pm_runtime_resume_and_get()
staging: media: vde: use pm_runtime_resume_and_get()
staging: media: csi: use pm_runtime_resume_and_get()
staging: media: vi: use pm_runtime_resume_and_get()
media: mtk-vcodec: fix pm_runtime_get_sync() usage count
media: s5p-jpeg: fix pm_runtime_get_sync() usage count
media: delta-v4l2: fix pm_runtime_get_sync() usage count
media: sun8i_rotate: fix pm_runtime_get_sync() usage count
media: i2c: ak7375: use pm_runtime_resume_and_get()
media: i2c: ccs-core: use pm_runtime_resume_and_get()
media: i2c: dw9714: use pm_runtime_resume_and_get()
media: i2c: dw9768: use pm_runtime_resume_and_get()
media: i2c: dw9807-vcm: use pm_runtime_resume_and_get()
media: i2c: hi556: use pm_runtime_resume_and_get()
media: i2c: imx214: use pm_runtime_resume_and_get()
media: i2c: imx219: use pm_runtime_resume_and_get()
media: i2c: imx258: use pm_runtime_resume_and_get()
media: i2c: imx274: use pm_runtime_resume_and_get()
media: i2c: imx290: use pm_runtime_resume_and_get()
media: i2c: imx319: use pm_runtime_resume_and_get()
media: i2c: imx334: use pm_runtime_resume_and_get()
media: i2c: imx355: use pm_runtime_resume_and_get()
media: i2c: mt9m001: use pm_runtime_resume_and_get()
media: i2c: ov02a10: use pm_runtime_resume_and_get()
media: i2c: ov13858: use pm_runtime_resume_and_get()
media: i2c: ov2659: use pm_runtime_resume_and_get()
media: i2c: ov2685: use pm_runtime_resume_and_get()
media: i2c: ov2740: use pm_runtime_resume_and_get()
media: i2c: ov5647: use pm_runtime_resume_and_get()
media: i2c: ov5648: use pm_runtime_resume_and_get()
media: i2c: ov5670: use pm_runtime_resume_and_get()
media: i2c: ov5675: use pm_runtime_resume_and_get()
media: i2c: ov5695: use pm_runtime_resume_and_get()
media: i2c: ov7740: use pm_runtime_resume_and_get()
media: i2c: ov8856: use pm_runtime_resume_and_get()
media: i2c: ov8865: use pm_runtime_resume_and_get()
media: i2c: ov9734: use pm_runtime_resume_and_get()
media: i2c: tvp5150: use pm_runtime_resume_and_get()
media: i2c: video-i2c: use pm_runtime_resume_and_get()
media: ipu3: use pm_runtime_resume_and_get()
media: coda: use pm_runtime_resume_and_get()
media: exynos4-is: use pm_runtime_resume_and_get()
media: exynos-gsc: use pm_runtime_resume_and_get()
media: mtk-jpeg: use pm_runtime_resume_and_get()
media: camss-csid: use pm_runtime_resume_and_get()
media: camss-csiphy: use pm_runtime_resume_and_get()
media: camss-ispif: use pm_runtime_resume_and_get()
media: camss-vfe: use pm_runtime_resume_and_get()
media: core: use pm_runtime_resume_and_get()
media: pm_helpers: use pm_runtime_resume_and_get()
media: vdec: use pm_runtime_resume_and_get()
media: venc: use pm_runtime_resume_and_get()
media: rcar-fcp: use pm_runtime_resume_and_get()
media: rcar-vin: use pm_runtime_resume_and_get()
media: rga-buf: use pm_runtime_resume_and_get()
media: rkisp1-capture: use pm_runtime_resume_and_get()
media: s3c-camif: use pm_runtime_resume_and_get()
media: s5p-mfc: use pm_runtime_resume_and_get()
media: bdisp-v4l2: use pm_runtime_resume_and_get()
media: stm32: use pm_runtime_resume_and_get()
media: sun4i_v4l2: use pm_runtime_resume_and_get()
media: ti-vpe: use pm_runtime_resume_and_get()
media: vsp1: use pm_runtime_resume_and_get()
drivers/media/cec/platform/s5p/s5p_cec.c | 5 +++- drivers/media/i2c/ak7375.c | 10 +------ drivers/media/i2c/ccs/ccs-core.c | 11 ++++---- drivers/media/i2c/dw9714.c | 10 +------ drivers/media/i2c/dw9768.c | 10 +------ drivers/media/i2c/dw9807-vcm.c | 10 +------ drivers/media/i2c/hi556.c | 3 +-- drivers/media/i2c/imx214.c | 6 ++--- drivers/media/i2c/imx219.c | 6 ++--- drivers/media/i2c/imx258.c | 6 ++--- drivers/media/i2c/imx274.c | 3 +-- drivers/media/i2c/imx290.c | 6 ++--- drivers/media/i2c/imx319.c | 6 ++--- drivers/media/i2c/imx334.c | 5 ++-- drivers/media/i2c/imx355.c | 6 ++--- drivers/media/i2c/mt9m001.c | 7 ++--- drivers/media/i2c/ov02a10.c | 6 ++--- drivers/media/i2c/ov13858.c | 6 ++--- drivers/media/i2c/ov2659.c | 6 ++--- drivers/media/i2c/ov2685.c | 7 +++-- drivers/media/i2c/ov2740.c | 6 ++--- drivers/media/i2c/ov5647.c | 9 ++++--- drivers/media/i2c/ov5648.c | 6 ++--- drivers/media/i2c/ov5670.c | 6 ++--- drivers/media/i2c/ov5675.c | 3 +-- drivers/media/i2c/ov5695.c | 6 ++--- drivers/media/i2c/ov7740.c | 8 +++--- drivers/media/i2c/ov8856.c | 3 +-- drivers/media/i2c/ov8865.c | 6 ++--- drivers/media/i2c/ov9734.c | 3 +-- drivers/media/i2c/tvp5150.c | 16 +++--------- drivers/media/i2c/video-i2c.c | 14 ++++------ drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 3 +-- drivers/media/platform/am437x/am437x-vpfe.c | 10 ++++--- drivers/media/platform/atmel/atmel-isc-base.c | 26 ++++++++++++++----- drivers/media/platform/atmel/atmel-isi.c | 19 +++++++++++--- drivers/media/platform/coda/coda-common.c | 2 +- drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- .../media/platform/exynos4-is/fimc-capture.c | 6 ++--- drivers/media/platform/exynos4-is/fimc-is.c | 3 ++- .../platform/exynos4-is/fimc-isp-video.c | 3 +-- drivers/media/platform/exynos4-is/fimc-isp.c | 7 +++-- drivers/media/platform/exynos4-is/fimc-lite.c | 5 ++-- drivers/media/platform/exynos4-is/fimc-m2m.c | 2 +- drivers/media/platform/exynos4-is/media-dev.c | 8 +++--- drivers/media/platform/exynos4-is/mipi-csis.c | 5 ++-- .../media/platform/marvell-ccic/mcam-core.c | 9 +++++-- .../media/platform/mtk-jpeg/mtk_jpeg_core.c | 4 +-- drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 ++--- .../platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 4 +-- .../media/platform/qcom/camss/camss-csid.c | 6 ++--- .../media/platform/qcom/camss/camss-csiphy.c | 6 ++--- .../media/platform/qcom/camss/camss-ispif.c | 6 ++--- drivers/media/platform/qcom/camss/camss-vfe.c | 5 ++-- drivers/media/platform/qcom/venus/core.c | 19 +++++++------- .../media/platform/qcom/venus/pm_helpers.c | 10 +++---- drivers/media/platform/qcom/venus/vdec.c | 4 +-- drivers/media/platform/qcom/venus/venc.c | 5 ++-- drivers/media/platform/rcar-fcp.c | 6 ++--- drivers/media/platform/rcar-vin/rcar-csi2.c | 2 +- drivers/media/platform/rcar-vin/rcar-dma.c | 6 ++--- drivers/media/platform/rcar-vin/rcar-v4l2.c | 6 ++--- drivers/media/platform/rcar_fdp1.c | 12 +++++++-- drivers/media/platform/renesas-ceu.c | 5 +++- drivers/media/platform/rockchip/rga/rga-buf.c | 3 +-- drivers/media/platform/rockchip/rga/rga.c | 4 ++- .../platform/rockchip/rkisp1/rkisp1-capture.c | 3 +-- .../media/platform/s3c-camif/camif-capture.c | 5 ++-- drivers/media/platform/s3c-camif/camif-core.c | 5 ++-- drivers/media/platform/s5p-jpeg/jpeg-core.c | 2 +- drivers/media/platform/s5p-mfc/s5p_mfc_pm.c | 6 ++--- drivers/media/platform/sh_vou.c | 6 ++++- drivers/media/platform/sti/bdisp/bdisp-v4l2.c | 7 ++--- drivers/media/platform/sti/delta/delta-v4l2.c | 4 +-- drivers/media/platform/sti/hva/hva-hw.c | 17 ++++++------ drivers/media/platform/stm32/stm32-dcmi.c | 5 ++-- .../platform/sunxi/sun4i-csi/sun4i_v4l2.c | 7 +++-- .../sunxi/sun8i-rotate/sun8i_rotate.c | 2 +- drivers/media/platform/ti-vpe/cal-video.c | 4 ++- drivers/media/platform/ti-vpe/cal.c | 8 +++--- drivers/media/platform/ti-vpe/vpe.c | 4 +-- drivers/media/platform/vsp1/vsp1_drv.c | 6 ++--- .../staging/media/atomisp/pci/atomisp_fops.c | 6 ++--- drivers/staging/media/hantro/hantro_drv.c | 2 +- drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++-- drivers/staging/media/ipu3/ipu3.c | 3 +-- drivers/staging/media/rkvdec/rkvdec.c | 2 +- .../staging/media/sunxi/cedrus/cedrus_video.c | 6 ++--- drivers/staging/media/tegra-vde/vde.c | 16 +++++++----- drivers/staging/media/tegra-video/csi.c | 3 +-- drivers/staging/media/tegra-video/vi.c | 3 +-- 92 files changed, 270 insertions(+), 322 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/78 media: atmel: properly get pm_runtime
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.
--- drivers/media/platform/atmel/atmel-isc-base.c | 26 ++++++++++++++----- drivers/media/platform/atmel/atmel-isi.c | 19 +++++++++++--- 2 files changed, 34 insertions(+), 11 deletions(-)
drivers/media/platform/atmel/atmel-isc-base.c +19 -7
@@ -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:
@@ -1831,7 +1841,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
drivers/media/platform/atmel/atmel-isi.c +15 -4
@@ -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) {
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH 01/78] media: atmel: properly get pm_runtime
I love your patch! Yet something to improve:
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-rc8 next-20210423] [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/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029 base: git://linuxtv.org/media_tree.git master config: nios2-randconfig-s031-20210424 (attached as .config) compiler: nios2-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-341-g8af24329-dirty
# https://github.com/0day-ci/linux/commit/40fc496edfa42498090c5a0d8230ec732b82bdc9
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mauro-Carvalho-Chehab/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029 git checkout 40fc496edfa42498090c5a0d8230ec732b82bdc9
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=nios2
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/media/platform/atmel/atmel-isc-base.c: In function 'isc_awb_work':
>> drivers/media/platform/atmel/atmel-isc-base.c:1844:2: error: 'ret' undeclared (first use in this function); did you mean 'net'?
1844 | ret = pm_runtime_resume_and_get(isc->dev);
| ^~~
| net drivers/media/platform/atmel/atmel-isc-base.c:1844:2: note: each undeclared identifier is reported only once for each function it appears in
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for SERIAL_CORE_CONSOLE Depends on TTY && HAS_IOMEM
Selected by
- EARLY_PRINTK
vim +1844 drivers/media/platform/atmel/atmel-isc-base.c
1811
1812 static void isc_awb_work(struct work_struct *w)
1813 {
1814 struct isc_device *isc =
1815 container_of(w, struct isc_device, awb_work);
1816 struct regmap *regmap = isc->regmap;
1817 struct isc_ctrls *ctrls = &isc->ctrls;
1818 u32 hist_id = ctrls->hist_id;
1819 u32 baysel;
1820 unsigned long flags;
1821 u32 min, max;
1822
1823 /* streaming is not active anymore */
1824 if (isc->stop)
1825 return;
1826
1827 if (ctrls->hist_stat != HIST_ENABLED)
1828 return;
1829
1830 isc_hist_count(isc, &min, &max);
1831 ctrls->hist_minmax[hist_id][HIST_MIN_INDEX] = min;
1832 ctrls->hist_minmax[hist_id][HIST_MAX_INDEX] = max;
1833
1834 if (hist_id != ISC_HIS_CFG_MODE_B) {
1835 hist_id++;
1836 } else {
1837 isc_wb_update(ctrls);
1838 hist_id = ISC_HIS_CFG_MODE_GR;
1839 }
1840
1841 ctrls->hist_id = hist_id;
1842 baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
1843
> 1844 ret = pm_runtime_resume_and_get(isc->dev);
1845 if (ret < 0)
1846 return;
1847
1848 /*
1849 * only update if we have all the required histograms and controls
1850 * if awb has been disabled, we need to reset registers as well.
1851 */
1852 if (hist_id == ISC_HIS_CFG_MODE_GR || ctrls->awb == ISC_WB_NONE) {
1853 /*
1854 * It may happen that DMA Done IRQ will trigger while we are
1855 * updating white balance registers here.
1856 * In that case, only parts of the controls have been updated.
1857 * We can avoid that by locking the section.
1858 */
1859 spin_lock_irqsave(&isc->awb_lock, flags);
1860 isc_update_awb_ctrls(isc);
1861 spin_unlock_irqrestore(&isc->awb_lock, flags);
1862
1863 /*
1864 * if we are doing just the one time white balance adjustment,
1865 * we are basically done.
1866 */
1867 if (ctrls->awb == ISC_WB_ONETIME) {
1868 v4l2_info(&isc->v4l2_dev,
1869 "Completed one time white-balance adjustment.\n");
1870 /* update the v4l2 controls values */
1871 isc_update_v4l2_ctrls(isc);
1872 ctrls->awb = ISC_WB_NONE;
1873 }
1874 }
1875 regmap_write(regmap, ISC_HIS_CFG, hist_id | baysel | ISC_HIS_CFG_RAR);
1876 isc_update_profile(isc);
1877 /* if awb has been disabled, we don't need to start another histogram */
1878 if (ctrls->awb)
1879 regmap_write(regmap, ISC_CTRLEN, ISC_CTRL_HISREQ);
1880
1881 pm_runtime_put_sync(isc->dev);
1882 }
1883
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 2/78 media: marvel-ccic: fix some issues when getting pm_runtime
In reply to Mauro Carvalho ChehabCalling 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.
--- drivers/media/platform/marvell-ccic/mcam-core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +7 -2
@@ -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 ) +return ret;__mcam_cam_reset (cam);mcam_set_config_needed (cam,1 ); }
Signature · 1 line
2.30.2
PATCH 3/78 media: mdk-mdp: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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.
--- drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +3 -3
@@ -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,
Signature · 1 line
2.30.2
PATCH 4/78 media: rcar_fdp1: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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.
--- drivers/media/platform/rcar_fdp1.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/media/platform/rcar_fdp1.c +10 -2
@@ -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) {
Signature · 1 line
2.30.2
PATCH 5/78 media: mdk-mdp: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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 was caught during chipset probing time.
--- drivers/media/platform/rockchip/rga/rga.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/rockchip/rga/rga.c +3 -1
@@ -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 ;
Signature · 1 line
2.30.2
Re: [PATCH 05/78] media: mdk-mdp: fix pm_runtime_get_sync() usage count
Hi Mauro,
Quoted 7 lines · Mauro Carvalho Chehab
The
pm_runtime_get_sync()internally increments thedev->power.usage_countwithout decrementing it, even on errors.
replace it by the newpm_runtime_resume_and_get(), introduced by:
commitdd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") in order to properly decrement the usage counter and avoid memory
leaks.
Quoted 8 lines
While here, check if the PM runtime was caught during chipset probing time.
Signed-off-by Mauro Carvalho Chehab <[email protected]>---
drivers/media/platform/rockchip/rga/rga.c | 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)
The commit log "media" mdk-mdp" is wrong here.
Maybe you can squash this commit with media: rga-buf: use pm_runtime_resume_and_get()?
Thanks,
Ezequiel
PATCH 6/78 media: renesas-ceu: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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 was caught at open time.
--- drivers/media/platform/renesas-ceu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/renesas-ceu.c +4 -1
@@ -1099,7 +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); +if (ret <0 ) +return ret; +mutex_unlock (&ceudev->mlock);return 0 ;
Signature · 1 line
2.30.2
Jacopo Mondi
maintainerRe: [PATCH 06/78] media: renesas-ceu: fix pm_runtime_get_sync() usage count
Hi Mauro,
Quoted 3 lines · Mauro Carvalho Chehab
The
pm_runtime_get_sync()internally increments thedev->power.usage_countwithout decrementing it, even on errors. replace it by the newpm_runtime_resume_and_get(), introduced by:
Nit: 'Replace' as it follows a full stop ?
Quoted 5 lines
commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") in order to properly decrement the usage counter and avoid memory
leaks.While here, check if the PM runtime was caught at open time.
Nit: Maybe "PM runtime error ..." or something similar as I'm missing the subject of the phrase.
Quoted 11 lines
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/renesas-ceu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/media/platform/renesas-ceu.c +0
-0
drivers/media/platform/renesas-ceu.c static int ceu_open(struct file *file) · line 1104
Quoted 7 lines
drivers/media/platform/renesas-ceu.c +3
-1@@ -1099,7 +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); +if (ret <0 ) +return ret;
The mutex should be released before returning
Quoted 7 lines
drivers/media/platform/renesas-ceu.c +1
-1+mutex_unlock (&ceudev->mlock);return 0 ; --2.30.2
PATCH 7/78 media: s5p: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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 was caught ats5p_cec_adap_enable().
--- drivers/media/cec/platform/s5p/s5p_cec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/cec/platform/s5p/s5p_cec.c +4 -1
@@ -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);
Signature · 1 line
2.30.2
PATCH 8/78 media: am437x:: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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().
--- drivers/media/platform/am437x/am437x-vpfe.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/media/platform/am437x/am437x-vpfe.c +6 -4
@@ -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,7 @@ 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); +pm_runtime_resume_and_get (&pdev->dev);vpfe_ccdc_config_defaults (ccdc);
@@ -2530,7 +2532,7 @@ static int vpfe_suspend(struct device *dev)/* only do full suspend if streaming has started */ if (vb2_start_streaming_called (&vpfe->buffer_queue)) { -pm_runtime_get_sync (dev); +pm_runtime_resume_and_get (dev);vpfe_config_enable (ccdc,1 );/* Save VPFE context */
@@ -2587,7 +2589,7 @@ static int vpfe_resume(struct device *dev)/* 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); +pm_runtime_resume_and_get (dev);vpfe_config_enable (ccdc,1 );/* Restore VPFE context */
Signature · 1 line
2.30.2
PATCH 9/78 media: sh_vou: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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 was caught at open time.
--- drivers/media/platform/sh_vou.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/sh_vou.c +5 -1
@@ -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);
Signature · 1 line
2.30.2
PATCH 10/78 media: sti/hva: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/sti/hva/hva-hw.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/media/platform/sti/hva/hva-hw.c +9 -8
@@ -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 ; }
Signature · 1 line
2.30.2
PATCH 11/78 staging: media: rkvdec: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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.
--- drivers/staging/media/rkvdec/rkvdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/rkvdec/rkvdec.c +1 -1
@@ -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 ;
Signature · 1 line
2.30.2
Re: [PATCH 11/78] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
Quoted 8 lines · Mauro Carvalho Chehab
The
pm_runtime_get_sync()internally increments thedev->power.usage_countwithout decrementing it, even on errors.
replace it by the newpm_runtime_resume_and_get(), introduced by:
commitdd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") in order to properly decrement the usage counter and avoid memory
leaks.Signed-off-by Mauro Carvalho Chehab <[email protected]>
Thanks a lot for taking care of this.
PATCH 12/78 staging: media: atomisp_fops: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/staging/media/atomisp/pci/atomisp_fops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_fops.c +3 -3
@@ -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; }
Signature · 1 line
2.30.2
PATCH 13/78 staging: media: hantro_drv: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/staging/media/hantro/hantro_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/hantro/hantro_drv.c +1 -1
@@ -155,7 +155,7 @@ 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;
Signature · 1 line
2.30.2
Re: [PATCH 13/78] staging: media: hantro_drv: use pm_runtime_resume_and_get()
Hi Mauro,
Quoted 23 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>---
drivers/staging/media/hantro/hantro_drv.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/media/hantro/hantro_drv.c +1
-1@@ -155,7 +155,7 @@ 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;
Quoted 1 line
Seems this one needs a different fix: err_cancel_job will call hantro_job_finish which has a pm_runtime put.
Thanks,
Ezequiel
Re: [PATCH 13/78] staging: media: hantro_drv: use pm_runtime_resume_and_get()
Em Sat, 24 Apr 2021 20:23:53 -0300 Ezequiel Garcia <[email protected]> escreveu:
Quoted 14 lines
Hi Mauro,
Quoted 11 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>---
drivers/staging/media/hantro/hantro_drv.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 12 lines
drivers/staging/media/hantro/hantro_drv.c +1
-1@@ -155,7 +155,7 @@ 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;Quoted 1 line
Seems this one needs a different fix:
err_cancel_jobwill callhantro_job_finishwhich has apm_runtimeput.
Good point. Thanks for reviewing it!
It sounds that this is a place where the best seems to keep using pm_runtime_get_sync(), but let's at least add a comment explaining why it should be kept here. This should help to avoid people to copy-and-paste the code on situations where pm_runtime_resume_and_get() should be used instead.
See enclosed patch.
Thanks,
Mauro
[PATCH] media: hantro: document the usage of pm_runtime_get_sync()
Despite other *_get()/*_put() functions, where usage count is incremented only if not errors, the pm_runtime_get_sync() has a different behavior, incrementing the counter *even* on errors.
That's an error prone behavior, as people often forget to decrement the usage counter.
However, the hantro driver depends on this behavior, as it will decrement the usage_count unconditionally at the m2m job finish time, which makes sense.
So, intead of using the pm_runtime_resume_and_get() that would decrement the counter on error, keep the current API, but add a documentation explaining the rationale for keep using pm_runtime_get_sync().
drivers/staging/media/hantro/hantro_drv.c +7 -0
@@ -155,6 +155,13 @@ static void device_run(void *priv) ret =clk_bulk_enable (ctx->dev->variant->num_clocks, ctx->dev->clocks);if (ret) goto err_cancel_job; + +/* +* The pm_runtime_get_sync() will increment dev->power.usage_count, +* even on errors. That's the expected behavior here, since the +* hantro_job_finish() function at the error handling code +* will internally call pm_runtime_put_autosuspend(). +*/ ret =pm_runtime_get_sync (ctx->dev->dev);if (ret <0 ) goto err_cancel_job;
Re: [PATCH 13/78] staging: media: hantro_drv: use pm_runtime_resume_and_get()
Em Mon, 26 Apr 2021 14:33:27 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:
Quoted 61 lines
Em Sat, 24 Apr 2021 20:23:53 -0300 Ezequiel Garcia <[email protected]> escreveu:
Quoted 14 lines
Hi Mauro,
Quoted 11 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>---
drivers/staging/media/hantro/hantro_drv.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 16 lines
Quoted 12 lines
drivers/staging/media/hantro/hantro_drv.c +1
-1@@ -155,7 +155,7 @@ 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;Quoted 1 line
Seems this one needs a different fix:
err_cancel_jobwill callhantro_job_finishwhich has apm_runtimeput.Good point. Thanks for reviewing it!
It sounds that this is a place where the best seems to keep using
pm_runtime_get_sync(), but let's at least add a comment explaining why it should be kept here. This should help to avoid people to copy-and-paste the code on situations wherepm_runtime_resume_and_get()should be used instead.See enclosed patch.
Thanks,
Mauro[PATCH] media: hantro: document the usage of
pm_runtime_get_sync()Despite other *_get()/*_put() functions, where usage count is incremented only if not errors, the
pm_runtime_get_sync()has a different behavior, incrementing the counter *even* on errors.That's an error prone behavior, as people often forget to decrement the usage counter.
However, the hantro driver depends on this behavior, as it will decrement the
usage_countunconditionally at the m2m job finish time, which makes sense.
Quoted 6 lines
So, intead of using the
pm_runtime_resume_and_get()that would decrement the counter on error, keep the current API, but add a documentation explaining the rationale for keep usingpm_runtime_get_sync().Signed-off-by Mauro Carvalho Chehab <[email protected]>
Hmm... maybe it can, instead, use the same solution as the rkvdec driver does, having a job_finish_no_pm() plus the normal job_finish().
What do you think?
Regards,
Mauro
Quoted 11 lines
drivers/staging/media/hantro/hantro_drv.c +0
-0@@ -155,6 +155,13 @@ static void device_run(void *priv) ret =clk_bulk_enable (ctx->dev->variant->num_clocks, ctx->dev->clocks);if (ret) goto err_cancel_job;
drivers/staging/media/hantro/hantro_drv.c static void device_run(void *priv) · line 167
Quoted 10 lines
drivers/staging/media/hantro/hantro_drv.c +7
-0+ +/* +* The pm_runtime_get_sync() will increment dev->power.usage_count, +* even on errors. That's the expected behavior here, since the +* hantro_job_finish() function at the error handling code +* will internally call pm_runtime_put_autosuspend(). +*/ ret =pm_runtime_get_sync (ctx->dev->dev);if (ret <0 ) goto err_cancel_job;
Thanks,
Mauro
PATCH 14/78 staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/media/imx/imx7-mipi-csis.c +3 -4
@@ -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;
Signature · 1 line
2.30.2
Re: [PATCH 14/78] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get()
Hi Mauro,
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Thanks, looks good.
------
Cheers,
Rui
Quoted 25 lines
--- drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/staging/media/imx/imx7-mipi-csis.c +3
-4@@ -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;Signature · 1 line
2.30.2
PATCH 15/78 staging: media: ipu3: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/staging/media/ipu3/ipu3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/media/ipu3/ipu3.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 16/78 staging: media: cedrus_video: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/staging/media/sunxi/cedrus/cedrus_video.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/media/sunxi/cedrus/cedrus_video.c +2 -4
@@ -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);
Signature · 1 line
2.30.2
PATCH 17/78 staging: media: vde: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/staging/media/tegra-vde/vde.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/staging/media/tegra-vde/vde.c +10 -6
@@ -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,8 +1071,8 @@ 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); -pm_runtime_put (dev); +if (pm_runtime_resume_and_get (dev) >=0 ) +pm_runtime_put (dev);return 0 ;
@@ -1088,8 +1090,9 @@ static int tegra_vde_remove(struct platform_device *pdev) {struct tegra_vde *vde =platform_get_drvdata (pdev);struct device *dev = &pdev->dev; +int ret; -pm_runtime_get_sync (dev); + ret =pm_runtime_resume_and_get (dev);pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);
@@ -1097,7 +1100,8 @@ static int tegra_vde_remove(struct platform_device *pdev)* Balance RPM state, the VDE power domain is left ON and hardware * is clock-gated. It's safe to reboot machine now. */ -pm_runtime_put_noidle (dev); +if (ret >=0 ) +pm_runtime_put_noidle (dev);clk_disable_unprepare (vde->clk);misc_deregister (&vde->miscdev);
Signature · 1 line
2.30.2
Re: [PATCH 17/78] staging: media: vde: use pm_runtime_resume_and_get()
24.04.2021 09:44, Mauro Carvalho Chehab пишет:
Quoted 60 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/staging/media/tegra-vde/vde.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)drivers/staging/media/tegra-vde/vde.c +8
-5@@ -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,8 +1071,8 @@ 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); -pm_runtime_put (dev); +if (pm_runtime_resume_and_get (dev) >=0 ) +pm_runtime_put (dev);return 0 ;@@ -1088,8 +1090,9 @@ static int tegra_vde_remove(struct platform_device *pdev) {struct tegra_vde *vde =platform_get_drvdata (pdev);struct device *dev = &pdev->dev; +int ret; -pm_runtime_get_sync (dev); + ret =pm_runtime_resume_and_get (dev);pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);
drivers/staging/media/tegra-vde/vde.c static int tegra_vde_remove(struct platform_device *pdev) · line 1107
Quoted 9 lines
drivers/staging/media/tegra-vde/vde.c +2
-1@@ -1097,7 +1100,8 @@ static int tegra_vde_remove(struct platform_device *pdev)* Balance RPM state, the VDE power domain is left ON and hardware * is clock-gated. It's safe to reboot machine now. */ -pm_runtime_put_noidle (dev); +if (ret >=0 ) +pm_runtime_put_noidle (dev);clk_disable_unprepare (vde->clk);misc_deregister (&vde->miscdev);
Hello Mauro,
Thank you very much for the patch. It looks to me that the original variant was a bit simpler, this patch adds more code lines without changing the previous behaviour. Or am I missing something?
Re: [PATCH 17/78] staging: media: vde: use pm_runtime_resume_and_get()
Hi Dmitry,
Em Sat, 24 Apr 2021 10:35:22 +0300
Dmitry Osipenko <[email protected]> escreveu:
Quoted 68 lines
24.04.2021 09:44, Mauro Carvalho Chehab пишет:
Quoted 67 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/staging/media/tegra-vde/vde.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)drivers/staging/media/tegra-vde/vde.c +10
-6@@ -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,8 +1071,8 @@ 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); -pm_runtime_put (dev); +if (pm_runtime_resume_and_get (dev) >=0 ) +pm_runtime_put (dev);return 0 ;@@ -1088,8 +1090,9 @@ static int tegra_vde_remove(struct platform_device *pdev) {struct tegra_vde *vde =platform_get_drvdata (pdev);struct device *dev = &pdev->dev; +int ret; -pm_runtime_get_sync (dev); + ret =pm_runtime_resume_and_get (dev);pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);@@ -1097,7 +1100,8 @@ static int tegra_vde_remove(struct platform_device *pdev)* Balance RPM state, the VDE power domain is left ON and hardware * is clock-gated. It's safe to reboot machine now. */ -pm_runtime_put_noidle (dev); +if (ret >=0 ) +pm_runtime_put_noidle (dev);clk_disable_unprepare (vde->clk);
Quoted 8 lines
drivers/staging/media/tegra-vde/vde.c static int tegra_vde_remove(struct platform_device *pdev) · line 1107
Quoted 2 lines
drivers/staging/media/tegra-vde/vde.c +0
-0misc_deregister (&vde->miscdev);Hello Mauro,
Thank you very much for the patch. It looks to me that the original variant was a bit simpler, this patch adds more code lines without changing the previous behaviour. Or am I missing something?
While on several places the newer code is simpler, the end goal here is to replace all occurrences of pm_runtime_get_sync() from the media subsystem, due to the number of problems we're having with this:
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 ;-)
The name of the new variant is a lot clearer:
pm_runtime_resume_and_get()
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. 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;
4. 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.
Thanks,
Mauro
Re: [PATCH 17/78] staging: media: vde: use pm_runtime_resume_and_get()
Quoted 81 lines · Mauro Carvalho Chehab
Hi Dmitry,
Em Sat, 24 Apr 2021 10:35:22 +0300
Dmitry Osipenko <[email protected]> escreveu:Quoted 76 lines
24.04.2021 09:44, Mauro Carvalho Chehab пишет:
Quoted 60 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/staging/media/tegra-vde/vde.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)drivers/staging/media/tegra-vde/vde.c +8
-5@@ -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,8 +1071,8 @@ 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); -pm_runtime_put (dev); +if (pm_runtime_resume_and_get (dev) >=0 ) +pm_runtime_put (dev);return 0 ;@@ -1088,8 +1090,9 @@ static int tegra_vde_remove(struct platform_device *pdev) {struct tegra_vde *vde =platform_get_drvdata (pdev);struct device *dev = &pdev->dev; +int ret; -pm_runtime_get_sync (dev); + ret =pm_runtime_resume_and_get (dev);pm_runtime_dont_use_autosuspend (dev);pm_runtime_disable (dev);drivers/staging/media/tegra-vde/vde.c static int tegra_vde_remove(struct platform_device *pdev) · line 1107
Quoted 9 lines
drivers/staging/media/tegra-vde/vde.c +2
-1@@ -1097,7 +1100,8 @@ static int tegra_vde_remove(struct platform_device *pdev)* Balance RPM state, the VDE power domain is left ON and hardware * is clock-gated. It's safe to reboot machine now. */ -pm_runtime_put_noidle (dev); +if (ret >=0 ) +pm_runtime_put_noidle (dev);clk_disable_unprepare (vde->clk);misc_deregister (&vde->miscdev);Hello Mauro,
Thank you very much for the patch. It looks to me that the original variant was a bit simpler, this patch adds more code lines without changing the previous behaviour. Or am I missing something?
I agree, the above does not look like an improvement at all.
Quoted 8 lines
While on several places the newer code is simpler, the end goal here is to replace all occurrences of
pm_runtime_get_sync()from the media subsystem, due to the number of problems we're having with this: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:
Quoted 6 lines
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 ;-)
It very well may. You're resuming the device and leaving it a defined power state before balancing the PM count, cleaning up and unbinding the driver.
Quoted 2 lines
The name of the new variant is a lot clearer:
pm_runtime_resume_and_get()
For people not used to the API perhaps.
Quoted 4 lines
2. Usual
*_get()methods only increment their use count on success, butpm_runtime_get_sync()increments it unconditionally. Due to that, several drivers were mistakenly not callingpm_runtime_put_noidle()when it fails;
As I mentioned elsewhere, all pm_runtime_get calls increment the usage count so the API is consistent.
Quoted 4 lines
3. Consistency: we did similar changes subsystem wide with for instance
strlcpy()andstrcpy()that got replaced bystrscpy(). Having all drivers using the same known-to-be-safe methods is a good thing;
There's no know-to-be safe API. People will find ways to get this wrong too.
And the old interface isn't going away from the kernel even if you manage to not use it in media.
Quoted 3 lines
4. 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.
Johan
PATCH 18/78 staging: media: csi: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/staging/media/tegra-video/csi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/media/tegra-video/csi.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 19/78 staging: media: vi: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/staging/media/tegra-video/vi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/media/tegra-video/vi.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 20/78 media: mtk-vcodec: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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.
--- drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c +2 -2
@@ -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)
Signature · 1 line
2.30.2
PATCH 21/78 media: s5p-jpeg: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +1 -1
@@ -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; }
Signature · 1 line
2.30.2
Re: [PATCH 21/78] media: s5p-jpeg: fix pm_runtime_get_sync() usage count
Quoted 3 lines · Mauro Carvalho Chehab
The
pm_runtime_get_sync()internally increments thedev->power.usage_countwithout decrementing it, even on errors. replace it by the newpm_runtime_resume_and_get(), introduced by:
s/replace/Replace
Quoted 3 lines
commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") in order to properly decrement the usage counter and avoid memory
leaks.
Thank you for the patch. I'm not sure if that could cause any memory leaks, for sure not optimal power handling for the device.
Quoted 1 line
Signed-off-by Mauro Carvalho Chehab <[email protected]>
PATCH 22/78 media: delta-v4l2: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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.
--- drivers/media/platform/sti/delta/delta-v4l2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/sti/delta/delta-v4l2.c +2 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 23/78 media: sun8i_rotate: fix pm_runtime_get_sync() usage count
In reply to Mauro Carvalho ChehabThe pm_runtime_get_sync() internally increments thedev->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.
--- drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c +1 -1
@@ -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" );
Signature · 1 line
2.30.2
PATCH 24/78 media: i2c: ak7375: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ak7375.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/media/i2c/ak7375.c +1 -9
@@ -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)
Signature · 1 line
2.30.2
PATCH 25/78 media: i2c: ccs-core: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ccs/ccs-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +5 -6
@@ -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,7 +3088,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)bool streaming = sensor->streaming;int rval; - rval =pm_runtime_get_sync (dev); + rval =pm_runtime_resume_and_get (dev);if (rval <0 ) {pm_runtime_put_noidle (dev);
Signature · 1 line
2.30.2
Sakari Ailus
maintainerRe: [PATCH 25/78] media: i2c: ccs-core: use pm_runtime_resume_and_get()
Hi Mauro,
Thanks for the patch.
Quoted 33 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/media/i2c/ccs/ccs-core.c +4
-5@@ -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)
drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3093
Quoted 7 lines
drivers/media/i2c/ccs/ccs-core.c +1
-1@@ -3089,7 +3088,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)bool streaming = sensor->streaming;int rval; - rval =pm_runtime_get_sync (dev); + rval =pm_runtime_resume_and_get (dev);if (rval <0 ) {pm_runtime_put_noidle (dev);
You'll need to drop pm_runtime_put_noidle() here.
Signature · 3 lines
Regards, Sakari Ailus
Re: [PATCH 25/78] media: i2c: ccs-core: use pm_runtime_resume_and_get()
Em Sun, 25 Apr 2021 21:55:25 +0300
Sakari Ailus <[email protected]> escreveu:
Quoted 41 lines
Hi Mauro,
Thanks for the patch.
Quoted 36 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/media/i2c/ccs/ccs-core.c +4
-5@@ -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,7 +3088,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)bool streaming = sensor->streaming;int rval;
Quoted 6 lines
drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3093
Quoted 4 lines
drivers/media/i2c/ccs/ccs-core.c +1
-1- rval =pm_runtime_get_sync (dev); + rval =pm_runtime_resume_and_get (dev);if (rval <0 ) {pm_runtime_put_noidle (dev);You'll need to drop
pm_runtime_put_noidle()here.
OK!
---
On a non-related issue at the same code, after the change, the suspend function will be:
static int __maybe_unused ccs_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct v4l2_subdev *subdev = i2c_get_clientdata(client);
struct ccs_sensor *sensor = to_ccs_sensor(subdev);
bool streaming = sensor->streaming;
int rval; rval = pm_runtime_resume_and_get(dev);
if (rval < 0)
return -EAGAIN;
if (sensor->streaming)
ccs_stop_streaming(sensor);
/* save state for resume */
sensor->streaming = streaming;
return 0;}
Not sure if "return -EAGAIN" is the right thing here. I mean, the PM runtime core has two error conditions that are independent on whatever the PM callback would be doing[1]:
if (dev->power.runtime_error)
retval = -EINVAL;
else if (dev->power.disable_depth > 0)
retval = -EACCES;It would be very unlikely that trying to suspend again would solve those conditions.
So, I guess that the right thing to do is to change the code to do, instead:
static int __maybe_unused ccs_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct v4l2_subdev *subdev = i2c_get_clientdata(client);
struct ccs_sensor *sensor = to_ccs_sensor(subdev);
bool streaming = sensor->streaming;
int rval; rval = pm_runtime_resume_and_get(dev);
if (rval < 0)
return rval;
...}
[1] see rpm_resume() code at drivers/base/power/runtime.c.
Thanks,
Mauro
Re: [PATCH 25/78] media: i2c: ccs-core: use pm_runtime_resume_and_get()
Hi Mauro,
Quoted 102 lines · Mauro Carvalho Chehab
Em Sun, 25 Apr 2021 21:55:25 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 41 lines
Hi Mauro,
Thanks for the patch.
Quoted 36 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/media/i2c/ccs/ccs-core.c +4
-5@@ -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,7 +3088,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)bool streaming = sensor->streaming;int rval;Quoted 6 lines
drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3093
Quoted 4 lines
drivers/media/i2c/ccs/ccs-core.c +1
-1- rval =pm_runtime_get_sync (dev); + rval =pm_runtime_resume_and_get (dev);if (rval <0 ) {pm_runtime_put_noidle (dev);You'll need to drop
pm_runtime_put_noidle()here.OK!
---
On a non-related issue at the same code, after the change, the suspend function will be:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;rval = pm_runtime_resume_and_get(dev); if (rval < 0) return -EAGAIN; if (sensor->streaming) ccs_stop_streaming(sensor); /* save state for resume */ sensor->streaming = streaming; return 0;}
Not sure if "return
-EAGAIN" is the right thing here. I mean, the PM runtime core has two error conditions that are independent on whatever the PM callback would be doing[1]:if (dev->power.runtime_error) retval = -EINVAL; else if (dev->power.disable_depth > 0) retval = -EACCES;It would be very unlikely that trying to suspend again would solve those conditions.
So, I guess that the right thing to do is to change the code to do, instead:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;
Quoted 8 lines
rval = pm_runtime_resume_and_get(dev); if (rval < 0) return rval; ...}
[1] see
rpm_resume()code atdrivers/base/power/runtime.c.
Yeah, I agree. This code is one of the older parts the driver.
Please add:
The same goes for the other sensor driver patches in the set you cc'd me, i.e. patches 12, 15, 26, 28,32, 40, 45, 51, 53 and 55.
Signature · 3 lines
Kind regards, Sakari Ailus
Re: [PATCH 25/78] media: i2c: ccs-core: use pm_runtime_resume_and_get()
Em Mon, 26 Apr 2021 17:09:00 +0300
Sakari Ailus <[email protected]> escreveu:
Quoted 114 lines
Hi Mauro,
Quoted 102 lines · Mauro Carvalho Chehab
Em Sun, 25 Apr 2021 21:55:25 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 41 lines
Hi Mauro,
Thanks for the patch.
Quoted 36 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/media/i2c/ccs/ccs-core.c +4
-5@@ -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,7 +3088,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)bool streaming = sensor->streaming;int rval;Quoted 6 lines
drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3093
Quoted 4 lines
drivers/media/i2c/ccs/ccs-core.c +1
-1- rval =pm_runtime_get_sync (dev); + rval =pm_runtime_resume_and_get (dev);if (rval <0 ) {pm_runtime_put_noidle (dev);You'll need to drop
pm_runtime_put_noidle()here.OK!
---
On a non-related issue at the same code, after the change, the suspend function will be:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;rval = pm_runtime_resume_and_get(dev); if (rval < 0) return -EAGAIN; if (sensor->streaming) ccs_stop_streaming(sensor); /* save state for resume */ sensor->streaming = streaming; return 0;}
Not sure if "return
-EAGAIN" is the right thing here. I mean, the PM runtime core has two error conditions that are independent on whatever the PM callback would be doing[1]:if (dev->power.runtime_error) retval = -EINVAL; else if (dev->power.disable_depth > 0) retval = -EACCES;It would be very unlikely that trying to suspend again would solve those conditions.
So, I guess that the right thing to do is to change the code to do, instead:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;Quoted 8 lines
rval = pm_runtime_resume_and_get(dev); if (rval < 0) return rval; ...}
[1] see
rpm_resume()code atdrivers/base/power/runtime.c.
Quoted 8 lines
Yeah, I agree. This code is one of the older parts the driver.
Please add:
Acked-by Sakari Ailus <[email protected]>The same goes for the other sensor driver patches in the set you cc'd me, i.e. patches 12, 15, 26, 28,32, 40, 45, 51, 53 and 55.
It probably makes sense to address the suspend/resume -EAGAIN return code on a separate patch series, before this one, as:
1. this is unrelated to this change;
2. it is something that should be c/c to fixes. So, having it before this series makes easier to apply there.
Thanks,
Mauro
Sakari Ailus
maintainerRe: [PATCH 25/78] media: i2c: ccs-core: use pm_runtime_resume_and_get()
Quoted 126 lines · Mauro Carvalho Chehab
Em Mon, 26 Apr 2021 17:09:00 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 114 lines
Hi Mauro,
Quoted 102 lines · Mauro Carvalho Chehab
Em Sun, 25 Apr 2021 21:55:25 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 41 lines
Hi Mauro,
Thanks for the patch.
Quoted 36 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/media/i2c/ccs/ccs-core.c +4
-5@@ -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,7 +3088,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)bool streaming = sensor->streaming;int rval;Quoted 6 lines
drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3093
Quoted 4 lines
drivers/media/i2c/ccs/ccs-core.c +1
-1- rval =pm_runtime_get_sync (dev); + rval =pm_runtime_resume_and_get (dev);if (rval <0 ) {pm_runtime_put_noidle (dev);You'll need to drop
pm_runtime_put_noidle()here.OK!
---
On a non-related issue at the same code, after the change, the suspend function will be:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;rval = pm_runtime_resume_and_get(dev); if (rval < 0) return -EAGAIN; if (sensor->streaming) ccs_stop_streaming(sensor); /* save state for resume */ sensor->streaming = streaming; return 0;}
Not sure if "return
-EAGAIN" is the right thing here. I mean, the PM runtime core has two error conditions that are independent on whatever the PM callback would be doing[1]:if (dev->power.runtime_error) retval = -EINVAL; else if (dev->power.disable_depth > 0) retval = -EACCES;It would be very unlikely that trying to suspend again would solve those conditions.
So, I guess that the right thing to do is to change the code to do, instead:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;Quoted 8 lines
rval = pm_runtime_resume_and_get(dev); if (rval < 0) return rval; ...}
[1] see
rpm_resume()code atdrivers/base/power/runtime.c.Quoted 8 lines
Yeah, I agree. This code is one of the older parts the driver.
Please add:
Acked-by Sakari Ailus <[email protected]>The same goes for the other sensor driver patches in the set you cc'd me, i.e. patches 12, 15, 26, 28,32, 40, 45, 51, 53 and 55.
Quoted 6 lines
It probably makes sense to address the suspend/resume
-EAGAINreturn code on a separate patch series, before this one, as:1. this is unrelated to this change;
2. it is something that should be c/c to fixes. So, having it before this series makes easier to apply there.
Sounds good to me. If you can submit a patch, please add my ack. :-)
Signature · 1 line
Sakari Ailus
Re: [PATCH 25/78] media: i2c: ccs-core: use pm_runtime_resume_and_get()
Em Mon, 26 Apr 2021 17:29:02 +0300
Sakari Ailus <[email protected]> escreveu:
Quoted 127 lines · Mauro Carvalho Chehab
Quoted 126 lines
Em Mon, 26 Apr 2021 17:09:00 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 122 lines
Hi Mauro,
Quoted 102 lines · Mauro Carvalho Chehab
Em Sun, 25 Apr 2021 21:55:25 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 41 lines
Hi Mauro,
Thanks for the patch.
Quoted 36 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/media/i2c/ccs/ccs-core.c +4
-5@@ -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,7 +3088,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)bool streaming = sensor->streaming;int rval;Quoted 6 lines
drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3093
Quoted 4 lines
drivers/media/i2c/ccs/ccs-core.c +1
-1- rval =pm_runtime_get_sync (dev); + rval =pm_runtime_resume_and_get (dev);if (rval <0 ) {pm_runtime_put_noidle (dev);You'll need to drop
pm_runtime_put_noidle()here.OK!
---
On a non-related issue at the same code, after the change, the suspend function will be:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;rval = pm_runtime_resume_and_get(dev); if (rval < 0) return -EAGAIN; if (sensor->streaming) ccs_stop_streaming(sensor); /* save state for resume */ sensor->streaming = streaming; return 0;}
Not sure if "return
-EAGAIN" is the right thing here. I mean, the PM runtime core has two error conditions that are independent on whatever the PM callback would be doing[1]:if (dev->power.runtime_error) retval = -EINVAL; else if (dev->power.disable_depth > 0) retval = -EACCES;It would be very unlikely that trying to suspend again would solve those conditions.
So, I guess that the right thing to do is to change the code to do, instead:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;Quoted 8 lines
rval = pm_runtime_resume_and_get(dev); if (rval < 0) return rval; ...}
[1] see
rpm_resume()code atdrivers/base/power/runtime.c.Yeah, I agree. This code is one of the older parts the driver.
Please add:
Acked-by Sakari Ailus <[email protected]>The same goes for the other sensor driver patches in the set you cc'd me, i.e. patches 12, 15, 26, 28,32, 40, 45, 51, 53 and 55.
Quoted 8 lines
Quoted 6 lines
It probably makes sense to address the suspend/resume
-EAGAINreturn code on a separate patch series, before this one, as:1. this is unrelated to this change;
2. it is something that should be c/c to fixes. So, having it before this series makes easier to apply there.Sounds good to me. If you can submit a patch, please add my ack. :-)
Sure. I'll work on such patch series.
Thanks!
Mauro
Mauro Carvalho Chehab
maintainerRe: [PATCH 25/78] media: i2c: ccs-core: use pm_runtime_resume_and_get()
Hi Sakari,
Em Mon, 26 Apr 2021 19:32:23 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:
Quoted 13 lines
Em Mon, 26 Apr 2021 17:29:02 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 10 lines · Mauro Carvalho Chehab
Quoted 9 lines
Em Mon, 26 Apr 2021 17:09:00 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 6 lines
Hi Mauro,
Quoted 3 lines · Mauro Carvalho Chehab
Em Sun, 25 Apr 2021 21:55:25 +0300
Sakari Ailus <[email protected]> escreveu:
...
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 56 lines
Quoted 47 lines
On a non-related issue at the same code, after the change, the suspend function will be:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;rval = pm_runtime_resume_and_get(dev); if (rval < 0) return -EAGAIN; if (sensor->streaming) ccs_stop_streaming(sensor); /* save state for resume */ sensor->streaming = streaming; return 0;}
Not sure if "return
-EAGAIN" is the right thing here. I mean, the PM runtime core has two error conditions that are independent on whatever the PM callback would be doing[1]:if (dev->power.runtime_error) retval = -EINVAL; else if (dev->power.disable_depth > 0) retval = -EACCES;It would be very unlikely that trying to suspend again would solve those conditions.
So, I guess that the right thing to do is to change the code to do, instead:
static int __maybe_unused ccs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *subdev = i2c_get_clientdata(client); struct ccs_sensor *sensor = to_ccs_sensor(subdev); bool streaming = sensor->streaming; int rval;Quoted 8 lines
rval = pm_runtime_resume_and_get(dev); if (rval < 0) return rval; ...}
[1] see
rpm_resume()code atdrivers/base/power/runtime.c.Quoted 8 lines
Yeah, I agree. This code is one of the older parts the driver.
Please add:
Acked-by Sakari Ailus <[email protected]>The same goes for the other sensor driver patches in the set you cc'd me, i.e. patches 12, 15, 26, 28,32, 40, 45, 51, 53 and 55.
It probably makes sense to address the suspend/resume
-EAGAINreturn code on a separate patch series, before this one, as:
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
1. this is unrelated to this change;
2. it is something that should be c/c to fixes. So, having it before this series makes easier to apply there.Sounds good to me. If you can submit a patch, please add my ack. :-)
Sure. I'll work on such patch series.
I checked the files affected by those patches:
12, 15, 26, 28,32, 40, 45, 51, 53 and 55, e.g.:
drivers/staging/media/atomisp/pci/atomisp_fops.c drivers/staging/media/ipu3/ipu3.c drivers/media/i2c/dw9714.c drivers/media/i2c/dw9807-vcm.c drivers/media/i2c/imx258.c drivers/media/i2c/ov13858.c drivers/media/i2c/ov8865.c drivers/media/i2c/tvp5150.c drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
I also double-checked the I2C drivers that use SET_SYSTEM_SLEEP_PM_OPS(). None of them are calling pm_runtime_* at suspend time, except for the ccs-core.
So, I ended writing just a patch for ccs-core, to be applied before this /78 series.
Thanks,
Mauro
PATCH 26/78 media: i2c: dw9714: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/dw9714.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/media/i2c/dw9714.c +1 -9
@@ -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)
Signature · 1 line
2.30.2
PATCH 27/78 media: i2c: dw9768: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/dw9768.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/media/i2c/dw9768.c +1 -9
@@ -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)
Signature · 1 line
2.30.2
PATCH 28/78 media: i2c: dw9807-vcm: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/dw9807-vcm.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/media/i2c/dw9807-vcm.c +1 -9
@@ -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)
Signature · 1 line
2.30.2
PATCH 29/78 media: i2c: hi556: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/hi556.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/hi556.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 30/78 media: i2c: imx214: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/imx214.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx214.c +2 -4
@@ -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 )
Signature · 1 line
2.30.2
PATCH 31/78 media: i2c: imx219: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/imx219.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx219.c +2 -4
@@ -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;
Signature · 1 line
2.30.2
PATCH 32/78 media: i2c: imx258: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/imx258.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx258.c +2 -4
@@ -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
Signature · 1 line
2.30.2
PATCH 33/78 media: i2c: imx274: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/imx274.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/imx274.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 34/78 media: i2c: imx290: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/imx290.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx290.c +2 -4
@@ -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) {
Signature · 1 line
2.30.2
PATCH 35/78 media: i2c: imx319: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/imx319.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx319.c +2 -4
@@ -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
Signature · 1 line
2.30.2
PATCH 36/78 media: i2c: imx334: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/imx334.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/imx334.c +3 -2
@@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable) }if (enable) { - ret =pm_runtime_get_sync (imx334->dev); + ret =pm_runtime_resume_and_get (imx334->dev);if (ret) - goto error_power_off; + 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;
Signature · 1 line
2.30.2
Re: [PATCH 36/78] media: i2c: imx334: use pm_runtime_resume_and_get()
Hi Mauro,
Thanks for the patch.
Quoted 37 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter")
addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/i2c/imx334.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/media/i2c/imx334.c +2
-2@@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable) }if (enable) { - ret =pm_runtime_get_sync (imx334->dev); + ret =pm_runtime_resume_and_get (imx334->dev);if (ret) - goto error_power_off; + goto error_unlock; ret =imx334_start_streaming (imx334);drivers/media/i2c/imx334.c +1
-0if (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);
Quoted 1 line
return ret;
Looks good to me.
PATCH 37/78 media: i2c: imx355: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/imx355.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx355.c +2 -4
@@ -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
Signature · 1 line
2.30.2
PATCH 38/78 media: i2c: mt9m001: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/mt9m001.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/i2c/mt9m001.c +4 -3
@@ -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,7 +835,7 @@ static int mt9m001_remove(struct i2c_client *client) {struct mt9m001 *mt9m001 =to_mt9m001 (client); -pm_runtime_get_sync (&client->dev); +pm_runtime_resume_and_get (&client->dev);v4l2_async_unregister_subdev (&mt9m001->subdev);media_entity_cleanup (&mt9m001->subdev.entity);
Signature · 1 line
2.30.2
Re: [PATCH 38/78] media: i2c: mt9m001: use pm_runtime_resume_and_get()
Hi Mauro,
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Thanks
I should re-work the error handling sequence there on top of this patch as right now it's not the best, that 'done' label bothers me... anyway, for later.
Quoted 40 lines
--- drivers/media/i2c/mt9m001.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/media/i2c/mt9m001.c +4
-4@@ -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,7 +835,7 @@ static int mt9m001_remove(struct i2c_client *client) {struct mt9m001 *mt9m001 =to_mt9m001 (client); -pm_runtime_get_sync (&client->dev); +pm_runtime_resume_and_get (&client->dev);v4l2_async_unregister_subdev (&mt9m001->subdev);media_entity_cleanup (&mt9m001->subdev.entity); --2.30.2
Re: [PATCH 38/78] media: i2c: mt9m001: use pm_runtime_resume_and_get()
Quoted 50 lines · Jacopo Mondi
Hi Mauro,
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>Thanks
Acked-by Jacopo Mondi <[email protected]>I should re-work the error handling sequence there on top of this patch as right now it's not the best, that 'done' label bothers me... anyway, for later.
Quoted 32 lines
--- drivers/media/i2c/mt9m001.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/media/i2c/mt9m001.c +3
-2@@ -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,7 +835,7 @@ static int mt9m001_remove(struct i2c_client *client) {struct mt9m001 *mt9m001 =to_mt9m001 (client);
Quoted 5 lines
drivers/media/i2c/mt9m001.c static int mt9m001_remove(struct i2c_client *client) · line 841
Quoted 5 lines
drivers/media/i2c/mt9m001.c +1
-1-pm_runtime_get_sync (&client->dev); +pm_runtime_resume_and_get (&client->dev);v4l2_async_unregister_subdev (&mt9m001->subdev);media_entity_cleanup (&mt9m001->subdev.entity);
I couldn't help looking at one more now that you got feedback on this one.
Here you have the same problem as the one I reported earlier, in that the usage count could end up negative on resume failure due to the later put_noidle() call in remove().
Also note that you're adding more lines than you're removing.
I'd say this kind of mass-conversion is of questionable worth as pm_runtime_resume_and_get() isn't necessarily an improvement (even if it may have its use in some places).
Johan
Re: [PATCH 38/78] media: i2c: mt9m001: use pm_runtime_resume_and_get()
Em Sat, 24 Apr 2021 12:00:46 +0200
Johan Hovold <[email protected]> escreveu:
Quoted 60 lines · Jacopo Mondi
Quoted 50 lines
Hi Mauro,
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>Thanks
Acked-by Jacopo Mondi <[email protected]>I should re-work the error handling sequence there on top of this patch as right now it's not the best, that 'done' label bothers me... anyway, for later.
Quoted 32 lines
--- drivers/media/i2c/mt9m001.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/media/i2c/mt9m001.c +3
-2@@ -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,7 +835,7 @@ static int mt9m001_remove(struct i2c_client *client) {struct mt9m001 *mt9m001 =to_mt9m001 (client);Quoted 5 lines
drivers/media/i2c/mt9m001.c static int mt9m001_remove(struct i2c_client *client) · line 841
Quoted 5 lines
drivers/media/i2c/mt9m001.c +1
-1-pm_runtime_get_sync (&client->dev); +pm_runtime_resume_and_get (&client->dev);v4l2_async_unregister_subdev (&mt9m001->subdev);media_entity_cleanup (&mt9m001->subdev.entity);I couldn't help looking at one more now that you got feedback on this one.
Quoted 3 lines
Here you have the same problem as the one I reported earlier, in that the usage count could end up negative on resume failure due to the later
put_noidle()call inremove().
I'll double-check this at the entire series. Different sensor drivers are handling this on different ways, which sounds bad, as they are meant to be independent on the media bridge driver.
Quoted 1 line
Also note that you're adding more lines than you're removing.
Ok, but the end goal is not really reducing the number of lines, but to have the code following the same pattern, and to avoid cut-and-paste errors when new drivers are written.
The mt9m001 is one of the oldest sensor drivers, written a long time before the PM runtime core, written for the soc_camera driver, back in 2008. The port to use PM runtime isn't old:
commit 8fcfc491c6ca5887bb341b3a622cca3ed8e3c9f0
Author: Akinobu Mita <[email protected]>
Date: Tue Jan 8 12:51:44 2019 -0200
media: mt9m001: switch s_power callback to runtime PM
It was part of an attempt to recover the soc_camera sensor drives from staging.
Yet, the logic on this driver seems to be different than the one used on more modern I2C sensors. So, better to re-check everything.
Quoted 3 lines
I'd say this kind of mass-conversion is of questionable worth as
pm_runtime_resume_and_get()isn't necessarily an improvement (even if it may have its use in some places).
The main problem is that other parts of the driver's core APIs assume that get object methods will only increment the usage counter if no errors. The pm_runtime_get_sync() is an exception.
Its name doesn't help at all: A function like that should, IMHO, be called, instead:
pm_runtime_inc_usage_count_and_try_to_resume().
Or something similar, in order to make clearer that it always increment the usage count, no matter what. If possible, all drivers should get rid of it too (or alternatively add comments warning people that keeping the usage_count incremented is desired on the very specific places where it is really needed), as it is risky to use something that has a different usage_count increement behavior than other more usual *_get() functions.
With regards to mass-fixing it, I've seen several patches seen to media fixing bugs due to the bad usage_count decrement logic. So, the best is to solve them all at once, and stop using pm_runtime_get_sync() inside the subsystem.
Thanks,
Mauro
Re: [PATCH 38/78] media: i2c: mt9m001: use pm_runtime_resume_and_get()
Quoted 28 lines · Mauro Carvalho Chehab
Em Sat, 24 Apr 2021 12:00:46 +0200
Johan Hovold <[email protected]> escreveu:Quoted 8 lines · Jacopo Mondi
Quoted 7 lines
Hi Mauro,
Quoted 4 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>I'd say this kind of mass-conversion is of questionable worth as
pm_runtime_resume_and_get()isn't necessarily an improvement (even if it may have its use in some places).The main problem is that other parts of the driver's core APIs assume that get object methods will only increment the usage counter if no errors. The
pm_runtime_get_sync()is an exception.Its name doesn't help at all: A function like that should, IMHO, be called, instead:
pm_runtime_inc_usage_count_and_try_to_resume().
Quoted 7 lines
Or something similar, in order to make clearer that it always increment the usage count, no matter what. If possible, all drivers should get rid of it too (or alternatively add comments warning people that keeping the
usage_countincremented is desired on the very specific places where it is really needed), as it is risky to use something that has a differentusage_countincreement behavior than other more usual*_get()functions.
pm_runtime_get_sync() has worked this way since it was merged 12 years ago, and for someone who's used to this interface this is not such a big deal as you seem to think. Sure, you need to remember to put the usage counter on errors, but that's it (and the other side of that is that you don't need to worry about error handling where it doesn't matter).
Also note all the pm_runtime_get functions *always* increment the usage count even if an async resume may later fail so there is consistency here.
And regarding naming, the new pm_resume_and_get() looks completely out of place to me since it uses a different naming scheme than the other helpers (including the ones that are used to balance the new call).
Quoted 4 lines
With regards to mass-fixing it, I've seen several patches seen to media fixing bugs due to the bad
usage_countdecrement logic. So, the best is to solve them all at once, and stop usingpm_runtime_get_sync()inside the subsystem.
Sure, having the script kiddies patch drivers without understanding what they're are really doing is bound to introduce bugs unless it can be caught in review.
You're call, but converting functioning drivers where the authors knew what they were doing just because you're not used to the API and risk introducing new bugs in the process isn't necessarily a good idea. Especially since the pm_runtime_get_sync() will continue to be used elsewhere, and possibly even in media in cases where you don't need to check for errors (e.g. remove()).
Johan
Re: [PATCH 38/78] media: i2c: mt9m001: use pm_runtime_resume_and_get()
Em Tue, 27 Apr 2021 14:23:20 +0200
Johan Hovold <[email protected]> escreveu:
Quoted 37 lines · Mauro Carvalho Chehab
Quoted 28 lines
Em Sat, 24 Apr 2021 12:00:46 +0200
Johan Hovold <[email protected]> escreveu:Quoted 8 lines · Jacopo Mondi
Quoted 7 lines
Hi Mauro,
Quoted 4 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>I'd say this kind of mass-conversion is of questionable worth as
pm_runtime_resume_and_get()isn't necessarily an improvement (even if it may have its use in some places).The main problem is that other parts of the driver's core APIs assume that get object methods will only increment the usage counter if no errors. The
pm_runtime_get_sync()is an exception.Its name doesn't help at all: A function like that should, IMHO, be called, instead:
pm_runtime_inc_usage_count_and_try_to_resume().Quoted 7 lines
Or something similar, in order to make clearer that it always increment the usage count, no matter what. If possible, all drivers should get rid of it too (or alternatively add comments warning people that keeping the
usage_countincremented is desired on the very specific places where it is really needed), as it is risky to use something that has a differentusage_countincreement behavior than other more usual*_get()functions.
Quoted 5 lines
pm_runtime_get_sync()has worked this way since it was merged 12 years ago, and for someone who's used to this interface this is not such a big deal as you seem to think. Sure, you need to remember to put the usage counter on errors, but that's it (and the other side of that is that you don't need to worry about error handling where it doesn't matter).
Before we have those at PM subsystem, the media had its own way to set/disable power for their sub-devices. The PCI and USB drivers still use it, instead of pm_runtime, mostly due to historic reasons.
So, basically, its usage at the media subsystem is restricted to drivers for embedded systems. The vast majority of drivers supporting PM runtime are the I2C camera drivers. The camera drivers can be used interchangeable. So, in practice, the same bridge driver can work with a lot of different camera models, depending on the hardware vendors' personal preferences and the desired max resolution.
So, in thesis, all such drivers should behave exactly the same with regards to PM.
However, on most existing drivers, the pm_runtime was added a couple of years ago, and by people that are not too familiar with the PM subsystem.
That probably explains why there were/are several places that do things like this[1]:
ret = pm_runtime_get_sync(dev); if (ret < 0) return ret;
without taking care of calling a pm_runtime_put*() function.
[1] besides the 13 patches made by UCN addressing it on existing code, I discovered the same pattern on a couple of other drivers with current upstream code.
That shows a pattern: several media developers are not familiar with the usage_count behavior for pm_runtime_get functions.
So, doing this work is not only helping to make the PM support more uniform, but it is also helping to solve existing issues.
Quoted 8 lines
Also note all the
pm_runtime_getfunctions *always* increment the usage count even if an async resume may later fail so there is consistency here.And regarding naming, the new
pm_resume_and_get()looks completely out of place to me since it uses a different naming scheme than the other helpers (including the ones that are used to balance the new call).
Quoted 8 lines
Quoted 4 lines
With regards to mass-fixing it, I've seen several patches seen to media fixing bugs due to the bad
usage_countdecrement logic. So, the best is to solve them all at once, and stop usingpm_runtime_get_sync()inside the subsystem.Sure, having the script kiddies patch drivers without understanding what they're are really doing is bound to introduce bugs unless it can be caught in review.
Yes, but as I pointed, the current code has bugs already.
Quoted 3 lines
You're call, but converting functioning drivers where the authors knew what they were doing just because you're not used to the API and risk introducing new bugs in the process isn't necessarily a good idea.
The problem is that the above assumption is not necessarily true:
based on the number of drivers that pm_runtime_get_sync() weren't decrementing usage_count on errors, several driver authors were not familiar enough with the PM runtime behavior by the time the drivers were written or converted to use the PM runtime, instead of the media .s_power()/.s_stream() callbacks.
Quoted 3 lines
Especially since the
pm_runtime_get_sync()will continue to be used elsewhere, and possibly even in media in cases where you don't need to check for errors (e.g.remove()).
Talking about the remove(), I'm not sure if just ignoring errors there would do the right thing. I mean, if pm_runtime_get_sync() fails, probably any attempts to disable clocks and other things that depend on PM runtime will also (silently) fail.
This may put the device on an unknown PM and keep clock lines enabled after its removal.
Thanks,
Mauro
Re: [PATCH 38/78] media: i2c: mt9m001: use pm_runtime_resume_and_get()
Quoted 40 lines · Mauro Carvalho Chehab
Em Tue, 27 Apr 2021 14:23:20 +0200
Johan Hovold <[email protected]> escreveu:Quoted 5 lines
pm_runtime_get_sync()has worked this way since it was merged 12 years ago, and for someone who's used to this interface this is not such a big deal as you seem to think. Sure, you need to remember to put the usage counter on errors, but that's it (and the other side of that is that you don't need to worry about error handling where it doesn't matter).Before we have those at PM subsystem, the media had its own way to set/disable power for their sub-devices. The PCI and USB drivers still use it, instead of
pm_runtime, mostly due to historic reasons.So, basically, its usage at the media subsystem is restricted to drivers for embedded systems. The vast majority of drivers supporting PM runtime are the I2C camera drivers. The camera drivers can be used interchangeable. So, in practice, the same bridge driver can work with a lot of different camera models, depending on the hardware vendors' personal preferences and the desired max resolution.
So, in thesis, all such drivers should behave exactly the same with regards to PM.
However, on most existing drivers, the
pm_runtimewas added a couple of years ago, and by people that are not too familiar with the PM subsystem.That probably explains why there were/are several places that do things like this[1]:
ret = pm_runtime_get_sync(dev); if (ret < 0) return ret;without taking care of calling a pm_runtime_put*() function.
[1] besides the 13 patches made by UCN addressing it on existing code, I discovered the same pattern on a couple of other drivers with current upstream code.
Quoted 5 lines
That shows a pattern: several media developers are not familiar with the
usage_countbehavior forpm_runtime_getfunctions.So, doing this work is not only helping to make the PM support more uniform, but it is also helping to solve existing issues.
Sure, I don't doubt that there are issues with the current code too.
Quoted 10 lines
Quoted 3 lines
You're call, but converting functioning drivers where the authors knew what they were doing just because you're not used to the API and risk introducing new bugs in the process isn't necessarily a good idea.
The problem is that the above assumption is not necessarily true:
based on the number of drivers thatpm_runtime_get_sync()weren't decrementingusage_counton errors, several driver authors were not familiar enough with the PM runtime behavior by the time the drivers were written or converted to use the PM runtime, instead of the media .s_power()/.s_stream() callbacks.
That may very well be the case. My point is just that this work needs to be done carefully and by people familiar with the code (and runtime pm) or you risk introducing new issues.
I really don't want the bot-warning-suppression crew to start with this for example.
Quoted 11 lines
Quoted 3 lines
Especially since the
pm_runtime_get_sync()will continue to be used elsewhere, and possibly even in media in cases where you don't need to check for errors (e.g.remove()).Talking about the
remove(), I'm not sure if just ignoring errors there would do the right thing. I mean, ifpm_runtime_get_sync()fails, probably any attempts to disable clocks and other things that depend on PM runtime will also (silently) fail.This may put the device on an unknown PM and keep clock lines enabled after its removal.
Right, a resume failure is a pretty big issue and it's not really clear how to to even handle that generally. But at remove() time you don't have much choice but to go on and release resource anyway.
So unless actually implementing some error handling too, using pm_runtime_sync_get() without checking for errors is still preferred over pm_runtime_resume_and_get(). That is
pm_runtime_get_sync(); /* cleanup */ pm_runtime_disable() pm_runtime_put_noidle();
is better than:
ret = pm_runtime_resume_and_get(); /* cleanup */ pm_runtime_disable(); if (ret == 0) pm_runtime_put_noidle();
unless you also start doing something ret.
Johan
Re: [PATCH 38/78] media: i2c: mt9m001: use pm_runtime_resume_and_get()
Em Wed, 28 Apr 2021 12:05:26 +0200
Johan Hovold <[email protected]> escreveu:
Quoted 16 lines · Mauro Carvalho Chehab
Quoted 8 lines
Em Tue, 27 Apr 2021 14:23:20 +0200
Johan Hovold <[email protected]> escreveu:Quoted 3 lines
You're call, but converting functioning drivers where the authors knew what they were doing just because you're not used to the API and risk introducing new bugs in the process isn't necessarily a good idea.
Quoted 6 lines
The problem is that the above assumption is not necessarily true:
based on the number of drivers thatpm_runtime_get_sync()weren't decrementingusage_counton errors, several driver authors were not familiar enough with the PM runtime behavior by the time the drivers were written or converted to use the PM runtime, instead of the media .s_power()/.s_stream() callbacks.
Quoted 3 lines
That may very well be the case. My point is just that this work needs to be done carefully and by people familiar with the code (and runtime pm) or you risk introducing new issues.
Yeah, that's for sure.
Quoted 30 lines
I really don't want the bot-warning-suppression crew to start with this for example.
Quoted 11 lines
Quoted 3 lines
Especially since the
pm_runtime_get_sync()will continue to be used elsewhere, and possibly even in media in cases where you don't need to check for errors (e.g.remove()).Talking about the
remove(), I'm not sure if just ignoring errors there would do the right thing. I mean, ifpm_runtime_get_sync()fails, probably any attempts to disable clocks and other things that depend on PM runtime will also (silently) fail.This may put the device on an unknown PM and keep clock lines enabled after its removal.
Right, a resume failure is a pretty big issue and it's not really clear how to to even handle that generally. But at
remove()time you don't have much choice but to go on and release resource anyway.So unless actually implementing some error handling too, using
pm_runtime_sync_get()without checking for errors is still preferred overpm_runtime_resume_and_get(). That ispm_runtime_get_sync(); /* cleanup */ pm_runtime_disable() pm_runtime_put_noidle();is better than:
Quoted 7 lines
ret = pm_runtime_resume_and_get(); /* cleanup */ pm_runtime_disable(); if (ret == 0) pm_runtime_put_noidle();unless you also start doing something ret.
Perhaps the best would be to use, instead:
pm_runtime_get_noresume(); /* cleanup */ pm_runtime_disable() pm_runtime_put_noidle(); pm_runtime_set_suspended();
I mean, at least for my eyes, it doesn't make sense to do a PM resume during driver's removal/unbind time.
Regards,
Mauro
Quoted 2 lines
Johan
Thanks,
Mauro
Re: [PATCH 38/78] media: i2c: mt9m001: use pm_runtime_resume_and_get()
Quoted 34 lines · Mauro Carvalho Chehab
Em Wed, 28 Apr 2021 12:05:26 +0200
Johan Hovold <[email protected]> escreveu:Quoted 15 lines
Right, a resume failure is a pretty big issue and it's not really clear how to to even handle that generally. But at
remove()time you don't have much choice but to go on and release resource anyway.So unless actually implementing some error handling too, using
pm_runtime_sync_get()without checking for errors is still preferred overpm_runtime_resume_and_get(). That ispm_runtime_get_sync(); /* cleanup */ pm_runtime_disable() pm_runtime_put_noidle();is better than:
Quoted 7 lines
ret = pm_runtime_resume_and_get(); /* cleanup */ pm_runtime_disable(); if (ret == 0) pm_runtime_put_noidle();unless you also start doing something ret.
Perhaps the best would be to use, instead:
pm_runtime_get_noresume();(quoted diff) +0
-0/* cleanup */ pm_runtime_disable() pm_runtime_put_noidle();pm_runtime_set_suspended();
Quoted 2 lines
I mean, at least for my eyes, it doesn't make sense to do a PM resume during driver's removal/unbind time.
The cleanup bit above would depend on the device being resumed so using pm_runtime_get_noresume() makes little sense.
Some drivers disable clocks etc explicitly at remove instead of relying on pm runtime for that and then they'd use the above scheme (plus explicit pm_runtime_set_suspended()).
Johan
PATCH 39/78 media: i2c: ov02a10: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov02a10.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov02a10.c +2 -4
@@ -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) {
Signature · 1 line
2.30.2
PATCH 40/78 media: i2c: ov13858: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov13858.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov13858.c +2 -4
@@ -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
Signature · 1 line
2.30.2
PATCH 41/78 media: i2c: ov2659: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov2659.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov2659.c +2 -4
@@ -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)
Signature · 1 line
2.30.2
PATCH 42/78 media: i2c: ov2685: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov2685.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/media/i2c/ov2685.c +3 -4
@@ -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);
Signature · 1 line
2.30.2
PATCH 43/78 media: i2c: ov2740: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov2740.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov2740.c +2 -4
@@ -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; }
Signature · 1 line
2.30.2
PATCH 44/78 media: i2c: ov5647: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov5647.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5647.c +5 -4
@@ -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;
Signature · 1 line
2.30.2
Re: [PATCH 44/78] media: i2c: ov5647: use pm_runtime_resume_and_get()
Hi Mauro,
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Looks good, thanks!
Quoted 46 lines
--- drivers/media/i2c/ov5647.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)drivers/media/i2c/ov5647.c +5
-5@@ -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
PATCH 45/78 media: i2c: ov5648: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov5648.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5648.c +2 -4
@@ -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);
Signature · 1 line
2.30.2
PATCH 46/78 media: i2c: ov5670: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov5670.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5670.c +2 -4
@@ -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)
Signature · 1 line
2.30.2
PATCH 47/78 media: i2c: ov5675: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov5675.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ov5675.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 48/78 media: i2c: ov5695: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov5695.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5695.c +2 -4
@@ -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) {
Signature · 1 line
2.30.2
PATCH 49/78 media: i2c: ov7740: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov7740.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/i2c/ov7740.c +3 -5
@@ -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)
@@ -1165,7 +1163,7 @@ 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_resume_and_get (&client->dev);pm_runtime_disable (&client->dev);pm_runtime_set_suspended (&client->dev);pm_runtime_put_noidle (&client->dev);
Signature · 1 line
2.30.2
PATCH 50/78 media: i2c: ov8856: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov8856.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ov8856.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 51/78 media: i2c: ov8865: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov8865.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov8865.c +2 -4
@@ -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);
Signature · 1 line
2.30.2
PATCH 52/78 media: i2c: ov9734: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/ov9734.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ov9734.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 53/78 media: i2c: tvp5150: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/tvp5150.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
drivers/media/i2c/tvp5150.c +3 -13
@@ -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)
Signature · 1 line
2.30.2
PATCH 54/78 media: i2c: video-i2c: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/i2c/video-i2c.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/media/i2c/video-i2c.c +5 -9
@@ -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)
@@ -893,7 +889,7 @@ 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_resume_and_get (&client->dev);pm_runtime_disable (&client->dev);pm_runtime_set_suspended (&client->dev);pm_runtime_put_noidle (&client->dev);
Signature · 1 line
2.30.2
PATCH 55/78 media: ipu3: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/pci/intel/ipu3/ipu3-cio2-main.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 56/78 media: coda: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/coda/coda-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/coda/coda-common.c +1 -1
@@ -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;
Signature · 1 line
2.30.2
Philipp Zabel
maintainerRe: [PATCH 56/78] media: coda: use pm_runtime_resume_and_get()
Hi Mauro,
Quoted 16 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/coda/coda-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/coda/coda-common.c +0
-0
drivers/media/platform/coda/coda-common.c static int coda_open(struct file *file) · line 2666
Quoted 8 lines
drivers/media/platform/coda/coda-common.c +1
-1@@ -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;
There's a pm_runtime_put_sync() at the err_pm_get below, so the label needs to be moved down a line:
@@ -2705,8 +2705,8 @@ static int coda_open(struct file *file)
clk_disable_unprepare(dev->clk_ahb);
err_clk_ahb:
clk_disable_unprepare(dev->clk_per);
-err_pm_get:
pm_runtime_put_sync(dev->dev);
+err_pm_get:
v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh);
err_coda_name_init:
regards
Philipp
PATCH 57/78 media: exynos4-is: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/exynos4-is/fimc-capture.c | 6 ++---- drivers/media/platform/exynos4-is/fimc-is.c | 3 ++- drivers/media/platform/exynos4-is/fimc-isp-video.c | 3 +-- drivers/media/platform/exynos4-is/fimc-isp.c | 7 +++---- drivers/media/platform/exynos4-is/fimc-lite.c | 5 +++-- drivers/media/platform/exynos4-is/fimc-m2m.c | 2 +- drivers/media/platform/exynos4-is/media-dev.c | 8 +++----- drivers/media/platform/exynos4-is/mipi-csis.c | 5 ++--- 8 files changed, 17 insertions(+), 22 deletions(-)
drivers/media/platform/exynos4-is/fimc-capture.c +2 -4
@@ -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) {
drivers/media/platform/exynos4-is/fimc-is.c +2 -1
@@ -828,7 +828,7 @@ static int fimc_is_probe(struct platform_device *pdev) goto err_irq; } - ret =pm_runtime_get_sync (dev); + ret =pm_runtime_resume_and_get (dev);if (ret <0 ) goto err_pm;
@@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)fimc_is_unregister_subdevs (is); err_pm:pm_runtime_put_noidle (dev); +err_suspend:if (!pm_runtime_enabled (dev))fimc_is_runtime_suspend (dev); err_irq:
drivers/media/platform/exynos4-is/fimc-isp-video.c +1 -2
@@ -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);
drivers/media/platform/exynos4-is/fimc-isp.c +3 -4
@@ -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);
drivers/media/platform/exynos4-is/fimc-lite.c +3 -2
@@ -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);
drivers/media/platform/exynos4-is/fimc-m2m.c +1 -1
@@ -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; }
drivers/media/platform/exynos4-is/media-dev.c +3 -5
@@ -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 ; }
drivers/media/platform/exynos4-is/mipi-csis.c +2 -3
@@ -494,7 +494,7 @@ static int s5pcsis_s_power(struct v4l2_subdev *sd, int on)struct device *dev = &state->pdev->dev;if (on) -return pm_runtime_get_sync (dev); +return pm_runtime_resume_and_get (dev);return pm_runtime_put_sync (dev); }
@@ -509,9 +509,8 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)if (enable) {s5pcsis_clear_counters (state); - ret =pm_runtime_get_sync (&state->pdev->dev); + ret =pm_runtime_resume_and_get (&state->pdev->dev);if (ret && ret !=1 ) { -pm_runtime_put_noidle (&state->pdev->dev);return ret; } }
Signature · 1 line
2.30.2
Re: [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get()
Quoted 41 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/exynos4-is/fimc-capture.c | 6 ++---- drivers/media/platform/exynos4-is/fimc-is.c | 3 ++- drivers/media/platform/exynos4-is/fimc-isp-video.c | 3 +-- drivers/media/platform/exynos4-is/fimc-isp.c | 7 +++---- drivers/media/platform/exynos4-is/fimc-lite.c | 5 +++-- drivers/media/platform/exynos4-is/fimc-m2m.c | 2 +- drivers/media/platform/exynos4-is/media-dev.c | 8 +++----- drivers/media/platform/exynos4-is/mipi-csis.c | 5 ++--- 8 files changed, 17 insertions(+), 22 deletions(-)drivers/media/platform/exynos4-is/fimc-capture.c +2
-4@@ -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) {drivers/media/platform/exynos4-is/fimc-is.c +0
-0
drivers/media/platform/exynos4-is/fimc-is.c static int fimc_is_probe(struct platform_device *pdev) · line 833
Quoted 7 lines
drivers/media/platform/exynos4-is/fimc-is.c +1
-1@@ -828,7 +828,7 @@ static int fimc_is_probe(struct platform_device *pdev) goto err_irq; } - ret =pm_runtime_get_sync (dev); + ret =pm_runtime_resume_and_get (dev);if (ret <0 ) goto err_pm;
It seems you intended to use err_suspend label here. We don't need a new label though, instead of err_pm we can jump to err_irq when pm_runtime_resume_and_get() fails. Note that when runtime PM is disabled pm_runtime_resume_and_get() always returns 0.
Quoted 24 lines
drivers/media/platform/exynos4-is/fimc-is.c +1
-0@@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)fimc_is_unregister_subdevs (is); err_pm:pm_runtime_put_noidle (dev); +err_suspend:if (!pm_runtime_enabled (dev))fimc_is_runtime_suspend (dev); err_irq:drivers/media/platform/exynos4-is/mipi-csis.c +1
-1@@ -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); }
drivers/media/platform/exynos4-is/mipi-csis.c static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable) · line 515
Quoted 9 lines
drivers/media/platform/exynos4-is/mipi-csis.c +1
-2@@ -509,9 +509,8 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)if (enable) {s5pcsis_clear_counters (state); - ret =pm_runtime_get_sync (&state->pdev->dev); + ret =pm_runtime_resume_and_get (&state->pdev->dev);if (ret && ret !=1 ) { -pm_runtime_put_noidle (&state->pdev->dev);return ret; }
Braces could be dropped as well here.
drivers/media/platform/exynos4-is/mipi-csis.c static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable) · line 516
Quoted 1 line
drivers/media/platform/exynos4-is/mipi-csis.c +0
-0}
Thanks,
Sylwester
Re: [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get()
Em Sun, 25 Apr 2021 22:57:25 +0200 Sylwester Nawrocki <[email protected]> escreveu:
Quoted 45 lines · Mauro Carvalho Chehab
Quoted 44 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/exynos4-is/fimc-capture.c | 6 ++---- drivers/media/platform/exynos4-is/fimc-is.c | 3 ++- drivers/media/platform/exynos4-is/fimc-isp-video.c | 3 +-- drivers/media/platform/exynos4-is/fimc-isp.c | 7 +++---- drivers/media/platform/exynos4-is/fimc-lite.c | 5 +++-- drivers/media/platform/exynos4-is/fimc-m2m.c | 2 +- drivers/media/platform/exynos4-is/media-dev.c | 8 +++----- drivers/media/platform/exynos4-is/mipi-csis.c | 5 ++--- 8 files changed, 17 insertions(+), 22 deletions(-)drivers/media/platform/exynos4-is/fimc-capture.c +2
-4@@ -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) {drivers/media/platform/exynos4-is/fimc-is.c +0
-0@@ -828,7 +828,7 @@ static int fimc_is_probe(struct platform_device *pdev) goto err_irq; }
Quoted 8 lines
drivers/media/platform/exynos4-is/fimc-is.c static int fimc_is_probe(struct platform_device *pdev) · line 833
Quoted 4 lines
drivers/media/platform/exynos4-is/fimc-is.c +1
-1- ret =pm_runtime_get_sync (dev); + ret =pm_runtime_resume_and_get (dev);if (ret <0 ) goto err_pm;It seems you intended to use
err_suspendlabel here. We don't need a new label though, instead oferr_pmwe can jump toerr_irqwhenpm_runtime_resume_and_get()fails.
Thanks! Will fix at the next version.
Quoted 2 lines
Note that when runtime PM is
disabledpm_runtime_resume_and_get()always returns 0.
Ok, but there are a couple of conditions at rpm_resume() function at drivers/base/power/runtime.c (which is the code that actually handles those PM macros) that could make it to return errors, which are independent on the PM callbacks, like those:
if (dev->power.runtime_error)
retval = -EINVAL;
else if (dev->power.disable_depth > 0)
retval = -EACCES;and more might be added as the PM core changes.
Quoted 26 lines
Quoted 26 lines
drivers/media/platform/exynos4-is/fimc-is.c +1
-0@@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)fimc_is_unregister_subdevs (is); err_pm:pm_runtime_put_noidle (dev); +err_suspend:if (!pm_runtime_enabled (dev))fimc_is_runtime_suspend (dev); err_irq:drivers/media/platform/exynos4-is/mipi-csis.c +1
-1@@ -494,7 +494,7 @@ static int s5pcsis_s_power(struct v4l2_subdev *sd, int on)struct device *dev = &state->pdev->dev;if (on) -return pm_runtime_get_sync (dev); +return pm_runtime_resume_and_get (dev);return pm_runtime_put_sync (dev); }@@ -509,9 +509,8 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)
Quoted 10 lines
drivers/media/platform/exynos4-is/mipi-csis.c static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable) · line 515
Quoted 8 lines
drivers/media/platform/exynos4-is/mipi-csis.c +1
-2if (enable) {s5pcsis_clear_counters (state); - ret =pm_runtime_get_sync (&state->pdev->dev); + ret =pm_runtime_resume_and_get (&state->pdev->dev);if (ret && ret !=1 ) { -pm_runtime_put_noidle (&state->pdev->dev);return ret; }Braces could be dropped as well here.
OK.
Quoted 7 lines
drivers/media/platform/exynos4-is/mipi-csis.c static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable) · line 516
Quoted 2 lines
drivers/media/platform/exynos4-is/mipi-csis.c +0
-0}Thanks,
Sylwester
Thanks,
Mauro
Re: [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get()
Quoted 39 lines · Mauro Carvalho Chehab
Em Sun, 25 Apr 2021 22:57:25 +0200 Sylwester Nawrocki <[email protected]> escreveu:
Quoted 17 lines · Mauro Carvalho Chehab
Quoted 16 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>drivers/media/platform/exynos4-is/fimc-is.c +0
-0@@ -828,7 +828,7 @@ static int fimc_is_probe(struct platform_device *pdev) goto err_irq; }Quoted 8 lines
drivers/media/platform/exynos4-is/fimc-is.c static int fimc_is_probe(struct platform_device *pdev) · line 833
Quoted 4 lines
drivers/media/platform/exynos4-is/fimc-is.c +1
-1- ret =pm_runtime_get_sync (dev); + ret =pm_runtime_resume_and_get (dev);if (ret <0 ) goto err_pm;It seems you intended to use
err_suspendlabel here. We don't need a new label though, instead oferr_pmwe can jump toerr_irqwhenpm_runtime_resume_and_get()fails.Thanks! Will fix at the next version.
Quoted 2 lines
Note that when runtime PM is
disabledpm_runtime_resume_and_get()always returns 0.Ok, but there are a couple of conditions at
rpm_resume()function atdrivers/base/power/runtime.c(which is the code that actually handles those PM macros) that could make it to return errors, which are independent on the PM callbacks, like those:
Quoted 6 lines
if (dev->power.runtime_error) retval = -EINVAL; else if (dev->power.disable_depth > 0) retval = -EACCES;and more might be added as the PM core changes.
Right, I looked only at !CONFIG_PM case, this is what the "if (!pm_runtime_enabled(dev))" test and explicit fimc_is_runtime_{resume,suspend} calls were originally for. Agreed, better not to rely too much on internal implementation as there is no specific guarantees about return value at the API documentation.
Regards,
Sylwester
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/media/platform/exynos4-is/fimc-is.c +1
-0@@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)fimc_is_unregister_subdevs (is); err_pm:pm_runtime_put_noidle (dev); +err_suspend:if (!pm_runtime_enabled (dev))fimc_is_runtime_suspend (dev); err_irq:
PATCH 58/78 media: exynos-gsc: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/media/platform/exynos-gsc/gsc-core.c +1 -2
@@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)struct gsc_dev *gsc =platform_get_drvdata (pdev);int i; -pm_runtime_get_sync (&pdev->dev); +pm_runtime_resume_and_get (&pdev->dev);gsc_unregister_m2m_device (gsc);v4l2_device_unregister (&gsc->v4l2_dev);
@@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)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);dev_dbg (&pdev->dev,"%s driver unloaded\n" , pdev->name);
drivers/media/platform/exynos-gsc/gsc-m2m.c +1 -1
@@ -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; }
Signature · 1 line
2.30.2
Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
Quoted 26 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)drivers/media/platform/exynos-gsc/gsc-core.c +1
-1@@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)struct gsc_dev *gsc =platform_get_drvdata (pdev);int i; -pm_runtime_get_sync (&pdev->dev); +pm_runtime_resume_and_get (&pdev->dev);gsc_unregister_m2m_device (gsc);v4l2_device_unregister (&gsc->v4l2_dev);
drivers/media/platform/exynos-gsc/gsc-core.c static int gsc_remove(struct platform_device *pdev) · line 1222
Quoted 4 lines
drivers/media/platform/exynos-gsc/gsc-core.c +0
-1@@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)for (i =0 ; i < gsc->num_clocks; i++)clk_disable_unprepare (gsc->clock[i]); -pm_runtime_put_noidle (&pdev->dev);
If we do this then the device usage count will not get decremented after the pm_runtime_resume_and_get() call above and after driver unload/load cycle it will not be possible to suspend the device. I wouldn't be changing anything in gsc_remove(), pm_runtime_get_sync() works better in that case.
Regards,
Sylwester
Quoted 3 lines
drivers/media/platform/exynos-gsc/gsc-core.c +0
-0pm_runtime_disable (&pdev->dev); dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name
Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
Em Tue, 27 Apr 2021 10:18:12 +0200
Sylwester Nawrocki <[email protected]> escreveu:
Quoted 30 lines · Mauro Carvalho Chehab
Quoted 29 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)drivers/media/platform/exynos-gsc/gsc-core.c +1
-1@@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)struct gsc_dev *gsc =platform_get_drvdata (pdev);int i; -pm_runtime_get_sync (&pdev->dev); +pm_runtime_resume_and_get (&pdev->dev);gsc_unregister_m2m_device (gsc);v4l2_device_unregister (&gsc->v4l2_dev);@@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)for (i =0 ; i < gsc->num_clocks; i++)clk_disable_unprepare (gsc->clock[i]);
Quoted 7 lines
drivers/media/platform/exynos-gsc/gsc-core.c static int gsc_remove(struct platform_device *pdev) · line 1222
Quoted 1 line
drivers/media/platform/exynos-gsc/gsc-core.c +0
-1-pm_runtime_put_noidle (&pdev->dev);If we do this then the device usage count will not get decremented after the
pm_runtime_resume_and_get()call above and after driver unload/load cycle it will not be possible to suspend the device. I wouldn't be changing anything ingsc_remove(),pm_runtime_get_sync()works better in that case.
Good point.
Actually, I don't see any reason why to call a PM resume function - either being pm_runtime_get_sync() or pm_runtime_resume_and_get().
The code there could simply be:
static int gsc_remove(struct platform_device *pdev)
{
struct gsc_dev *gsc = platform_get_drvdata(pdev);
int i;
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_disable(&pdev->dev);
dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
return 0;
}Eventually also adding:
pm_runtime_suspended(&pdev->dev);
just after pm_runtime_disable().
Regards,
Mauro
Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
Em Tue, 27 Apr 2021 11:30:55 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:
Quoted 67 lines
Em Tue, 27 Apr 2021 10:18:12 +0200
Sylwester Nawrocki <[email protected]> escreveu:Quoted 30 lines · Mauro Carvalho Chehab
Quoted 29 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)drivers/media/platform/exynos-gsc/gsc-core.c +1
-1@@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)struct gsc_dev *gsc =platform_get_drvdata (pdev);int i; -pm_runtime_get_sync (&pdev->dev); +pm_runtime_resume_and_get (&pdev->dev);gsc_unregister_m2m_device (gsc);v4l2_device_unregister (&gsc->v4l2_dev);@@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)for (i =0 ; i < gsc->num_clocks; i++)clk_disable_unprepare (gsc->clock[i]);Quoted 7 lines
drivers/media/platform/exynos-gsc/gsc-core.c static int gsc_remove(struct platform_device *pdev) · line 1222
Quoted 1 line
drivers/media/platform/exynos-gsc/gsc-core.c +0
-1-pm_runtime_put_noidle (&pdev->dev);If we do this then the device usage count will not get decremented after the
pm_runtime_resume_and_get()call above and after driver unload/load cycle it will not be possible to suspend the device. I wouldn't be changing anything ingsc_remove(),pm_runtime_get_sync()works better in that case.Good point.
Actually, I don't see any reason why to call a PM resume function - either being
pm_runtime_get_sync()orpm_runtime_resume_and_get().The code there could simply be:
static int gsc_remove(struct platform_device *pdev) { struct gsc_dev *gsc = platform_get_drvdata(pdev); int i; 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_disable(&pdev->dev); dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); return 0; }
Quoted 2 lines
Eventually also adding:
pm_runtime_suspended(&pdev->dev);
In time: I actually meant:
pm_runtime_set_suspended(&pdev->dev);
but after double-checking the PM runtime code, it sounds to me that just calling pm_runtime_disable() would be enough. Not 100% sure here. Btw, some media drivers call it after pm_runtime_disable(), while others don't do.
Thanks,
Mauro
Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
Quoted 73 lines · Mauro Carvalho Chehab
Em Tue, 27 Apr 2021 11:30:55 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:Quoted 67 lines
Em Tue, 27 Apr 2021 10:18:12 +0200
Sylwester Nawrocki <[email protected]> escreveu:Quoted 30 lines · Mauro Carvalho Chehab
Quoted 29 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)drivers/media/platform/exynos-gsc/gsc-core.c +1
-1@@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)struct gsc_dev *gsc =platform_get_drvdata (pdev);int i; -pm_runtime_get_sync (&pdev->dev); +pm_runtime_resume_and_get (&pdev->dev);gsc_unregister_m2m_device (gsc);v4l2_device_unregister (&gsc->v4l2_dev);@@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)for (i =0 ; i < gsc->num_clocks; i++)clk_disable_unprepare (gsc->clock[i]);Quoted 7 lines
drivers/media/platform/exynos-gsc/gsc-core.c static int gsc_remove(struct platform_device *pdev) · line 1222
Quoted 1 line
drivers/media/platform/exynos-gsc/gsc-core.c +0
-1-pm_runtime_put_noidle (&pdev->dev);If we do this then the device usage count will not get decremented after the
pm_runtime_resume_and_get()call above and after driver unload/load cycle it will not be possible to suspend the device. I wouldn't be changing anything ingsc_remove(),pm_runtime_get_sync()works better in that case.Good point.
Actually, I don't see any reason why to call a PM resume function - either being
pm_runtime_get_sync()orpm_runtime_resume_and_get().The code there could simply be:
static int gsc_remove(struct platform_device *pdev) { struct gsc_dev *gsc = platform_get_drvdata(pdev); int i; 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_disable(&pdev->dev); dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); return 0; }Quoted 2 lines
Eventually also adding:
pm_runtime_suspended(&pdev->dev);
Quoted 8 lines
In time: I actually meant:
pm_runtime_set_suspended(&pdev->dev);but after double-checking the PM runtime code, it sounds to me that just calling
pm_runtime_disable()would be enough. Not 100% sure here. Btw, some media drivers call it afterpm_runtime_disable(), while others don't do.
I think if the device is brought into suspended state (e.g. by disabling clocks as above) the pm_runtime_set_suspended() call should be there. IOW a following sequence:
pm_runtime_disable(dev); if (!pm_runtime_status_suspended(dev)) /* put device into suspended state (disable clocks, voltage regulators, assert GPIOs, etc. */ pm_runtime_set_suspended(dev);
--
Regards,
Sylwester
Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
Em Tue, 27 Apr 2021 13:50:44 +0200
Sylwester Nawrocki <[email protected]> escreveu:
Quoted 87 lines · Mauro Carvalho Chehab
Quoted 73 lines
Em Tue, 27 Apr 2021 11:30:55 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:Quoted 67 lines
Em Tue, 27 Apr 2021 10:18:12 +0200
Sylwester Nawrocki <[email protected]> escreveu:Quoted 30 lines · Mauro Carvalho Chehab
Quoted 29 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)drivers/media/platform/exynos-gsc/gsc-core.c +1
-1@@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)struct gsc_dev *gsc =platform_get_drvdata (pdev);int i; -pm_runtime_get_sync (&pdev->dev); +pm_runtime_resume_and_get (&pdev->dev);gsc_unregister_m2m_device (gsc);v4l2_device_unregister (&gsc->v4l2_dev);@@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)for (i =0 ; i < gsc->num_clocks; i++)clk_disable_unprepare (gsc->clock[i]);Quoted 7 lines
drivers/media/platform/exynos-gsc/gsc-core.c static int gsc_remove(struct platform_device *pdev) · line 1222
Quoted 1 line
drivers/media/platform/exynos-gsc/gsc-core.c +0
-1-pm_runtime_put_noidle (&pdev->dev);If we do this then the device usage count will not get decremented after the
pm_runtime_resume_and_get()call above and after driver unload/load cycle it will not be possible to suspend the device. I wouldn't be changing anything ingsc_remove(),pm_runtime_get_sync()works better in that case.Good point.
Actually, I don't see any reason why to call a PM resume function - either being
pm_runtime_get_sync()orpm_runtime_resume_and_get().The code there could simply be:
static int gsc_remove(struct platform_device *pdev) { struct gsc_dev *gsc = platform_get_drvdata(pdev); int i; 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_disable(&pdev->dev); dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); return 0; }Quoted 2 lines
Eventually also adding:
pm_runtime_suspended(&pdev->dev);Quoted 8 lines
In time: I actually meant:
pm_runtime_set_suspended(&pdev->dev);but after double-checking the PM runtime code, it sounds to me that just calling
pm_runtime_disable()would be enough. Not 100% sure here. Btw, some media drivers call it afterpm_runtime_disable(), while others don't do.I think if the device is brought into suspended state (e.g. by disabling clocks as above) the
pm_runtime_set_suspended()call should be there. IOW a following sequence:
Quoted 5 lines
pm_runtime_disable(dev); if (!pm_runtime_status_suspended(dev)) /* put device into suspended state (disable clocks, voltage regulators, assert GPIOs, etc. */ pm_runtime_set_suspended(dev);
Not sure if this would work, as the clock framework would try to do things like calling clk_pm_runtime_put().
Perhaps an alternative would be to just return an error if it can't resume PM runtime, e. g.:
drivers/media/platform/exynos-gsc/gsc-core.c +4 -2
@@ -1208,9 +1208,11 @@ static int gsc_probe(struct platform_device *pdev)static int gsc_remove (struct platform_device *pdev) {struct gsc_dev *gsc =platform_get_drvdata (pdev); -int i; +int ret, i; -pm_runtime_get_sync (&pdev->dev); + ret =pm_runtime_resume_and_get (&pdev->dev); +if (ret <0 ) +return ret;gsc_unregister_m2m_device (gsc);v4l2_device_unregister (&gsc->v4l2_dev);
Thanks,
Mauro
Mauro Carvalho Chehab
maintainerRe: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
Em Wed, 28 Apr 2021 09:13:02 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:
Quoted 107 lines
Em Tue, 27 Apr 2021 13:50:44 +0200
Sylwester Nawrocki <[email protected]> escreveu:Quoted 87 lines · Mauro Carvalho Chehab
Quoted 73 lines
Em Tue, 27 Apr 2021 11:30:55 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:Quoted 67 lines
Em Tue, 27 Apr 2021 10:18:12 +0200
Sylwester Nawrocki <[email protected]> escreveu:Quoted 30 lines · Mauro Carvalho Chehab
Quoted 29 lines
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/exynos-gsc/gsc-core.c | 3 +-- drivers/media/platform/exynos-gsc/gsc-m2m.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)drivers/media/platform/exynos-gsc/gsc-core.c +1
-1@@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)struct gsc_dev *gsc =platform_get_drvdata (pdev);int i; -pm_runtime_get_sync (&pdev->dev); +pm_runtime_resume_and_get (&pdev->dev);gsc_unregister_m2m_device (gsc);v4l2_device_unregister (&gsc->v4l2_dev);@@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)for (i =0 ; i < gsc->num_clocks; i++)clk_disable_unprepare (gsc->clock[i]);Quoted 7 lines
drivers/media/platform/exynos-gsc/gsc-core.c static int gsc_remove(struct platform_device *pdev) · line 1222
Quoted 1 line
drivers/media/platform/exynos-gsc/gsc-core.c +0
-1-pm_runtime_put_noidle (&pdev->dev);If we do this then the device usage count will not get decremented after the
pm_runtime_resume_and_get()call above and after driver unload/load cycle it will not be possible to suspend the device. I wouldn't be changing anything ingsc_remove(),pm_runtime_get_sync()works better in that case.Good point.
Actually, I don't see any reason why to call a PM resume function - either being
pm_runtime_get_sync()orpm_runtime_resume_and_get().The code there could simply be:
static int gsc_remove(struct platform_device *pdev) { struct gsc_dev *gsc = platform_get_drvdata(pdev); int i; 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_disable(&pdev->dev); dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); return 0; }Quoted 2 lines
Eventually also adding:
pm_runtime_suspended(&pdev->dev);Quoted 8 lines
In time: I actually meant:
pm_runtime_set_suspended(&pdev->dev);but after double-checking the PM runtime code, it sounds to me that just calling
pm_runtime_disable()would be enough. Not 100% sure here. Btw, some media drivers call it afterpm_runtime_disable(), while others don't do.I think if the device is brought into suspended state (e.g. by disabling clocks as above) the
pm_runtime_set_suspended()call should be there. IOW a following sequence:Quoted 5 lines
pm_runtime_disable(dev); if (!pm_runtime_status_suspended(dev)) /* put device into suspended state (disable clocks, voltage regulators, assert GPIOs, etc. */ pm_runtime_set_suspended(dev);Not sure if this would work, as the clock framework would try to do things like calling
clk_pm_runtime_put().Perhaps an alternative would be to just return an error if it can't resume PM runtime, e. g.:
drivers/media/platform/exynos-gsc/gsc-core.c +0
-0
drivers/media/platform/exynos-gsc/gsc-core.c static int gsc_probe(struct platform_device *pdev) · line 1215
Quoted 10 lines
drivers/media/platform/exynos-gsc/gsc-core.c +4
-2@@ -1208,9 +1208,11 @@ static int gsc_probe(struct platform_device *pdev)static int gsc_remove (struct platform_device *pdev) {struct gsc_dev *gsc =platform_get_drvdata (pdev); -int i; +int ret, i; -pm_runtime_get_sync (&pdev->dev); + ret =pm_runtime_resume_and_get (&pdev->dev); +if (ret <0 ) +return ret;
Nah, forget about that. Despite the platform driver having a return code, support for it bogus:
static int platform_remove(struct device *_dev)
{
struct platform_driver *drv = to_platform_driver(_dev->driver);
struct platform_device *dev = to_platform_device(_dev);
if (drv->remove) {
int ret = drv->remove(dev);
if (ret)
dev_warn(_dev, "remove callback returned a non-zero value. This will be ignored.\n");
}
dev_pm_domain_detach(_dev, true);
return 0;
}Thanks,
Mauro
Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
Quoted 20 lines · Mauro Carvalho Chehab
Em Wed, 28 Apr 2021 09:13:02 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:Quoted 17 lines
Em Tue, 27 Apr 2021 13:50:44 +0200
Sylwester Nawrocki <[email protected]> escreveu:Quoted 11 lines · Mauro Carvalho Chehab
I think if the device is brought into suspended state (e.g. by disabling clocks as above) the
pm_runtime_set_suspended()call should be there. IOW a following sequence:pm_runtime_disable(dev); if (!pm_runtime_status_suspended(dev)) /* put device into suspended state (disable clocks, voltage regulators, assert GPIOs, etc. */ pm_runtime_set_suspended(dev);Not sure if this would work, as the clock framework would try to do things like calling
clk_pm_runtime_put().
It's done in multiple drivers this way. clk_pm_runtime_put() operates on different device - the clock supplier, not the consumer device. We just need to disable runtime PM for GSC as the last step, to avoid any possible v4l2 m2m device_run() call with runtime PM disabled.
Quoted 2 lines
Quoted 2 lines
Perhaps an alternative would be to just return an error if it can't resume PM runtime, e. g.:
[...]
Quoted 2 lines
Nah, forget about that. Despite the platform driver having a return code, support for it bogus:
Yes, we can't really stop remove() from driver level so as much complete resource release is being done as possible.
Regards,
Sylwester
PATCH 59/78 media: mtk-jpeg: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +2 -2
@@ -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;
Signature · 1 line
2.30.2
PATCH 60/78 media: camss-csid: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/qcom/camss/camss-csid.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/platform/qcom/camss/camss-csid.c +2 -4
@@ -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 ) {
Signature · 1 line
2.30.2
PATCH 61/78 media: camss-csiphy: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/qcom/camss/camss-csiphy.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/platform/qcom/camss/camss-csiphy.c +2 -4
@@ -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 ) {
Signature · 1 line
2.30.2
PATCH 62/78 media: camss-ispif: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/qcom/camss/camss-ispif.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/platform/qcom/camss/camss-ispif.c +2 -4
@@ -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 ) {
Signature · 1 line
2.30.2
PATCH 63/78 media: camss-vfe: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/qcom/camss/camss-vfe.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/camss/camss-vfe.c +3 -2
@@ -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:
Signature · 1 line
2.30.2
PATCH 64/78 media: core: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/qcom/venus/core.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/media/platform/qcom/venus/core.c +10 -9
@@ -84,7 +84,7 @@ 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); +pm_runtime_resume_and_get (core->dev);hfi_core_deinit (core, true);
@@ -106,7 +106,7 @@ static void venus_sys_error_handler(struct work_struct *work)hfi_reinit (core); -pm_runtime_get_sync (core->dev); +pm_runtime_resume_and_get (core->dev); ret |=venus_boot (core); ret |=hfi_core_resume (core, true);
@@ -305,21 +305,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)
@@ -351,8 +351,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);
@@ -371,7 +372,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);
@@ -403,7 +404,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);
Signature · 1 line
2.30.2
PATCH 65/78 media: pm_helpers: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/qcom/venus/pm_helpers.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/media/platform/qcom/venus/pm_helpers.c +4 -6
@@ -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);
Signature · 1 line
2.30.2
PATCH 66/78 media: vdec: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/qcom/venus/vdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/vdec.c +2 -2
@@ -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;
Signature · 1 line
2.30.2
PATCH 67/78 media: venc: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/qcom/venus/venc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/venc.c +3 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 68/78 media: rcar-fcp: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/rcar-fcp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/platform/rcar-fcp.c +2 -4
@@ -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 ; }
Signature · 1 line
2.30.2
PATCH 69/78 media: rcar-vin: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/rcar-vin/rcar-csi2.c | 2 +- drivers/media/platform/rcar-vin/rcar-dma.c | 6 ++---- drivers/media/platform/rcar-vin/rcar-v4l2.c | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-)
drivers/media/platform/rcar-vin/rcar-csi2.c +1 -1
@@ -408,7 +408,7 @@ static void rcsi2_enter_standby(struct rcar_csi2 *priv)static void rcsi2_exit_standby (struct rcar_csi2 *priv) { -pm_runtime_get_sync (priv->dev); +pm_runtime_resume_and_get (priv->dev);reset_control_deassert (priv->rstc); }
drivers/media/platform/rcar-vin/rcar-dma.c +2 -4
@@ -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 );
drivers/media/platform/rcar-vin/rcar-v4l2.c +2 -4
@@ -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)
Signature · 1 line
2.30.2
Re: [PATCH 69/78] media: rcar-vin: use pm_runtime_resume_and_get()
Hi Mauro,
Thanks for your work.
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Quoted 58 lines
--- drivers/media/platform/rcar-vin/rcar-csi2.c | 2 +- drivers/media/platform/rcar-vin/rcar-dma.c | 6 ++---- drivers/media/platform/rcar-vin/rcar-v4l2.c | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-)drivers/media/platform/rcar-vin/rcar-csi2.c +1
-1@@ -408,7 +408,7 @@ static void rcsi2_enter_standby(struct rcar_csi2 *priv)static void rcsi2_exit_standby (struct rcar_csi2 *priv) { -pm_runtime_get_sync (priv->dev); +pm_runtime_resume_and_get (priv->dev);reset_control_deassert (priv->rstc); }drivers/media/platform/rcar-vin/rcar-dma.c +2
-4@@ -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 );drivers/media/platform/rcar-vin/rcar-v4l2.c +2
-4@@ -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)Signature · 1 line
2.30.2
Signature · 2 lines
Regards, Niklas Söderlund
Re: [PATCH 69/78] media: rcar-vin: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabHi Mauro,
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Thanks for your patch!
drivers/media/platform/rcar-vin/rcar-csi2.c static void rcsi2_enter_standby(struct rcar_csi2 *priv) · line 411
Quoted 8 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +1
-1@@ -408,7 +408,7 @@ static void rcsi2_enter_standby(struct rcar_csi2 *priv)static void rcsi2_exit_standby (struct rcar_csi2 *priv) { -pm_runtime_get_sync (priv->dev); +pm_runtime_resume_and_get (priv->dev);
I believe this part is incorrect: on failure[*], the refcount will now be decremented, and in a subsequent call to rcsi2_enter_standby(), the refcount will be decremented again due to the call to pm_runtime_put().
[*] On e.g. R-Car SoCs, this can never fail. This is the reason why
many R-Car (and SuperH) drivers never check the result of pm_runtime_get_sync(). So the refcount "imbalances" were actually introduced by the various "clean up" patches to add return value checking, which now need another round of fixing...
Quoted 6 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +0
-0reset_control_deassert (priv->rstc); }
drivers/media/platform/rcar-vin/rcar-dma.c int rvin_set_channel_routing(struct rvin_dev *vin, u8 chsel) · line 1465
Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-dma.c +2
-4@@ -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; - }
This change (and the change below) is correct, as the logic before/after is equivalent.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH 69/78] media: rcar-vin: use pm_runtime_resume_and_get()
Em Sat, 24 Apr 2021 11:12:31 +0200
Geert Uytterhoeven <[email protected]> escreveu:
Quoted 18 lines
Hi Mauro,
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>Thanks for your patch!
Quoted 4 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +0
-0@@ -408,7 +408,7 @@ static void rcsi2_enter_standby(struct rcar_csi2 *priv)
Quoted 8 lines
drivers/media/platform/rcar-vin/rcar-csi2.c static void rcsi2_enter_standby(struct rcar_csi2 *priv) · line 411
Quoted 4 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +1
-1static void rcsi2_exit_standby (struct rcar_csi2 *priv) { -pm_runtime_get_sync (priv->dev); +pm_runtime_resume_and_get (priv->dev);I believe this part is incorrect: on failure[*], the refcount will now be decremented, and in a subsequent call to
rcsi2_enter_standby(), the refcount will be decremented again due to the call topm_runtime_put().
I see your point.
Quoted 5 lines
[*] On e.g. R-Car SoCs, this can never fail. This is the reason why
many R-Car (and SuperH) drivers never check the result ofpm_runtime_get_sync(). So the refcount "imbalances" were actually introduced by the various "clean up" patches to add return value checking, which now need another round of fixing...
It sounds dangerous to assume that. I'm not a PM expert, but, at least looking at drivers/base/power/runtime.c, there are two situations where the core itself will return an error, even if the PM callback never return errors[1], and more could be added in the future:
if (dev->power.runtime_error)
retval = -EINVAL;
else if (dev->power.disable_depth > 0)
retval = -EACCES;[1] see rpm_resume() function
IMO, the right thing here would be to check it at resume time, and to handle it properly.
Quoted 21 lines
Quoted 7 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +0
-0reset_control_deassert (priv->rstc); }drivers/media/platform/rcar-vin/rcar-dma.c int rvin_set_channel_routing(struct rvin_dev *vin, u8 chsel) · line 1465
Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-dma.c +2
-4@@ -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; - }This change (and the change below) is correct, as the logic before/after is equivalent.
Quoted 4 lines
Gr{oetje,eeting}s,
Geert
Thanks,
Mauro
PATCH 70/78 media: rga-buf: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/rockchip/rga/rga-buf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/platform/rockchip/rga/rga-buf.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
Re: [PATCH 70/78] media: rga-buf: use pm_runtime_resume_and_get()
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Thanks,
Quoted 19 lines
---
drivers/media/platform/rockchip/rga/rga-buf.c | 3 +--1 file changed, 1 insertion(+), 2 deletions(-)drivers/media/platform/rockchip/rga/rga-buf.c +0
-0@@ -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;
}
PATCH 71/78 media: rkisp1-capture: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c +1 -2
@@ -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; }
Signature · 1 line
2.30.2
PATCH 72/78 media: s3c-camif: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/s3c-camif/camif-capture.c | 5 ++--- drivers/media/platform/s3c-camif/camif-core.c | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/media/platform/s3c-camif/camif-capture.c +2 -3
@@ -547,16 +547,15 @@ 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; + goto unlock; ret =sensor_set_power (camif,1 );if (!ret) goto unlock;pm_runtime_put (camif->dev); -err_pm:v4l2_fh_release (file); unlock:mutex_unlock (&camif->lock);
drivers/media/platform/s3c-camif/camif-core.c +3 -2
@@ -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:
Signature · 1 line
2.30.2
Re: [PATCH 72/78] media: s3c-camif: use pm_runtime_resume_and_get()
Hi Mauro,
Quoted 17 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- drivers/media/platform/s3c-camif/camif-capture.c | 5 ++--- drivers/media/platform/s3c-camif/camif-core.c | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-)drivers/media/platform/s3c-camif/camif-capture.c +0
-0
drivers/media/platform/s3c-camif/camif-capture.c static int s3c_camif_open(struct file *file) · line 553
Quoted 9 lines
drivers/media/platform/s3c-camif/camif-capture.c +2
-2@@ -547,16 +547,15 @@ 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; + goto unlock;
I think we don't need that label change, fh still needs to be released in case of an error.
drivers/media/platform/s3c-camif/camif-capture.c static int s3c_camif_open(struct file *file) · line 561
Quoted 9 lines
drivers/media/platform/s3c-camif/camif-capture.c +0
-1ret =sensor_set_power (camif,1 );if (!ret) goto unlock;pm_runtime_put (camif->dev); -err_pm:v4l2_fh_release (file); unlock:mutex_unlock (&camif->lock);
--
Regards,
Sylwester
PATCH 73/78 media: s5p-mfc: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/s5p-mfc/s5p_mfc_pm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/platform/s5p-mfc/s5p_mfc_pm.c +2 -4
@@ -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++) {
Signature · 1 line
2.30.2
Re: [PATCH 73/78] media: s5p-mfc: use pm_runtime_resume_and_get()
Quoted 7 lines · Mauro Carvalho Chehab
Commit
dd8088d5a896("PM: runtime: Addpm_runtime_resume_and_getto deal with usage counter") addedpm_runtime_resume_and_get()in order to automatically handledev->power.usage_countdecrement on errors.Use the new API, in order to cleanup the error check logic.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Thank you for the patch.
PATCH 74/78 media: bdisp-v4l2: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/sti/bdisp/bdisp-v4l2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/platform/sti/bdisp/bdisp-v4l2.c +4 -3
@@ -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:
Signature · 1 line
2.30.2
PATCH 75/78 media: stm32: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/stm32/stm32-dcmi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/platform/stm32/stm32-dcmi.c +3 -2
@@ -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.
Signature · 1 line
2.30.2
PATCH 76/78 media: sun4i_v4l2: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c +3 -4
@@ -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)
@@ -225,8 +225,7 @@ static int sun4i_csi_open(struct file *file) err_pipeline_pm_put:v4l2_pipeline_pm_put (&csi->vdev.entity); -err_pm_put: -pm_runtime_put (csi->dev); +err_unlock:mutex_unlock (&csi->lock);return ret;
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH 76/78] media: sun4i_v4l2: use pm_runtime_resume_and_get()
I love your patch! Yet something to improve:
Hi Mauro,
I love your patch! Yet something to improve:
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on next-20210423]
[cannot apply to rockchip/for-next tegra/for-next v5.12-rc8] [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/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029 base: git://linuxtv.org/media_tree.git master config: nios2-randconfig-s031-20210424 (attached as .config) compiler: nios2-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-341-g8af24329-dirty
# https://github.com/0day-ci/linux/commit/ddf22a45db8814ab855d3535a125e17f5e58f94b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mauro-Carvalho-Chehab/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029 git checkout ddf22a45db8814ab855d3535a125e17f5e58f94b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=nios2
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c: In function 'sun4i_csi_open':
>> drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c:215:3: error: label 'err_pm_put' used but not defined
215 | goto err_pm_put;
| ^~~~Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for SERIAL_CORE_CONSOLE Depends on TTY && HAS_IOMEM
Selected by
- EARLY_PRINTK
vim +/err_pm_put +215 drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
577bbf23b758848 Maxime Ripard 2019-08-22 199
577bbf23b758848 Maxime Ripard 2019-08-22 200 static int sun4i_csi_open(struct file *file)
577bbf23b758848 Maxime Ripard 2019-08-22 201 {
577bbf23b758848 Maxime Ripard 2019-08-22 202 struct sun4i_csi *csi = video_drvdata(file);
577bbf23b758848 Maxime Ripard 2019-08-22 203 int ret;
577bbf23b758848 Maxime Ripard 2019-08-22 204
577bbf23b758848 Maxime Ripard 2019-08-22 205 ret = mutex_lock_interruptible(&csi->lock);
577bbf23b758848 Maxime Ripard 2019-08-22 206 if (ret)
577bbf23b758848 Maxime Ripard 2019-08-22 207 return ret;
577bbf23b758848 Maxime Ripard 2019-08-22 208
ddf22a45db8814a Mauro Carvalho Chehab 2021-04-24 209 ret = pm_runtime_resume_and_get(csi->dev);
577bbf23b758848 Maxime Ripard 2019-08-22 210 if (ret < 0)
ddf22a45db8814a Mauro Carvalho Chehab 2021-04-24 211 goto err_unlock;
577bbf23b758848 Maxime Ripard 2019-08-22 212
8fd390b89cc8ca7 Ezequiel Garcia 2020-01-24 213 ret = v4l2_pipeline_pm_get(&csi->vdev.entity);
577bbf23b758848 Maxime Ripard 2019-08-22 214 if (ret)
577bbf23b758848 Maxime Ripard 2019-08-22 @215 goto err_pm_put;
577bbf23b758848 Maxime Ripard 2019-08-22 216
577bbf23b758848 Maxime Ripard 2019-08-22 217 ret = v4l2_fh_open(file);
577bbf23b758848 Maxime Ripard 2019-08-22 218 if (ret)
577bbf23b758848 Maxime Ripard 2019-08-22 219 goto err_pipeline_pm_put;
577bbf23b758848 Maxime Ripard 2019-08-22 220
577bbf23b758848 Maxime Ripard 2019-08-22 221 mutex_unlock(&csi->lock);
577bbf23b758848 Maxime Ripard 2019-08-22 222
577bbf23b758848 Maxime Ripard 2019-08-22 223 return 0;
577bbf23b758848 Maxime Ripard 2019-08-22 224
577bbf23b758848 Maxime Ripard 2019-08-22 225 err_pipeline_pm_put:
8fd390b89cc8ca7 Ezequiel Garcia 2020-01-24 226 v4l2_pipeline_pm_put(&csi->vdev.entity);
577bbf23b758848 Maxime Ripard 2019-08-22 227
ddf22a45db8814a Mauro Carvalho Chehab 2021-04-24 228 err_unlock:
577bbf23b758848 Maxime Ripard 2019-08-22 229 mutex_unlock(&csi->lock);
577bbf23b758848 Maxime Ripard 2019-08-22 230
577bbf23b758848 Maxime Ripard 2019-08-22 231 return ret;
577bbf23b758848 Maxime Ripard 2019-08-22 232 }
577bbf23b758848 Maxime Ripard 2019-08-22 233 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 77/78 media: ti-vpe: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- 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(-)
drivers/media/platform/ti-vpe/cal-video.c +3 -1
@@ -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);
drivers/media/platform/ti-vpe/cal.c +5 -3
@@ -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 ;
drivers/media/platform/ti-vpe/vpe.c +1 -3
@@ -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 ; }
Signature · 1 line
2.30.2
PATCH 78/78 media: vsp1: use pm_runtime_resume_and_get()
In reply to Mauro Carvalho ChehabCommit 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.
--- drivers/media/platform/vsp1/vsp1_drv.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/platform/vsp1/vsp1_drv.c +2 -4
@@ -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 ; }
Signature · 1 line
2.30.2
There was a Smatch check for these bugs. This was a good source of recurring Reported-by tags for me. ;) Thanks for doing this.
regards,
dan carpenter